模拟环境:
往表中插入100万条相同的数据。该表有6个索引。
查询的时候,会有where,也有order by。目前暂且排序一个字段。
结果发现,查询很慢。查询效率以分钟级别计算。
在用explain查看select语句的时候 id select_type table type possible_keys key key_len ref rows Extra
------ ----------- ------ ------ --------------------------- --------- ------- ------ ------ ---------------------------
1 SIMPLE btitle ref BoardID_1,BoardID_2,deleted BoardID_2 1002 const 73468 Using where; Using filesort
从语句中看,好像不能在优化了。
对这样的情况,该怎么处理?
往表中插入100万条相同的数据。该表有6个索引。
查询的时候,会有where,也有order by。目前暂且排序一个字段。
结果发现,查询很慢。查询效率以分钟级别计算。
在用explain查看select语句的时候 id select_type table type possible_keys key key_len ref rows Extra
------ ----------- ------ ------ --------------------------- --------- ------- ------ ------ ---------------------------
1 SIMPLE btitle ref BoardID_1,BoardID_2,deleted BoardID_2 1002 const 73468 Using where; Using filesort
从语句中看,好像不能在优化了。
对这样的情况,该怎么处理?
解决方案 »
- 建立多个数据表,是合建好还是分开建多张数据表好?可以教导下?
- Mysql一次性插入多少条记录最优
- mysql定义触发器错误,:[Err] 1415 - Not allowed to return a result set from a trigger
- 获取记录总数,此两种方法效率上有何差别?
- mysql为何默认是latin 1字符集呀?phpmyadmin中显示中文乱码?
- mysql 字符转码问题
- sql中表数据记录的提取
- Mysql在什么情况下会丢失数据库文件
- mysql5.0支持存储过程和触发器了?
- MySQL数据库实例
- 通过父节点ID查询所有子节点ID,报错:data too long for column
- mysql能够访问ACCESS数据库吗,就是以MDB结尾的数据库
Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
-------- ---------- --------- ------------ ----------- --------- ----------- -------- ------ ------ ---------- -------
bbstitle 0 PRIMARY 1 id A 47539 (NULL) (NULL) BTREE
bbstitle 1 BoardID_2 1 BoardID_2 A (NULL) 333 (NULL) YES BTREE
bbstitle 1 titleType 1 titleType A (NULL) (NULL) (NULL) YES BTREE
bbstitle 1 deleted 1 deleted A (NULL) (NULL) (NULL) YES BTREE
bbstitle 1 BoardID_1 1 BoardID_1 A (NULL) 333 (NULL) YES BTREE
bbstitle 1 user_id 1 user_id A (NULL) 333 (NULL) YES BTREE SQL语句 大概是这样.
select * from bbstitle where BoardID_1=? and BoardID_2=? and deleted=0 group by top desc,date desc limit ?,2;
不是标准的SQL语句
另外你的语句写错了吧。建议贴问题出来 时严谨一些,否则别人分析反而是浪费时间。select * from bbstitle
where BoardID_1=?
and BoardID_2=?
and deleted=0
group by top desc,date desc limit ?,2;GROUP BY 还是ORDER BY ?!
select * from bbstitle where BoardID_1=? and BoardID_2=? and deleted=0 group by top desc,date desc limit ?,2;另外,我昨天想到把需要排序的字段抽取出来,然后放到另外一张表A.
查询的时候,先查询表A,对表A,进行排序.然后在查询具体表B.是否行得通?
这样带来一个问题.连接数据库过多.