更新时间:2022-09-06 23:18:56
@ver
BANNER CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production 0
SCOTT@test01p> create table t as select * from emp ;
Table created.
SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID grp1wk6pwfkvr, child number 0
-------------------------------------
create table t as se
Plan hash value: 2748781111
--------------------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)| OMem | 1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | | 4 (100)| | | |
| 1 | LOAD AS SELECT | | | | 1036K| 1036K| 1036K (0)|
| 2 | OPTIMIZER STATISTICS GATHERING | | 14 | 3 (0)| | | |
| 3 | TABLE ACCESS FULL | EMP | 14 | 3 (0)| | | |
----------------------------------------------------------------------------------------------------可以发现执行计划存在OPTIMIZER STATISTICS GATHERING。
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T 14 2013-09-18 22:27:31
--可以发现收集了表的统计信息。
SCOTT@test01p> select column_name, num_distinct, histogram,notes from user_tab_col_statistics where table_name = 'T' ;
COLUMN_NAME NUM_DISTINCT HISTOGRAM NOTES
-------------------- ------------ --------------- -----------------------------------------
EMPNO 14 NONE STATS_ON_LOAD
ENAME 14 NONE STATS_ON_LOAD
JOB 5 NONE STATS_ON_LOAD
MGR 6 NONE STATS_ON_LOAD
HIREDATE 13 NONE STATS_ON_LOAD
SAL 12 NONE STATS_ON_LOAD
COMM 4 NONE STATS_ON_LOAD
DEPTNO 3 NONE STATS_ON_LOAD
SCOTT@test01p> drop table t purge ;
Table dropped.
SCOTT@test01p> create table t as select * from emp where 1=2;
Table created.
SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 9r2x17fxjgutq, child number 0
-------------------------------------
create table t as se
Plan hash value: 2561008478
-----------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
-----------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | | 1 (100)|
| 1 | LOAD AS SELECT | | | |
| 2 | OPTIMIZER STATISTICS GATHERING | | 14 | 3 (0)|
|* 3 | FILTER | | | |
| 4 | TABLE ACCESS FULL | EMP | 14 | 3 (0)|
-----------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
3 - filter(NULL IS NOT NULL)
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T 0 2013-09-18 22:32:48
SCOTT@test01p> insert into t select * from emp where rownum
5 rows created.
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T 0 2013-09-18 22:32:48
--插入5行记录,可以发现没有 direct-path data loading operation,并不会分析表。
SCOTT@test01p> insert /*+ append */ into t select * from emp ;
14 rows created.
SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 99wpy6dhfk4j7, child number 0
-------------------------------------
insert /*+ append */ into t select * from emp
Plan hash value: 2748781111
-----------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)|
-----------------------------------------------------------------------
| 0 | INSERT STATEMENT | | | 3 (100)|
| 1 | LOAD AS SELECT | | | |
| 2 | OPTIMIZER STATISTICS GATHERING | | 14 | 3 (0)|
| 3 | TABLE ACCESS FULL | EMP | 14 | 3 (0)|
-----------------------------------------------------------------------
SCOTT@test01p> commit ;
Commit complete.
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T 0 2013-09-18 22:32:48
--?? 奇怪这样并没有收集表的统计信息。
SCOTT@test01p> drop table t purge ;
Table dropped.
SCOTT@test01p> create table t as select * from emp where 1=2;
Table created.
SCOTT@test01p> insert /*+ append */ into t select * from emp ;
14 rows created.
SCOTT@test01p> commit;
Commit complete.
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T 14 2013-09-18 22:41:44
SCOTT@test01p> create table t as select /*+ NO_GATHER_OPTIMIZER_STATISTICS */ * from emp ;
Table created.
SCOTT@test01p> @dpc '' ''
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID 60f2a25kbbyz6, child number 0
-------------------------------------
create table t as se
--?为什么显示不全呢?
Plan hash value: 2748781111
----------------------------------------------------------------------------------------
| Id | Operation | Name | E-Rows | Cost (%CPU)| OMem | 1Mem | Used-Mem |
----------------------------------------------------------------------------------------
| 0 | CREATE TABLE STATEMENT | | | 4 (100)| | | |
| 1 | LOAD AS SELECT | | | | 1036K| 1036K| 1036K (0)|
| 2 | TABLE ACCESS FULL | EMP | 14 | 3 (0)| | | |
----------------------------------------------------------------------------------------
SCOTT@test01p> select table_name, num_rows, last_analyzed from user_tables where table_name='T';
TABLE_NAME NUM_ROWS LAST_ANALYZED
---------- ---------- -------------------
T
SCOTT@test01p> select column_name, num_distinct, histogram,notes from user_tab_col_statistics where table_name = 'T' ;
no rows selected