我对一个将近6000条记录表进行了20次不同条件的count查询,结果花了3,4秒,但是这些count结果都放在同个页面的.3,4秒太慢了,如何才能提速,求高手帮忙
解决方案 »
- mysql触发器的问题 Not allowed to return a result set from a trigger
- 求一个字符串截位替换的解法
- 多对多连接,为什么需要中间表????
- 求SQL语句
- Mysql的字符/转义问题
- MYSQL提示说:incorrect integer value,我大致查了一下,说是因为MYSQL5的BUG,高手能详细说下吗?谢谢~~
- 请问在MYSQL中怎样修改一个表的结构啊?
- 请问这个PostgreSQL的SQL语句,怎么写?
- mysql索引为何没有用到
- MySql经常无故自动停止服务,求帮助
- 如何提高mysql 服务器图片存取速度
- 请问mysql如何在两个数据库之间导入数据表
6000条
SELECT COUNT(DISTINCT item.id) FROM item WHERE (((item.id) IN (1,2...,600))
AND ((item.status) = (0)))
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows
| Extra |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+
| 1 | SIMPLE | item | ALL | PRIMARY | NULL | NULL | NULL | 6089
| Using where |
+----+-------------+-------+------+---------------+------+---------+------+-----
-+-------------+查询用时0.5秒左右
为什么type是ALL,不是index
AND item.status = 0
在哪个字段上建立的索引
select sum(case when (condition1 is true) then 1 else 0 end) count1,
sum(case when (condition2 is true) then 1 else 0 end) count2
from ....
item.id建立一个索引
item.id和item.status建立一个联合索引
create table auto_id ().....;
SELECT COUNT(DISTINCT a.id) FROM item as a, auto_id as b where a.id = b.id
AND a.status = 0