1. 程式人生 > >mysql Like查詢使用索引的情況

mysql Like查詢使用索引的情況


EXPLAIN SELECT *FROM  `hb_send_list`  WHERE hongbao_id LIKE '%AA1317B32755BDFC1B8036'

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE hb_send_list ALL (NULL) (NULL) (NULL) (NULL) 14382 Using where

EXPLAIN SELECT *FROM  `hb_send_list`  WHERE hongbao_id LIKE 'AA1317B32755BDFC1B8036%'

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE hb_send_list range hongbao_id hongbao_id 98 (NULL) 1 Using index condition

EXPLAIN  SELECT *FROM  `hb_send_list`  WHERE hongbao_id LIKE 'A%A1317B32755BDFC1B8036'

id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE hb_send_list range hongbao_id hongbao_id 98 (NULL) 995 Using index condition


mysql在使用like查詢,%在最前面不會用到索引,中間或最後是會用到索引的,只是越靠前掃描的行數越多