Col 1,
col 2,
.....
.....
from
table1,
table2
........
........
where
join conditions1
join conditions1
................
.................
and
table1.day_key >= (select key from date_dim where value='01-JAN-2011')
and table1.day_key <= (select key from date_dim where value='31-DEC-2011')
and
table2.day_key >= (select key from date_dim where value='01-JAN-2011')
and table2.day_key <= (select key from date_dim where value='31-DEC-2011')
Here I can see date_dim table is doing scan four in where condition, how to avoid it. date_dim table is not selected in main from clause. I dont have enviornment to test this unfortunatly. Database is oracle 10g
As I said I don’t see a performance problem scanning that table double times as necessary.
A pure rewrite of query would be:
But you should test it, in order to not suffer a performance hit.