In MySQL 'USE INDEX' is not working But 'FORCE Index' seems working fine

梦想的初衷 提交于 2021-02-11 12:24:41

问题


EXPLAIN EXTENDED 

SELECT * FROM table_name

--  FORCE INDEX(dummy_date)

 USE INDEX(dummy_date)

where dummy_date 

between '2020-12-01' AND '2020-12-31'

AND name='something';

ALTER TABLE `table_name` ADD INDEX `dummy_date_index`(`dummy_date`)

When I execute this query then indexing is not working but if I use force index then its working with index. Please let me know the correct approach to use the index for millions of rows.


回答1:


Even better than MySQL not using indexes with WHERE IN clause? --

Use a better index and don't bother with USE or FORCE:

INDEX(name, dummy_date)

Anyway, if most of the table is in that month, then using INDEX(dummy_date) is less efficient than scanning the table.



来源:https://stackoverflow.com/questions/66007286/in-mysql-use-index-is-not-working-but-force-index-seems-working-fine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!