讨论见http://www.iteye.com/topic/710338
帖子中说如果使用了where 1=1,则索引查询会失效。通过实验,该结论是错误的:
mysql> explain select * from pu_user_message where userid=1\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pu_user_message
type: ref
possible_keys: userid_index
key: userid_index
key_len: 5
ref: const
rows: 1
Extra: Using where
1 row in set (0.00 sec)
mysql> explain select * from pu_user_message where 1=1 and userid=1\G
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: pu_user_message
type: ref
possible_keys: userid_index
key: userid_index
key_len: 5
ref: const
rows: 1
Extra: Using where
1 row in set (0.00 sec)
两次执行完全一样,均使用了索引。