I am trying to understand how multiple conditions are executed in 'where clause', If I query a table and in the where condition if I have built in function with 'and' operator if I have some simple filter condition on columns, again a select query which is the best possible way it would take minimum time.
1.17sec to execute:
SELECT count(col1) FROM table1 idbs WHERE TRUNC(idbs.DATE) BETWEEN TO_DATE('01/01/2000','mm/dd/yyyy') AND TO_DATE('08/11/2016','mm/dd/yyyy') and COL2 <> 'Y' AND COL3 = 'N' AND COL4 <> 36 AND (var IS NULL OR idbs.COL5 IN( (SELECT regexp_substr(var,'[^|]+', 1, LEVEL) FROM dual CONNECT BY regexp_substr(var,'[^|]+', 1, LEVEL) IS NOT NULL)));
Below query took 1.207 sec to execute:
SELECT count(col1) FROM table1 idbs WHERE COL2 <> 'Y' AND COL3 = 'N' AND COL4 <> 36 AND TRUNC(idbs.DATE) BETWEEN TO_DATE('01/01/2000','mm/dd/yyyy') AND TO_DATE('08/11/2016','mm/dd/yyyy') AND (var IS NULL OR idbs.COL5 IN( (SELECT regexp_substr(var,'[^|]+', 1, LEVEL) FROM dual CONNECT BY regexp_substr(var,'[^|]+', 1, LEVEL) IS NOT NULL))) ;
I have just rearranged the conditions but the time I see after execution is slightly different.