0
EXPLAIN EXTENDED 
SELECT * FROM table_name
where dummy_date 
between '2020-12-01' AND '2020-12-31'
-- between '2020-12-01' AND '2020-12-20'
AND name='something';
ALTER TABLE `table_name` ADD INDEX `dummy_date_index`(`dummy_date`);

if dummy_date is between 20-25 days then query used indexing for 700,000 records but if it is more than 25 days then query is not using indexing and doing full table scan. please let me know the correct approach to utilize index.

Deepak Rai
  • 2,163
  • 3
  • 21
  • 36
  • Can you please add table schema? Also this has no relation to phpmyadmin, that is just a UI. It is as related as your browser is. – user3783243 Feb 02 '21 at 12:31
  • Does this answer your question? [In MySQL 'USE INDEX' is not working But 'FORCE Index' seems working fine](https://stackoverflow.com/questions/66007286/in-mysql-use-index-is-not-working-but-force-index-seems-working-fine) – P.Salmon Feb 02 '21 at 12:53
  • How is this different to your last question? – P.Salmon Feb 02 '21 at 12:53

1 Answers1

0
INDEX(name, dummy_date)

would be better.

It is right for the Optimizer to avoid an index that is not very selective. There is overhead in using an index. There is also overhead in skipping rows during a table scan. The Optimizer has to pick which is the "lesser of two evils"; sometimes it does not pick the right 'lesser'.

Rick James
  • 135,179
  • 13
  • 127
  • 222