Hi Friends,
We are using oracle 8.1.7, solaris 2.8.
can u please help me in tuning this SQL.
INDEX is present on both date_added and ad_id column
select count(distinct l.com_id),l.date_added, a.source
from tabs a,lis l where
(to_char(l.date_added,'DD/MON/YYYY') >= '01/JAN/2002' and
to_char(l.date_added,'DD/MON/YYYY') <= '31/DEC/2002') and
l.ad_id = a.ad_id
group by l.date_added,a.source
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=279116 Card=32505 By
tes=942645)
The following statement is wrong because you compare
strings and not dates:
(to_char(l.date_added,'DD/MON/YYYY') >= '01/JAN/2002' and
to_char(l.date_added,'DD/MON/YYYY') <= '31/DEC/2002')
A string like '01/DEC/2003' will be smaler than '31/JAN/2003', I guess it's not soemthing you realy want.
Try the follwing statement and check if it's faster
select count(distinct l.com_id),l.date_added, a.source
from tabs a,lis l
where
l.date_added >= to_date('01/JAN/2002','DD/MON/YYYY') and
l.date_added <= to_date('31/DEC/2002','DD/MON/YYYY') and
l.ad_id = a.ad_id
group by l.date_added,a.source
select count(distinct l.com_id),l.date_added, a.source
from tabs a,lis l
where
l.date_added >= to_date('01/JAN/2002','DD/MON/YYYY') and
l.date_added <= to_date('31/DEC/2002','DD/MON/YYYY') and
l.ad_id = a.ad_id
group by l.date_added,a.source 2 3 4 5 6 7
8 /
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=CHOOSE (Cost=602938 Card=5108360
Bytes=148142440)
Bookmarks