I have a table of about million rows and I am trying to filter out rows based on a particular column using an IN
clause.
Sample data:
status
---------
'XXX-01'
'XXX-02'
'XXX-06'
'XXX-010'
'XX-XXX-027'
'XX-XXX-030'
Query:
The following query took about 5 seconds to complete.
select * from demo_tabl where substring_index(status, '-', -1) in ('06', '07');
But the following took just a few milliseconds to complete.
select * from demo_tabl where substring_index(status, '-', -1) in ('06', '07', '030', '027');
The column is indexed, however, the index goes unused due to the substring_index
function.
Question:
Why is there a huge difference in the query runtime, in spite of the similar formation?