简体   繁体   中英

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM