i have the following select statement :
( SELECT CAL_DATE,BUS_DAY FROM risk_mart.vw_calendar_t5 WHERE type = 'RPC' AND BUS_DAY BETWEEN 0 AND 1 ) CAL WHERE t.cal_date = cal.cal_date
It selects all the dates and then filters them between 0 and 1 (displays only two dates e.g. ’22-OCT-12′,’19-OCT-12′).
Now, i can re-write that manually as
WHERE t.cal_date in (’22-OCT-12′,’19-OCT-12′)
The difference is performance. The first example i get a return back within 90 seconds and the second example, i get it within 10 seconds. Why?.
How can i improve the first statement/rewrite it?
Now ,this is your first query .In this you are first retrieving the records into an inner view CAL which takes some amount of time .And after that you join
t.cal_date = cal.cal_datewhich will again take some amount of time (TOTAL 90Sec).Now ,here is the second query .
In this case ,you dint use the inner view ,so you have somehow managed to get the
datesdirectly and use that in your where condition(HARDCODED) .This was you have reduce the processing time of the inner view (CAL) and the join with the CAL table with table t.