Joins and in-line views [message #571855] |
Mon, 03 December 2012 00:47 |
lakshmis
Messages: 102 Registered: November 2008 Location: India
|
Senior Member |
|
|
Hi All,
Please help me in understanding how joins work with in-line views.
I have a query and its explain plan as below:
SELECT e.ename,e.deptno,d.dname FROM
dept d,
emp e
WHERE e.deptno=d.deptno
AND e.deptno=20
-----------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
-----------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 210 | 11 |
| 1 | HASH JOIN | | 5 | 210 | 11 |
| 2 | TABLE ACCESS FULL| DEPT | 1 | 22 | 5 |
| 3 | TABLE ACCESS FULL| EMP | 5 | 100 | 5 |
-----------------------------------------------------------
Note
-----
- 'PLAN_TABLE' is old version
I read the docuemnt at: http://www.dba-oracle.com/oracle_tips_rittman_inlineviews.htm,
section "Using outer joins with in-line views", under which he demonstartes the use of in-line views.
I changed the above query to use in-line view.
The new query and its explain plan are as below:
SELECT e.ename,e.deptno,d.dname FROM
dept d,
(SELECT * FROM emp WHERE deptno=20) e
WHERE e.deptno=d.deptno
-----------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
-----------------------------------------------------------
| 0 | SELECT STATEMENT | | 5 | 210 | 11 |
| 1 | HASH JOIN | | 5 | 210 | 11 |
| 2 | TABLE ACCESS FULL| DEPT | 1 | 22 | 5 |
| 3 | TABLE ACCESS FULL| EMP | 5 | 100 | 5 |
-----------------------------------------------------------
Note
-----
- 'PLAN_TABLE' is old version
I do not find any difference in both the explain plans. Both are same.
In my second query, the filtered rows will be joined to dept table. And hence the baggage will reduce.
But how can I verify that in-line view has worked better?
Regards,
Lakshmi.
[Updated on: Mon, 03 December 2012 00:55] Report message to a moderator
|
|
|
Re: Joins and in-line views [message #571858 is a reply to message #571855] |
Mon, 03 December 2012 01:11 |
|
Michel Cadot
Messages: 68732 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
1/ "'PLAN_TABLE' is old version", use the current version of the plan table if you want accurate information.
2/ It does not matter how you write it (in this case) as Oracle optimizer knows what is SQL and rewrites the query in the most efficient way.
3/ NEVER relies on information from this site, it is b...
Regards
Michel
[Updated on: Mon, 03 December 2012 01:12] Report message to a moderator
|
|
|
Re: Joins and in-line views [message #571859 is a reply to message #571858] |
Mon, 03 December 2012 01:17 |
lakshmis
Messages: 102 Registered: November 2008 Location: India
|
Senior Member |
|
|
Hi Michel,
Thanks for your response.
You said,
Quote:
2/ It does not matter how you write it (in this case) as Oracle optimizer knows what is SQL and rewrites the query in the most efficient way.
Is there any way, I can find what oracle decides the efficient way and how it internally re-wrote the query?
Regards,
Lakshmi.
[Updated on: Mon, 03 December 2012 01:18] Report message to a moderator
|
|
|
|
Re: Joins and in-line views [message #571868 is a reply to message #571864] |
Mon, 03 December 2012 03:30 |
lakshmis
Messages: 102 Registered: November 2008 Location: India
|
Senior Member |
|
|
Hi,
Please suggest:
1. Is changing the joins in long-running queries to in-line views is advisable or not?
If I can change, how can I verify the improvement in performance statistically?
Also I face another situation where in:
1. I start a sql*plus session,
2. Run the long running query with timing ON. Lets assume it takes 10mins.
3. I make some changes to the queries (Tuning changes)
4. And then re-run the query. This time, the query completes in less than 2 secs.
The reason I suspect is that the data has come from SGA and not from disk.
I can not flush the memory because there are many jobs which run in this environment.
Please suggest how can I get the actual time taken by the query every time I run the query.
Regards,
Lakshmi.
|
|
|
|
|
|
|