![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| ||||||||||
| ||||||||||
|
|
Id | Operation | Name | Rows | Bytes | Cos |
|
0 | SELECT STATEMENT | | 15 | 585 | |
|
1 | VIEW | | 15 | 585 | |
|
2 | UNION ALL (RECURSIVE WITH) BREADTH FIRST| | | | 3 | TABLE ACCESS BY INDEX ROWID | EMP | 1 | 17 | |
|
* 4 | INDEX UNIQUE SCAN | PK_EMP | 1 | 0 (0)| 00:00:01 | |
|
* 5 | HASH JOIN | | 14 | 602 | |
|
6 | RECURSIVE WITH PUMP | | | | 7 | TABLE ACCESS FULL | EMP | 14 | 238 | |
|
Id | Operation | Name | Rows | Bytes | Cost (% |
|
0 | SELECT STATEMENT | | 14 | 364 4 (25)| 00:00:41 | |
|
* 1 | CONNECT BY NO FILTERING WITH START-WITH| | | | | 2 | TABLE ACCESS FULL | EMP | 14 | 238 3 (0)| 00:00:31 | |
#2
| |||
| |||
|
|
The question is why does oracle think that this statement will return 15 rows? |
#3
| |||
| |||
|
|
On Thu, 17 Feb 2011 22:34:02 +0000, Mladen Gogala wrote: The question is why does oracle think that this statement will return 15 rows? I figured it out. The recursive CTE has 2 parts: the initial and the recursive part. The part of the 1st statement which says "select empno,mgr,1 from emp where empno=7839" plays the same role as the "start with empnp=7839" part of the "connect by" version, but is apparently executed separately. It seems to me that the good, old "connect by" stuff is still preferred by Oracle. --http://mgogala.byethost5.com |
#4
| |||
| |||
|
|
On Feb 17, 6:02*pm, Mladen Gogala <n... (AT) email (DOT) here.invalid> wrote: On Thu, 17 Feb 2011 22:34:02 +0000, Mladen Gogala wrote: The question is why does oracle think that this statement will return15 rows? I figured it out. The recursive CTE has 2 parts: the initial and the recursive part. The part of the 1st statement which says "select empno,mgr,1 from emp where empno=7839" plays the same role as the "start with empnp=7839" part of the "connect by" version, but is apparently executed separately. It seems to me that the good, old "connect by" stuff is still preferred by Oracle. --http://mgogala.byethost5.com You can get a very similar plan for the CONNECT BY variant if you use the "CONNECT_BY_FILTERING" hint - your simple query is using the "NO_CONNECT_BY_FILTERING" variant which basically corresponds to the old connect by implementation if I remember correctly. The costs will be quite similar I believe since the plan will be almost identical (in this particular case). Of course it might not work out as expected since you seem to have baselines activated for both statements - I wonder why? |
#5
| |||
| |||
|
|
Maybe I'm not understanding something, but isn't the idea for Oracle to figure out the best plan over time for each statement? |
#6
| |||
| |||
|
|
On Fri, 18 Feb 2011 09:30:16 -0800, joel garry wrote: Maybe I'm not understanding something, but isn't the idea for Oracle to figure out the best plan over time for each statement? Actually no. Oracle 11 will collect statistics and replace the baseline in the SYSMAN tablespaces if and only if the plan costs less than the existing one. Oracle is not Watson, doesn't play Jeopardy with our SQL, it simply saves the plans and replaces them with cheaper plans. |
|
Although, speaking of Watson and intelligence, I predict that we will soon see multi-TB NVRAM devices, and the face of the computing will definitely change. Among other things, B*Trees may become obsolete. |
#7
| |||
| |||
|
|
On Fri, 18 Feb 2011 09:30:16 -0800, joel garry wrote: Maybe I'm not understanding something, but isn't the idea for Oracle to figure out the best plan over time for each statement? Actually no. Oracle 11 will collect statistics and replace the baseline in the SYSMAN tablespaces if and only if the plan costs less than the existing one. Oracle is not Watson, doesn't play Jeopardy with our SQL, it simply saves the plans and replaces them with cheaper plans. |
![]() |
| Thread Tools | |
| Display Modes | |
| |