JL,
Thanks for your answer.
<quote>
If you wish to show that Oracle may materialize the subquery unhinted then, possibly, changing your main query to the following (and I have to work from memory here as it's now off-screen) may be a sufficient demonstration: <quote>
Here is my test. I did not add a MATERIALIZE hint.
Raw trace file shows:
PARSING IN CURSOR #1 len=133 dep=0 uid=65 oct=3 lid=65 tim=6455264884414 hv=3578672561 ad='3d2cdc10'
with gen as
(select * from t1 where rownum <= 50)
select * from gen where rownum <= 10
union all
select * from gen where rownum <= 10
END OF STMT
PARSE #1:c=330000,e=470856,p=0,cr=102,cu=2,mis=1,r=0,dep=0,og=1,tim=6455264884388
WAIT #1: nam='control file sequential read' ela= 231 file#=0 block#=1 blocks=1 obj#=-1 tim=6455264914896
WAIT #1: nam='control file sequential read' ela= 140 file#=1 block#=1 blocks=1 obj#=-1 tim=6455264915361
WAIT #1: nam='control file sequential read' ela= 138 file#=2 block#=1 blocks=1 obj#=-1 tim=6455264915672
WAIT #1: nam='control file sequential read' ela= 133 file#=0 block#=390 blocks=1 obj#=-1 tim=6455264916029
WAIT #1: nam='db file sequential read' ela= 14490 file#=5 block#=142110 blocks=1 obj#=64908 tim=6455264932727
WAIT #1: nam='db file sequential read' ela= 38898 file#=5 block#=142111 blocks=1 obj#=64908 tim=6455264972959
WAIT #1: nam='direct path write temp' ela= 2 file number=201 first dba=17034 block cnt=1 obj#=64908 tim=6455265054692
WAIT #1: nam='direct path write temp' ela= 2 file number=201 first dba=17034 block cnt=1 obj#=64908 tim=6455265062202
WAIT #1: nam='direct path write temp' ela= 132 file number=201 first dba=17034 block cnt=1 obj#=64908 tim=6455265062332
EXEC #1:c=1150000,e=1242997,p=2,cr=3,cu=7,mis=0,r=0,dep=0,og=1,tim=6455266128129
WAIT #1: nam='SQL*Net message to client' ela= 17 driver id=1650815232 #bytes=1 p3=0 obj#=64908 tim=6455266128797
WAIT #1: nam='db file sequential read' ela= 157 file#=201 block#=17034 blocks=1 obj#=-40016382 tim=6455266130118
FETCH #1:c=0,e=1166,p=1,cr=5,cu=1,mis=0,r=1,dep=0,og=1,tim=6455266130443
WAIT #1: nam='SQL*Net message from client' ela= 22644 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266153591
WAIT #1: nam='SQL*Net message to client' ela= 4 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266153911
FETCH #1:c=0,e=701,p=0,cr=4,cu=0,mis=0,r=15,dep=0,og=1,tim=6455266154513
WAIT #1: nam='SQL*Net message from client' ela= 12699 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266167436
WAIT #1: nam='SQL*Net message to client' ela= 4 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266167711
FETCH #1:c=0,e=312,p=0,cr=1,cu=0,mis=0,r=4,dep=0,og=1,tim=6455266167932
WAIT #1: nam='SQL*Net message from client' ela= 5344 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266174715
STAT #1 id=1 cnt=20 pid=0 pos=1 obj=0 op='TEMP TABLE TRANSFORMATION (cr=13 pr=3 pw=1 time=1243807 us)'
STAT #1 id=2 cnt=1 pid=1 pos=1 obj=0 op='LOAD AS SELECT (cr=3 pr=2 pw=1 time=1241100 us)'
STAT #1 id=3 cnt=50 pid=2 pos=1 obj=0 op='COUNT STOPKEY (cr=3 pr=2 pw=0 time=57808 us)'
STAT #1 id=4 cnt=50 pid=3 pos=1 obj=64908 op='TABLE ACCESS FULL T1 (cr=3 pr=2 pw=0 time=56998 us)'
STAT #1 id=5 cnt=20 pid=1 pos=2 obj=0 op='UNION-ALL (cr=10 pr=1 pw=0 time=1098 us)'
STAT #1 id=6 cnt=10 pid=5 pos=1 obj=0 op='COUNT STOPKEY (cr=6 pr=1 pw=0 time=1064 us)'
STAT #1 id=7 cnt=10 pid=6 pos=1 obj=0 op='VIEW (cr=6 pr=1 pw=0 time=1042 us)'
STAT #1 id=8 cnt=10 pid=7 pos=1 obj=4254950914 op='TABLE ACCESS FULL SYS_TEMP_0FD9D6602_D2AA59 (cr=6 pr=1 pw=0 time=960 us)'
STAT #1 id=9 cnt=10 pid=5 pos=2 obj=0 op='COUNT STOPKEY (cr=4 pr=0 pw=0 time=252 us)'
STAT #1 id=10 cnt=10 pid=9 pos=1 obj=0 op='VIEW (cr=4 pr=0 pw=0 time=217 us)'
STAT #1 id=11 cnt=10 pid=10 pos=1 obj=4254950914 op='TABLE ACCESS FULL SYS_TEMP_0FD9D6602_D2AA59 (cr=4 pr=0 pw=0 time=186 us)'
WAIT #0: nam='SQL*Net message to client' ela= 4 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455266176546
*** 2007-02-25 10:23:40.680
WAIT #0: nam='SQL*Net message from client' ela= 14261391 driver id=1650815232 #bytes=1 p3=0 obj#=-40016382 tim=6455280438103
=====================
Output from TKPROF:
with gen as
(select * from t1 where rownum <= 50)
select * from gen where rownum <= 10
union all
select * from gen where rownum <= 10
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 1 0.09 0.09 0 0 1 0
Execute 1 1.15 1.24 2 3 7 0
Fetch 3 0.00 0.00 1 10 1 20
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 5 1.24 1.34 3 13 9 20
Misses in library cache during parse: 1
Optimizer mode: ALL_ROWS
Parsing user id: 65
Rows Row Source Operation
------- ---------------------------------------------------
20 TEMP TABLE TRANSFORMATION (cr=13 pr=3 pw=1 time=1243807 us)
1 LOAD AS SELECT (cr=3 pr=2 pw=1 time=1241100 us)
50 COUNT STOPKEY (cr=3 pr=2 pw=0 time=57808 us)
50 TABLE ACCESS FULL T1 (cr=3 pr=2 pw=0 time=56998 us)
20 UNION-ALL (cr=10 pr=1 pw=0 time=1098 us)
10 COUNT STOPKEY (cr=6 pr=1 pw=0 time=1064 us)
10 VIEW (cr=6 pr=1 pw=0 time=1042 us)
10 TABLE ACCESS FULL SYS_TEMP_0FD9D6602_D2AA59 (cr=6 pr=1 pw=0 time=960 us)
10 COUNT STOPKEY (cr=4 pr=0 pw=0 time=252 us)
10 VIEW (cr=4 pr=0 pw=0 time=217 us)
10 TABLE ACCESS FULL SYS_TEMP_0FD9D6602_D2AA59 (cr=4 pr=0 pw=0 time=186 us)
Is it a valid proof for flooding the shared pool thus causing ora-4031 error?
Or are we heading towards a optimizer bug in 10gR2? My basic question is: Why did oracle create a GTT for a skinny table of 100 rows where it could do every thing in memory ?
Tamil