- 论坛徽章:
- 0
|
Index_U_Id: `type`, `ischecked`, `u_id`,
and连接的条件的顺序并不影响索引使用的判断。
索引列的顺序会影响索引使用的判断
可以理解你所说的:
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (ischecked =1 AND type=01 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (type=01 AND ischecked =1) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (u_id=14 AND type=01 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (type=01 AND u_id=14) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE type=01 ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (u_id=14 AND ischecked =1 AND type=01) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (u_id=14 AND type=01 AND ischecked =1 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (type=01 AND ischecked =1 AND u_id=14) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (type=01 AND u_id=14 AND ischecked =1) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (ischecked =1 AND u_id=14 AND type=01 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (ischecked =1 AND type=01 AND u_id=14) ORDER BY `id` ASC ;
------------以下语句没有用到索引。
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (u_id=14 AND ischecked =1 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (ischecked =1 AND u_id=14 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE u_id=14 ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE ischecked =1 ORDER BY `id` ASC ;
我又针对这些没有用到索引的语句增加了两个索引,以确保所用可能的SQL语句都能用到索引:
Index_U_Id2: `u_id`, `ischecked` :
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (u_id=14 AND ischecked =1 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE (ischecked =1 AND u_id=14 ) ORDER BY `id` ASC ;
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE u_id=14 ORDER BY `id` ASC ;
Index_Check: `ischecked` :
explain SELECT `ios_seeds`.* FROM `ios_seeds` WHERE ischecked =1 ORDER BY `id` ASC ;
这样做合理吗?是不是索引太多了
[ 本帖最后由 zhengdl126 于 2009-8-12 09:42 编辑 ] |
|