Home » RDBMS Server » Performance Tuning » Query on Explain Plan Steps (Oracle 10.2.0.4 on RHEL)
Query on Explain Plan Steps [message #535562] Wed, 14 December 2011 22:01 Go to next message
orapratap
Messages: 134
Registered: November 2011
Location: Canada
Senior Member
Hello

Please refer the following execution plan

I was assuming
1) The table T2 will be Full scanned
2) In a Nested loop for every value retuned in step 1) above index on T1 will be accessed
3) For every value accessed from index on T1, value will be retrived from table T1

However from the plan below it seems
1) The table T2 will be Full scanned
2) In a Nested loop for every value retuned in step 1) above index on T1 will be accessed
Now "after all iteration of the loop are completed" and values are retrieved from table T1 (out of the loop)

Please help me understand it

Also please let me know how we can print execution step nos. in the explain plan

Regards
OraPratap

<font size="1"><font size="4"><font size="4">
select  /*+   gather_plan_statistics   ordered use_nl(t1) index(t1)  */  count(t1.n2), count(t2.n2) from  t2, t1 where  t2.n2 = 45 and t1.n1 = t2.n1 ;         


 -----------------------------------------------------------------------------------------------  

| Id  | Operation                    | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  

-----------------------------------------------------------------------------------------------  

|   1 |  SORT AGGREGATE              |      |      1 |      1 |      1 |00:00:00.01 |     146 |  

|   2 |   TABLE ACCESS BY INDEX ROWID| T1   |      1 |     15 |    225 |00:00:00.01 |     146 |  

|   3 |    NESTED LOOPS              |      |      1 |    225 |    241 |00:00:00.02 |     116 |  

|*  4 |     TABLE ACCESS FULL        | T2   |      1 |     15 |     15 |00:00:00.01 |      99 |  

|*  5 |     INDEX RANGE SCAN         | T_I1 |     15 |     15 |    225 |00:00:00.01 |      17 |  

-----------------------------------------------------------------------------------------------          [/size][/size][/size]



[Updated on: Wed, 14 December 2011 22:03]

Report message to a moderator

Re: Query on Explain Plan Steps [message #535563 is a reply to message #535562] Wed, 14 December 2011 22:34 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
That certainly is a nice looking SELECT statement & similar to below

http://jonathanlewis.wordpress.com/2006/11/09/dbms_xplan-in-10g/
Re: Query on Explain Plan Steps [message #535564 is a reply to message #535563] Wed, 14 December 2011 22:38 Go to previous messageGo to next message
orapratap
Messages: 134
Registered: November 2011
Location: Canada
Senior Member
BlackSwan

No doubt about your eagle eye

It is copied from there itself

At this moment I do not have a db system and was reading article on dbms_xplan where I saw this plan

However I genuinely want to understand the plan posted

Regards
OraPratap
Re: Query on Explain Plan Steps [message #535565 is a reply to message #535564] Wed, 14 December 2011 22:46 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://structureddata.org/2008/01/06/oracle-11g-real-time-sql-monitoring-using-dbms_sqltunereport_sql_monitor/
Re: Query on Explain Plan Steps [message #535568 is a reply to message #535565] Wed, 14 December 2011 23:21 Go to previous messageGo to next message
orapratap
Messages: 134
Registered: November 2011
Location: Canada
Senior Member
Hello BlackSwan

Thanks for the link

I understand that you forwarded me the link as an answer to my question no. 2
BTW I will be using (10g) and not 11g

Also
Could you please answer my query no 1 as well?

Regards
OraPratap
Re: Query on Explain Plan Steps [message #535571 is a reply to message #535568] Wed, 14 December 2011 23:31 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>Could you please answer my query no 1 as well?

no
Re: Query on Explain Plan Steps [message #535620 is a reply to message #535571] Thu, 15 December 2011 05:50 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
In this particular case, the operation at step 2 is repeated for every row returned by step 3 as they are returned. Step 1 is different though; it collects all rows from child step 2 before it passes any back.

Here's an article that might help http://www.orafaq.com/node/1420

There are only a few actions that "collect" data before passing to the parent step - most pass rows on as soon as they get them. SORT is the main one (aggregation, distinct, sort-merge join, UNION). If you see a VIEW step in a plan then it is almost certainly collecting all child rows in TEMP before passing them on.

Ross Leishman
Re: Query on Explain Plan Steps [message #535623 is a reply to message #535620] Thu, 15 December 2011 06:09 Go to previous messageGo to next message
orapratap
Messages: 134
Registered: November 2011
Location: Canada
Senior Member
Many Thanks Ross

I shall go through the link in detail

Meanwhile when the optimizer might chose plan 1 and when goes for plan 2?

Plan 1

 Id  | Operation                    | Name            |
--------------------------------------------------------
|   0 | SELECT STATEMENT             |                 |
|   1 |  NESTED LOOPS                |                 |
|   2 |   PARTITION LIST ALL         |                 |
|   3 |    TABLE ACCESS FULL         | EF_ACTL_EXPNS   |
|   4 |   TABLE ACCESS BY INDEX ROWID| ED_LBR_CST_ROLE |
|   5 |    INDEX UNIQUE SCAN         | ED_LBCR_PK      |
--------------------------------------------------------

Plan 2

 -----------------------------------------------------------------------------------------------  

| Id  | Operation                    | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  

-----------------------------------------------------------------------------------------------  

|   1 |  SORT AGGREGATE              |      |      1 |      1 |      1 |00:00:00.01 |     146 |  

|   2 |   TABLE ACCESS BY INDEX ROWID| T1   |      1 |     15 |    225 |00:00:00.01 |     146 |  

|   3 |    NESTED LOOPS              |      |      1 |    225 |    241 |00:00:00.02 |     116 |  

|*  4 |     TABLE ACCESS FULL        | T2   |      1 |     15 |     15 |00:00:00.01 |      99 |  

|*  5 |     INDEX RANGE SCAN         | T_I1 |     15 |     15 |    225 |00:00:00.01 |      17 |  

-----------------------------------------------------------------


Apologies for copying and pasting plans from Articles
Also 1 is having partition and the other do not

But question here is Plan 1 has the Table access before Nested loop and Plan 2 has it after Nested loop

isn't it like -
outer loop
FTS table 1
Inner loop
index scan table 2
scan table 2 for the rowid in above index blocks
<return row>
end Inner loop
end outer loop


Also can we get the sequence of execution steps in explain plan

Once again many thanks for the link.

Regards
OraPratap

Re: Query on Explain Plan Steps [message #535701 is a reply to message #535623] Thu, 15 December 2011 14:22 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
If Oracle can find all of the join columns in the index, then it will probably choose Plan 2 - depending on version. I'm pretty sure the "deferred table access" we see in Plan 2 was not around in earlier versions. If it is only scanning the index for SOME of the join columns, it will need to retrieve the others from the table before joining.

I don't know how to get the execution sequence. Once you know how to read a plan, they are kind of redundant.

Ross Leishman
Re: Query on Explain Plan Steps [message #536427 is a reply to message #535701] Tue, 20 December 2011 23:57 Go to previous message
orapratap
Messages: 134
Registered: November 2011
Location: Canada
Senior Member
Hello Ross

Many Thanks for the wonderful article (http://www.orafaq.com/node/1420) and the reply

Regards
OraPratap
Previous Topic: Query performance related
Next Topic: How to Track Delay in Displaying data on application GUI
Goto Forum:
  


Current Time: Fri Apr 19 09:06:54 CDT 2024