SQL> create table scott.tabcol as select owner,table_name,column_name,data_type,data_type_mod,data_type_owner from dba_tab_cols;
Table created.
SQL> create table scott.tabgrp as select column_name from dba_tab_cols group by column_name;
Table created.
SQL> alter table tabgrp add constraint pk_column primary key(column_name);
SQL> exec dbms_stats.gather_index_stats('SCOTT','PK_COLUMN');
SQL> exec dbms_stats.gather_table_stats('SCOTT','TABGRP');
SQL> create index idx_column on tabcol(column_name);
SQL> exec dbms_stats.gather_index_stats('SCOTT','IDX_COLUMN');
SQL> exec dbms_stats.gather_table_stats('SCOTT','TABCOL');
set autot trace exp stat;
select * from tabcol
where column_name = 'NAME'
or column_name in
(select column_name
from tabgrp
where column_name = 'NAME');
Execution Plan
----------------------------------------------------------
Plan hash value: 339360689
---------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
---------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 2130 | 85200 | 74 (2)| 00:00:01 |
|* 1 | FILTER | | | | | |
| 2 | TABLE ACCESS FULL | TABCOL | 42311 | 1652K| 74 (2)| 00:00:01 |
|* 3 | FILTER | | | | | |
|* 4 | INDEX UNIQUE SCAN| PK_COLUMN | 1 | 12 | 1 (0)| 00:00:01 |
---------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("COLUMN_NAME"='NAME' OR EXISTS (SELECT /*+ */ 0 FROM
"TABGRP" "TABGRP" WHERE :B1='NAME' AND "COLUMN_NAME"=:B2))
3 - filter(:B1='NAME')
4 - access("COLUMN_NAME"=:B1)
select t1.* from tabcol t1,(select column_name from tabgrp where column_name = 'NAME') t2
where t1.column_name = t2.column_name and t1.column_name = 'NAME';
Execution Plan
----------------------------------------------------------
Plan hash value: 2228261001
-------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 52 | 3 (0)| 00:00:01 |
| 1 | NESTED LOOPS | | 1 | 52 | 3 (0)| 00:00:01 |
|* 2 | INDEX UNIQUE SCAN | PK_COLUMN | 1 | 12 | 1 (0)| 00:00:01 |
| 3 | TABLE ACCESS BY INDEX ROWID| TABCOL | 1 | 40 | 2 (0)| 00:00:01 |
|* 4 | INDEX RANGE SCAN | IDX_COLUMN | 1 | | 1 (0)| 00:00:01 |
-------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("COLUMN_NAME"='NAME')
4 - access("T1"."COLUMN_NAME"='NAME')
filter("T1"."COLUMN_NAME"="COLUMN_NAME")
|