I have a table with 2 million rows. I have two index (status, gender) and also (birthday).
I find strange that this query is taking 3.6 seconds or more QUERY N° 1
SELECT COUNT(*) FROM ts_user_core
WHERE birthday BETWEEN '1980-01-01' AND '1985-01-01'
AND status='ok' AND gender='female';
same for this: QUERY N° 2
SELECT COUNT(*) FROM ts_user_core
WHERE status='ok' AND gender='female'
AND birthday between '1980-01-01' AND '1985-01-01';
While this query is taking 0.140 seconds QUERY N° 3
select count(*) from ts_user_core where (birthday between '1990-01-01' and '2000-01-01');
Also this query takes 0.2 seconds QUERY N° 4
select count(*) from ts_user_core where status='ok' and gender='female'
I expect the first query to be way more faster, how can be possible this behavior? I can't handle so much time for this query.
Here the result of:
I know that I can add a new index with 3 columns, but is there a way to have a faster query without adding an index for every where clause?
Thanks for your advice