Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Even though an index is available it's not getting used

I face a weird situation where the same query is executing fast in the environment even though the index is unavailable and it’s slow in another environment where the index is available. Can someone please help me with this? The table structure is identical in both the environments and also the data is around 2 million.

I did a select to find the execution time on both the servers. The query is executed in 2 sec in the environment where there is no index available and it took around 80 sec in the environment where an index is available.

UPDATE jobs_feed 
set posted_to_gfj=3 
WHERE posted_to_gfj = 1 
AND posted_date < '2022-06-28' 
ORDER BY posted_date ASC limit 8000;

Explain with Index

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Explain without Index

column:posted_to_gfj tinyint(1)

column:posted_date datetime

>Solution :

Are the columns in the index in the same order they’re used in the query? as in

posted_to_gfj,
posted_date

vs.

posted_date,
posted_to_gfj?

see How important is the order of columns in indexes?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading