对一个大表进行很多次不同条件的count查询,如何提高速度? 我对一个将近6000条记录表进行了20次不同条件的count查询,结果花了3,4秒,但是这些count结果都放在同个页面的.3,4秒太慢了,如何才能提速,求高手帮忙 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 做了公共部分好是好了点,但数据一大,查询又慢下来了.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 SELECT COUNT(DISTINCT item.id) FROM item WHERE item.id BETWEEN 1 AND 600AND item.status = 0在哪个字段上建立的索引 item.id 是主键 这个上会产生索引的啊 item表里还有一个item.guid字段上也建立索引啦 看看能不能用这种方式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 .... SELECT COUNT(DISTINCT item.id) FROM item WHERE (((item.id) IN (1,2...,600)) AND ((item.status) = (0))) 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.idAND a.status = 0 哎,楼上的方法是好的,但是我用sqlobject 无法实现啊.因为整个项目是python做的,sqlobject只有95%的SQL能全部正确地处理,谁精通SQLOBJECT啊,高手救命啊.先谢谢各位的热心帮助了 1个mysql数据库怎么在两台电脑上同时运行要互不干扰怎么实现? mysql varchar text 等长度问题 sql截取字符串替换字段 关于一个mysql查询问题, libmysql.dll出错 导进去的库不能用,请高手帮我看看,急 !!! 问一个查询的问题(立刻给分) 安装ODBC的问题 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