您的位置:首页 > 其它

基础知识之11g新特性用extended statistics 解决列相关性

2013-01-21 09:01 316 查看
SQL> set wrap off
--创建测试表,reap列有比较高的重复率
SQL> create table t as select object_id,floor(object_id/10000) reap from dba_obj
ects;

表已创建。

SQL> set autotrace traceonly explain
--2级动态采样
SQL> select * from t where object_id<10000;

执行计划
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  8494 |   215K|    41   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |  8494 |   215K|    41   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter("OBJECT_ID"<10000)

Note
-----
- dynamic sampling used for this statement (level=2)

SQL> show parameter dynamic
SQL> show parameter dyna
--未动态采样
SQL> select /*+dynamic_sampling(t 0)*/* from t where object_id<10000;

执行计划
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   576 | 14976 |    40   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |   576 | 14976 |    40   (0)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter("OBJECT_ID"<10000)
--表级分析
SQL> exec dbms_stats.gather_table_stats('YWBZ','T');

PL/SQL 过程已成功完成。

SQL> select * from t where object_id<10000;

执行计划
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  8771 | 70168 |    41   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |  8771 | 70168 |    41   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter("OBJECT_ID"<10000)
--多谓词导致执行计划信息不准确
SQL> select * from t where object_id<10000 and reap=1;

执行计划
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |   975 |  7800 |    41   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |   975 |  7800 |    41   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter("REAP"=1 AND "OBJECT_ID"<10000)

SQL> set autotrace off
--实际记录数0
SQL> select count(*) from t where object_id<10000 and reap=1;

COUNT(*)
----------
0
-- extended statistics
SQL> exec dbms_stats.gather_table_stats('YWBZ','T',METHOD_OPT=>'FOR ALL COLUMNS
SIZE SKEWONLY FOR COLUMNS(OBJECT_ID,REAP) SIZE SKEWONLY');

PL/SQL 过程已成功完成。
--验证列相关性问题解决,统计信息较准确
SQL> select * from t where object_id<10000 and reap=1;

执行计划
----------------------------------------------------------
Plan hash value: 1601196873

--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |  195 |  960 |    21   (3)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| T    |  195 |  960 |    21   (3)| 00:00:01 |
--------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

1 - filter("OBJECT_ID"<10000 AND "REAP"=1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐