create table t(x integer);
Table created.
insert into t select 1 from dual connect by level <= 10000;
10000 rows created.
commit;
Commit complete.
create function f(x in integer) return integer as begin return 1; end;
/
Function created.
analyze table t compute statistics;
Table analyzed.
set autotrace traceonly
set timing on
select * from t where (select f(x) from dual) = 1;
10000 rows selected.
Elapsed: 00:00:15.00
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=10 Card=10000 Byte
s=20000)
1 0 FILTER
2 1 TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=8 Card=10000 By
tes=20000)
3 1 FAST DUAL (Cost=2 Card=1)
Statistics
----------------------------------------------------------
17 recursive calls
0 db block gets
721 consistent gets
0 physical reads
0 redo size
403627 bytes sent via SQL*Net to client
87750 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
10000 rows processed
select * from t where (select f(x) from dual) = 1 order by x;
10000 rows selected.
Elapsed: 00:00:04.08
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=12 Card=10000 Byte
s=20000)
1 0 SORT (ORDER BY) (Cost=12 Card=10000 Bytes=20000)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=8 Card=10000
Bytes=20000)
4 2 FAST DUAL (Cost=2 Card=1)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
31 consistent gets
0 physical reads
0 redo size
403627 bytes sent via SQL*Net to client
87750 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10000 rows processed
select * from (select * from t order by x) where (select f(x) from dual) = 1;
10000 rows selected.
Elapsed: 00:00:11.06
Execution Plan
----------------------------------------------------------
0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=12 Card=10000 Byte
s=20000)
1 0 SORT (ORDER BY) (Cost=12 Card=10000 Bytes=20000)
2 1 FILTER
3 2 TABLE ACCESS (FULL) OF 'T' (TABLE) (Cost=8 Card=10000
Bytes=20000)
4 2 FAST DUAL (Cost=2 Card=1)
Statistics
----------------------------------------------------------
1 recursive calls
0 db block gets
31 consistent gets
0 physical reads
0 redo size
403627 bytes sent via SQL*Net to client
87750 bytes received via SQL*Net from client
668 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
10000 rows processed</code>
Here t.x has only one value that is 1. so i expected the same perfomance in all the query hoping that the sub query (select f(x) from dual) will be executed only 1 for all the queries. But i guess iam wrong.
Can you explain whats happening here