select X from
(select dbms_random.string('x',6) X from user_objects)
where replace(translate(upper(X),'ABCDEFGHIJKLMNOPQRSTUVXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA'),'A','')is not null;
is to the compiler the same as
select dbms_random.string('x',6) X
from user_objects
where replace( translate(upper(dbms_random.string('x',6),'...','....' )
is not null;
view merging.
You want to do something that'll prevent the view merging - such as:
ops$tkyte%ORA10GR2> select X
2 from (select dbms_random.string('x',6) X
3 from (select level l from dual connect by level <= 10)
4 )
5 where replace(translate(upper(X),'ABCDEFGHIJKLMNOPQRSTUVXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA'),'A','')is not null;
X
----------
R69GXC
G6XI7V
3GWTNL
BFIRAK
81CECA
FCGHJS
8316ZP
EUN6AK
YEX8OU
4Y1SU4
10 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 3020077840
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2002 | 2 (0)| 00:00:01 |
| 1 | VIEW | | 1 | 2002 | 2 (0)| 00:00:01 |
|* 2 | FILTER | | | | | |
| 3 | VIEW | | 1 | | 2 (0)| 00:00:01 |
|* 4 | CONNECT BY WITHOUT FILTERING| | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter(REPLACE(TRANSLATE(UPPER("DBMS_RANDOM"."STRING"('x',6)),'ABCDEFGHIJ
KLMNOPQRSTUVXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA'),'A','') IS NOT NULL)
4 - filter(LEVEL<=10)
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> column x format a10
ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> with data
2 as
3 (select dbms_random.string('x',6) x, rownum r
4 from (select level l from dual connect by level <= 10)
5 )
6 select *
7 from data
8 where replace(translate(upper(X),'ABCDEFGHIJKLMNOPQRSTUVXYZ','AAAAAAAAAAAAAAAAAAAAAAAAAA'),'A','')is not null;
X R
---------- ----------
NBKY0M 2
5JAIAE 3
WWZLKZ 4
G1675A 5
6947EM 6
G95H2H 7
5UFUWA 8
5K8JKK 9
LRRGD3 10
9 rows selected.
Execution Plan
----------------------------------------------------------
Plan hash value: 1045347588
----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 2015 | 2 (0)| 00:00:01 |
|* 1 | VIEW | | 1 | 2015 | 2 (0)| 00:00:01 |
| 2 | COUNT | | | | | |
| 3 | VIEW | | 1 | | 2 (0)| 00:00:01 |
|* 4 | CONNECT BY WITHOUT FILTERING| | | | | |
| 5 | FAST DUAL | | 1 | | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(REPLACE(TRANSLATE(UPPER("X"),'ABCDEFGHIJKLMNOPQRSTUVXYZ','AAAAAAAA
AAAAAAAAAAAAAAAAAA'),'A','') IS NOT NULL)
4 - filter(LEVEL<=10)
see the differences in the filter...