Bo's Oracle Station

查看: 1671|回复: 0

复合列扩展统计信息

[复制链接]

1005

主题

1469

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
12012
发表于 2022-5-16 14:59:57 | 显示全部楼层 |阅读模式
1. 准备环境:
  1. [oracle@cvcdds198 ~]$ . oraenv
  2. ORACLE_SID = [rcat] ?
  3. The Oracle base remains unchanged with value /u01/app/oracle
  4. [oracle@cvcdds198 ~]$ sqlplus /nolog

  5. SQL*Plus: Release 19.0.0.0.0 - Production on Mon May 16 14:21:31 2022
  6. Version 19.3.0.0.0

  7. Copyright (c) 1982, 2019, Oracle.  All rights reserved.

  8. SQL> conn sh/oracle_4U
  9. Connected.
  10. SQL> create table t1( a  varchar2(20) , b varchar2(20) , c varchar2(20)) ;

  11. Table created.
复制代码
  1. SQL> begin
  2.   2  for i in 1..100000
  3.   3  loop
  4.   4   insert into t1 values ( 'a','b','c');
  5.   5  end loop;
  6.   6  commit;
  7.   7  end;
  8.   8  /

  9. PL/SQL procedure successfully completed.

  10. SQL> insert into t1 values ( 'x','y','c');        

  11. 1 row created.

  12. SQL> commit;

  13. Commit complete.
复制代码
  1. SQL> create index ia on t1(a) ;

  2. Index created.

  3. SQL> create index ib on t1(b) ;

  4. Index created.

  5. SQL> create index ic on t1(c) ;

  6. Index created.
复制代码
收集优化器统计信息:
  1. SQL>  exec dbms_stats.gather_table_stats('hr','t1', estimate_percent=>100, method_opt=>'for all columns size auto',cascade=>true);  --注意如果使用size skewonly会用索引访问,都不必要收集下面的复合列统计信息,说明skewonly功能还是比auto强

  2. PL/SQL procedure successfully completed.
复制代码
2. 第一次执行查询:
  1. SQL> set linesize 10000
  2. SQL> set autot on  
  3. SQL> select  * from t1 where a='x' and b='y' and c='c';

  4. A                     B                          C
  5. -------------------- -------------------- --------------------
  6. x                     y                          c


  7. Execution Plan
  8. ----------------------------------------------------------
  9. Plan hash value: 3617692013

  10. --------------------------------------------------------------------------
  11. | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time         |
  12. --------------------------------------------------------------------------
  13. |   0 | SELECT STATEMENT  |         | 25000 |   146K|    69   (2)| 00:00:01 |
  14. |*  1 |  TABLE ACCESS FULL| T1         | 25000 |   146K|    69   (2)| 00:00:01 |
  15. --------------------------------------------------------------------------

  16. Predicate Information (identified by operation id):
  17. ---------------------------------------------------

  18.    1 - filter("A"='x' AND "B"='y' AND "C"='c')

  19. Note
  20. -----
  21.    - automatic DOP: Computed Degree of Parallelism is 1 because of parallel threshold


  22. Statistics
  23. ----------------------------------------------------------
  24.          53  recursive calls
  25.           5  db block gets
  26.         287  consistent gets
  27.           0  physical reads
  28.         936  redo size
  29.         688  bytes sent via SQL*Net to client
  30.         411  bytes received via SQL*Net from client
  31.           2  SQL*Net roundtrips to/from client
  32.          13  sorts (memory)
  33.           0  sorts (disk)
  34.           1  rows processed<b><font size="3">
  35. </font></b>
复制代码
3. 收集复合列扩展统计信息:
  1. declare
  2. v1 varchar2(200);
  3. begin
  4. v1 :=dbms_stats.create_extended_stats('SH','T1','(a,b,c)');
  5. end;
  6. /

  7. begin
  8. dbms_stats.gather_table_stats('sh','t1',estimate_percent=>100,
  9.                             method_opt=>'for all columns size auto for columns (a,b,c) size skewonly', cascade=>true);
  10. end;
  11. /
复制代码
  1. select   * from dba_tab_col_statistics where owner='SH' and table_name='T1';   
复制代码
SH    T1    C    1    63    63    0.0000049999500005    0    1    16-MAY-22    100001    YES    NO        2    FREQUENCY    SHARED
SH    T1    SYS_STUM4KJU$CCICS9C1UJ6UWC4YP    2    C55A571A4A12    C55F2A1E5C3A    0.0000049999500005    0    2    16-MAY-22    100001    YES    NO        12    FREQUENCY    SHARED
SH    T1    A    2    61    78    0.0000049999500005    0    2    16-MAY-22    100001    YES    NO        2    FREQUENCY    SHARED
SH    T1    B    2    62    79    0.0000049999500005    0    2    16-MAY-22    100001    YES    NO        2    FREQUENCY    SHARED

4. 第二次执行查询:
  1. SQL> select  * from t1 where a='x' and b='y' and c='c';

  2. A                     B                          C
  3. -------------------- -------------------- --------------------
  4. x                     y                          c


  5. Execution Plan
  6. ----------------------------------------------------------
  7. Plan hash value: 38189099

  8. --------------------------------------------------------------------------------------------
  9. | Id  | Operation                            | Name | Rows  | Bytes | Cost (%CPU)| Time           |
  10. --------------------------------------------------------------------------------------------
  11. |   0 | SELECT STATEMENT                    |           |         1 |         6 |         2   (0)| 00:00:01 |
  12. |*  1 |  TABLE ACCESS BY INDEX ROWID BATCHED| T1   |         1 |         6 |         2   (0)| 00:00:01 |
  13. |*  2 |   INDEX RANGE SCAN                    | IA   |         1 |           |         1   (0)| 00:00:01 |
  14. --------------------------------------------------------------------------------------------

  15. Predicate Information (identified by operation id):
  16. ---------------------------------------------------

  17.    1 - filter("B"='y' AND "C"='c')
  18.    2 - access("A"='x')

  19. Note
  20. -----
  21.    - automatic DOP: Computed Degree of Parallelism is 1 because of parallel threshold


  22. Statistics
  23. ----------------------------------------------------------
  24.          12  recursive calls
  25.           0  db block gets
  26.          16  consistent gets
  27.           0  physical reads
  28.           0  redo size
  29.         688  bytes sent via SQL*Net to client
  30.         411  bytes received via SQL*Net from client
  31.           2  SQL*Net roundtrips to/from client
  32.           0  sorts (memory)
  33.           0  sorts (disk)
  34.           1  rows processed
复制代码





回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Bo's Oracle Station   

GMT+8, 2024-4-27 13:37 , Processed in 0.076693 second(s), 24 queries .

快速回复 返回顶部 返回列表