我有以下MYSQL查询:
SELECT statusdate,consigneenamee,weight,productcode,
pieces,statustime,statuscode,statusdesc,generatingiata,
shipmentdate,shipmenttime,consigneeairportcode,signatory
FROM notes
where (shipperref='180908184' OR shipperref='180908184'
OR shipperref='180908184' OR shipperref='180908184 '
OR shipperref like 'P_L_%180908184')
order by edicheckpointdate asc, edicheckpointtime asc;
我添加了索引以使用MYSQL Workbench加快该查询的速度,但是在执行EXPLAIN
命令时,它仍然不显示键,并显示为NULL:
+----+-------------+---------------+------+---------------+------+---------+------+---------+-----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+---------------+------+---------------+------+---------+------+---------+-----------------------------+
| 1 | SIMPLE | dhltracking_2 | ALL | index2 | NULL | NULL | NULL | 3920874 | Using where; Using filesort |
+----+-------------+---------------+------+---------------+------+---------+------+---------+-----------------------------+
发生这种情况的原因以及如何加快此查询的速度?
我的索引:
答案 0 :(得分:1)
您的查询中有LIKE
条语句,我认为您的索引跨越表行的20%至30%(或更多)。因此,出于性能原因,MySQL可以忽略它。
我的建议:
FORCE INDEX
FULLTEXT
索引(也适用于CHAR和VARCHAR)并使用MATCH ... AGAINST
搜索(https://dev.mysql.com/doc/refman/8.0/en/fulltext-boolean.html)