Understanding Execution Plan of a query [message #548750] |
Sun, 25 March 2012 23:35 |
|
orapratap
Messages: 134 Registered: November 2011 Location: Canada
|
Senior Member |
|
|
Hello
I have queries on the execution plan of a sql statement
Please help me understand
Following is the example
create table t1 as select s1.nextval id,a.* from dba_objects a;
create table t2 as select s2.nextval id,a.* from dba_objects a;
insert into t1 select s1.nextval id,a.* from dba_objects a;
insert into t1 select s1.nextval id,a.* from dba_objects a;
insert into t2 select s2.nextval id,a.* from dba_objects a;
insert into t2 select s2.nextval id,a.* from dba_objects a;
insert into t2 select s2.nextval id,a.* from dba_objects a;
commit;
create index i1 on t1(id);
create index i2 on t2(id);
create index i11 on t1(object_type);
exec dbms_stats.gather_table_stats(user,'T1',cascade=>true);
exec dbms_stats.gather_table_stats(user,'T2',cascade=>true);
select count(*) from t1 where object_type='VIEW';
COUNT(*)
----------
8934
set autotrace traceonly explain
Can we say in the following case, that,
(1) First index on object_type is accessed to get rowids - t1.object_type='VIEW'
(2) Then the filter on owner is applied - t1.owner='SYS'
(3) Then the table T1 is accessed to fetch data from the rowids returned by the index I11 and filer application - TABLE ACCESS BY INDEX ROWID
Though I am unable to understand how filter can be applied to the rowids retrieved from index, we can see from the plan below that
The rows accessed have reduced from 8550 to 1221 before we access the table...Thus filter "t1.owner='SYS'" is applied in between. Right?
another question is
Case 1 - do we retrieve a rowid from index for a given value, then retrieve required values from table for that rowid
Thus row at a time in both ... in loop
OR
Case 2 - we first fetch all rowids from index and then retrieve values from table one row at a time from the collection of rowids fetched?
Suppose Case 1 is what is happening then can we say, both the steps mentioned by IDS 2,3 in plan below are executed exactly equal number of times and the filter "t1.owner='SYS'" is applied at some later stage?
Of course in this case the values in ROWS stand misleading then
select * from t1,t2 where t1.id = t2.id and t1.object_type='VIEW' and t1.owner='SYS';
Execution Plan
----------------------------------------------------------
Plan hash value: 26873579
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1221 | 233K| 915 (1)| 00:00:11 |
|* 1 | HASH JOIN | | 1221 | 233K| 915 (1)| 00:00:11 |
|* 2 | TABLE ACCESS BY INDEX ROWID| T1 | 1221 | 116K| 381 (1)| 00:00:05 |
|* 3 | INDEX RANGE SCAN | I11 | 8550 | | 24 (0)| 00:00:01 |
| 4 | TABLE ACCESS FULL | T2 | 161K| 15M| 533 (1)| 00:00:07 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("T1"."ID"="T2"."ID")
2 - filter("T1"."OWNER"='SYS')
3 - access("T1"."OBJECT_TYPE"='VIEW')
Thanks and Regards
OraPratap
|
|
|
|
|
|
Re: Understanding Execution Plan of a query [message #548775 is a reply to message #548764] |
Mon, 26 March 2012 04:13 |
|
orapratap
Messages: 134 Registered: November 2011 Location: Canada
|
Senior Member |
|
|
Hello Michel
Thanks for your reply
I am still not clear about Quote:
Rowids are retrieved per block, rows are retrieved row by row in a loop
Suppose a block has IDS as 1,1,2,2,3,4 and another block has rowids as 2,5,6,7
how the rowids will be retrived from index and then the data from the table T1?
Also does these rowid are stored in memory as a collection before values are retrieved from table row-by-row?
loop
-- initiall i = 1 (i.e. ID = 1)
access index I11
get "all" rowids from block, in which for ID = i is stored
--will it retrurn and use rowids for ID = 2,2,3 as well since it is in the same block
access table T1 with -- this problem now as we have multiple rowids
apply filter (owner = 'SYS') ** am I misunderstanding it?...will it apply filter row-by-row in loop
Return data to hash table
i= i+1;
end loop;
Thanks and Regards
OraPratap
|
|
|
|
|
Re: Understanding Execution Plan of a query [message #548787 is a reply to message #548784] |
Mon, 26 March 2012 04:58 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:This means we always access all index blocks
No, In this case Oracle walks along its tree structure to find the first block with object_type='VIEW' then walks to the next blocks until it find an entry with another value.
Quote:Another related question is what is "rows" in the plan?
Estimated rows returned by the operation.
Regards
Michel
|
|
|