by 구루비스터디 CBO Optimizer DB_FILE_MULTIBLOCK_READ_COUNT [2018.07.14]
SQL>drop table t1 purge;
Table dropped.
SQL>create table t1(c1 int, c2 char(100), c3 char(100));
Table created.
SQL>create index t1_n1 on t1(c1);
Index created.
SQL>insert into t1
2 select level, 'dummy', 'dummy' from dual
3 connect by level <= 100000;
100000 rows created.
SQL>exec dbms_stats.gather_table_stats('ghlee', 't1');
PL/SQL procedure successfully completed.
SQL>alter session set "_optimizer_cost_model"=io;
Session altered.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 1000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
---------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
---------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 988 | 198K| 33 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 988 | 198K| 33 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 988 | | 3 |
---------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=1000)
Note
-----
- cpu costing is off (consider enabling it)
18 rows selected.
SQL>explain plan fo
2
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 2000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
---------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
---------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1988 | 399K| 64 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1988 | 399K| 64 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 1988 | | 5 |
---------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=2000)
Note
-----
- cpu costing is off (consider enabling it)
18 rows selected.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 10000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
----------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost |
----------------------------------------------------------
| 0 | SELECT STATEMENT | | 9990 | 2009K| 292 |
|* 1 | TABLE ACCESS FULL| T1 | 9990 | 2009K| 292 |
----------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("C1">=1 AND "C1"<=10000)
Note
-----
- cpu costing is off (consider enabling it)
17 rows selected.
SQL>
SQL>alter session set "_optimizer_cost_model"=cpu;
Session altered.
SQL>exec dbms_stats.delete_system_stats;
PL/SQL procedure successfully completed.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 1000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 988 | 198K| 33 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 988 | 198K| 33 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 988 | | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=1000)
14 rows selected.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 2000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1988 | 399K| 64 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1988 | 399K| 64 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 1988 | | 5 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=2000)
14 rows selected.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 10000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9990 | 2009K| 315 (0)| 00:00:04 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 9990 | 2009K| 315 (0)| 00:00:04 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 9990 | | 21 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=10000)
14 rows selected.
SQL>explain plan for
2 select /*+ full(t1) */ *
3 from t1
4 where c1 between 1 and 10000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9990 | 2009K| 664 (1)| 00:00:08 |
|* 1 | TABLE ACCESS FULL| T1 | 9990 | 2009K| 664 (1)| 00:00:08 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("C1"<=10000 AND "C1">=1)
13 rows selected.
SQL>alter session set "_optimizer_cost_model" = cpu;
Session altered.
SQL>begin
2 dbms_stats.set_system_stats('cpuspeed', 1680);
3 dbms_stats.set_system_stats('sreadtim', 5);
4 dbms_stats.set_system_stats('mreadtim', 10);
5 dbms_stats.set_system_stats('mbrc', 8);
6 end;
7 /
PL/SQL procedure successfully completed.
SQL> select * from sys.aux_stats$
SNAME PNAME PVAL1 PVAL2
--------------- --------------- -------- -------------------------
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 02-12-2009 00:19
SYSSTATS_INFO DSTOP 02-12-2009 00:19
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 1206
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM 5
SYSSTATS_MAIN MREADTIM 10
SYSSTATS_MAIN CPUSPEED 1680
SYSSTATS_MAIN MBRC 8
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 1000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 988 | 198K| 33 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 988 | 198K| 33 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 988 | | 3 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=1000)
14 rows selected.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 2000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1988 | 399K| 64 (0)| 00:00:01 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 1988 | 399K| 64 (0)| 00:00:01 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 1988 | | 5 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=2000)
14 rows selected.
SQL>explain plan for
2 select * from t1
3 where c1 between 1 and 10000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 1420382924
-------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9990 | 2009K| 316 (1)| 00:00:02 |
| 1 | TABLE ACCESS BY INDEX ROWID| T1 | 9990 | 2009K| 316 (1)| 00:00:02 |
|* 2 | INDEX RANGE SCAN | T1_N1 | 9990 | | 21 (0)| 00:00:01 |
-------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("C1">=1 AND "C1"<=10000)
14 rows selected.
SQL>explain plan for
2 select /*+ full(t1) */ *
3 from t1
4 where c1 between 1 and 10000;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 9990 | 2009K| 761 (1)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T1 | 9990 | 2009K| 761 (1)| 00:00:04 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("C1"<=10000 AND "C1">=1)
13 rows selected.
SQL>explain plan for
2 select * from t1;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100K| 19M| 761 (1)| 00:00:04 |
| 1 | TABLE ACCESS FULL| T1 | 100K| 19M| 761 (1)| 00:00:04 |
--------------------------------------------------------------------------
8 rows selected.
SQL>explain plan for
2 select * from t1
3 where c2='dummy';
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100K| 19M| 764 (2)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T1 | 100K| 19M| 764 (2)| 00:00:04 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("C2"='dummy')
13 rows selected.
SQL>explain plan for
2 select * from t1
3 where upper(c2)='DUMMY';
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 201K| 765 (2)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T1 | 1000 | 201K| 765 (2)| 00:00:04 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(UPPER("C2")='DUMMY')
13 rows selected.
SQL>explain plan for
2 select * from t1
3 where lower(upper(c2)) = 'dummy';
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1000 | 201K| 766 (2)| 00:00:04 |
|* 1 | TABLE ACCESS FULL| T1 | 1000 | 201K| 766 (2)| 00:00:04 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(LOWER(UPPER("C2"))='dummy')
13 rows selected.
SQL>explain plan for
2 select c1
3 from t1;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100K| 488K| 760 (1)| 00:00:04 |
| 1 | TABLE ACCESS FULL| T1 | 100K| 488K| 760 (1)| 00:00:04 |
--------------------------------------------------------------------------
8 rows selected.
SQL>explain plan for
2 select c1, c2
3 from t1;
Explained.
SQL>select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3617692013
--------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 100K| 10M| 761 (1)| 00:00:04 |
| 1 | TABLE ACCESS FULL| T1 | 100K| 10M| 761 (1)| 00:00:04 |
--------------------------------------------------------------------------
8 rows selected.
SQL>
- 강좌 URL : http://www.gurubee.net/lecture/3845
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.