View previous topic :: View next topic |
Author |
Message |
edkir98 Beginner

Joined: 27 Aug 2007 Posts: 102 Topics: 42 Location: Chennai
|
Posted: Thu Sep 18, 2008 6:30 am Post subject: Order of execution of Query |
|
|
Suppose I have a query as follows
Code: | SELECT
A.FIELD1
B.FIELD2
C.FIELD3
D.FIELD4
FROM TABLE1 AS A,
TABLE2 AS B,
TABLE3 AS C
LEFT OUTER JOIN --left outer join between table3 and table4
TABLE4 AS D
ON
C.LJOINFIELD = D.LJOINFIELD
WHERE A.FIELD1 > 0 --some filter conditions on table1
C.FIELD2 = 'ABC' --some filter conditions on table3
B.IJOINFIELD = D.IJOINFIELD --inner join between table2 and table4
A.IJOINFIELD = C.IJOINFIELD --inner join between table1 and table3 |
In the above query I would like to know how the query would proceed.. which join happends first, what filtering happens next...
can someone please help.. _________________ Thanks |
|
Back to top |
|
 |
jim haire Beginner
Joined: 30 Dec 2002 Posts: 140 Topics: 40
|
Posted: Thu Sep 18, 2008 8:12 am Post subject: |
|
|
You could run an Explain on the query which would tell you what was performed first. There is also a free tool called Visual Explain from IBM which you can download which would show the order.
We can't tell from the query which order the statements would be performed in. The optimizer makes choices depending on the number of rows in each table, filter factors, and many other criteria. |
|
Back to top |
|
 |
arungr Beginner
Joined: 12 Feb 2005 Posts: 16 Topics: 4
|
Posted: Mon Jan 12, 2009 10:14 pm Post subject: Outer Join - execution order |
|
|
I have a similar qustion. All I wanted to know which will get executed first in the above query. "ON" or "WHERE". |
|
Back to top |
|
 |
arungr Beginner
Joined: 12 Feb 2005 Posts: 16 Topics: 4
|
Posted: Mon Jan 12, 2009 10:23 pm Post subject: |
|
|
I had asked the above question because I do not have access to Plan_Table and hence I wont be able to run "Explain". Any inputs are appreciated. |
|
Back to top |
|
 |
CZerfas Intermediate
Joined: 31 Jan 2003 Posts: 211 Topics: 8
|
Posted: Tue Jan 13, 2009 4:31 am Post subject: |
|
|
Regarding your access to a PLAN_TABLE:
You need access to a PLAN_TABLE of another userid (table qualifier different from your User-ID), if you want to explain the access path of an existing DB2 package. If you want to know the access path of a single SQL statement, you can create a PLAN-TABLE with your own User-ID as qualifier and then issue an EXPLAIN SQL statement through any interactive SQL facility (SPUFI, BMC catalog manager, etc.). The create statement for the latest version of PLAN_TABLE can be found in the DB2 manuals or derived by you from an existing PLAN_TABLE.
Regarding to the sequence of ON and WHERE: As far as I have understood it, ON is issued first, but only when the "outer-joined table" is accessed by the optimizer during the preparation process of the statement. So some predicates of the WHERE clause, that have nothing to do with your "outer-joined table", can already be evaluated.
regards
Christian |
|
Back to top |
|
 |
|
|