Get a tool like TOAD which can be used to really fine tune a query.
The stuff that Tim sais is also very important, limit your records as soon as possible so there are less records to scan for each part of the join. I shrank a query from 12 commas in the iteration count to less than 100 million iteration simply by filter the where clause earlier
>Can you post the explain plan for each query:
>
>Example:
>
>EXPLAIN PLAN FOR
>SELECT Tab1.*, Tab2.*, Tab3.*, Tab4.*, Tab5.* FROM tab1, tab2, tab3, tab4, tab5 WHERE (tab1.column1=tab5.column1) AND (tab1.column2=tab2.column2) AND (tab2.column3=tab4.column3) AND (tab2.column4=tab3.column4)
> AND tab1.column5=to_date('1900-01-01','YYYY-MM-DD')
> AND tab2.column6='03' AND tab2.column7='AC';
>
>EXPLAIN PLAN FOR
>SELECT Tab1.*, Tab2.*, Tab3.*, Tab4.*, Tab5.* FROM tab1, tab2, tab3, tab4, tab5 WHERE (tab1.column1=tab5.column1) AND (tab1.column2=tab2.column2) AND (tab2.column3=tab4.column3) AND (tab2.column4=tab3.column4)
> AND tab1.column5=to_date('1900-01-01','YYYY-MM-DD');
>
>EXPLAIN PLAN FOR
>SELECT Tab1.*, Tab2.*, Tab3.*, Tab4.*, Tab5.* FROM tab1, tab2, tab3, tab4, tab5 WHERE (tab1.column1=tab5.column1) AND (tab1.column2=tab2.column2) AND (tab2.column3=tab4.column3) AND (tab2.column4=tab3.column4)
>AND tab2.column6='03' AND tab2.column7='AC';
>
>
>How much data is in each table....
>
>A quick quess without the extra explain plan info would be :
>Try putting the 'AC' part first...
>SELECT Tab1.*, Tab2.*, Tab3.*, Tab4.*, Tab5.* FROM tab1, tab2, tab3, tab4, tab5 WHERE tab2.column7='AC' AND
>(tab1.column1=tab5.column1) AND (tab1.column2=tab2.column2) AND (tab2.column3=tab4.column3) AND (tab2.column4=tab3.column4)
> AND tab1.column5=to_date('1900-01-01','YYYY-MM-DD')
> AND tab2.column6='03';
>
>in general Order the where clause as follows...
>
>where table with most data first join AND table with less data at end join...
>I.E. move the where clauses around so that the largest tables come first...
>
>
>I'm thinking Hash Join too but need to see the execution plan.
>
>Note if you run the queries in that order you would expect the last 2 to be faster becuase the rows would now be in the DB Buffer (memory). To get real results you will need to run each query with a clean buffer...
>
>HTH
Previous
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only