[20170612]FOR ALL COLUMNS SIZE repeat(11g).txt

--//昨天看了https://jonathanlewis.wordpress.com/2017/06/01/histogram-upgrade-2/,提到了直方图的问题,
--//特别是FOR ALL COLUMNS SIZE repeat引起的问题,在一些特殊情况要注意.

1.环境:
[email protected]> @ &r/ver1

PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

create table t (id number,pad varchar2(20),flag varchar2(1));
insert into t select rownum,lpad(‘a‘,20,‘a‘) ,‘a‘ from dual connect by level<=2e4;
insert into t select rownum+2e4,lpad(‘d‘,20,‘d‘) ,‘d‘ from dual connect by level<=2;
commit ;

[email protected]> SELECT flag, COUNT(*) FROM t GROUP BY flag;
F   COUNT(*)
- ----------
d          2
a      20000

[email protected]> exec dbms_stats.Gather_table_stats(ownname => user, tabname => ‘T‘,method_opt => ‘FOR ALL COLUMNS ‘);
PL/SQL procedure successfully completed.

select * from DBA_TAB_COL_STATISTICS where owner=user and table_name=‘T‘ and column_name=‘FLAG‘;

Record View
As of: 2017/6/12 9:35:03

OWNER:          SCOTT
TABLE_NAME:     T
COLUMN_NAME:    FLAG
NUM_DISTINCT:   2
LOW_VALUE:      61
HIGH_VALUE:     64
DENSITY:        0.000024997500249975
NUM_NULLS:      0
NUM_BUCKETS:    2
LAST_ANALYZED:  2017/6/12 9:33:35
SAMPLE_SIZE:    20002
GLOBAL_STATS:   YES
USER_STATS:     NO
AVG_COL_LEN:    2
HISTOGRAM:      FREQUENCY

--//建立了直方图.

[email protected]> set numw 36
[email protected]> select * from USER_TAB_HISTOGRAMS where column_name=‘FLAG‘;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER                       ENDPOINT_VALUE ENDPOINT_A
---------- ----------- --------------- ------------------------------------ ----------
T          FLAG                  20000 503652795277878000000000000000000000
T          FLAG                  20002 519229685853483000000000000000000000

--//如果应用模式发生变化,加入了2种值.

insert into t select rownum+2e4+2,lpad(‘b‘,20,‘b‘) ,‘b‘ from dual connect by level<=2e4;
insert into t select rownum+4e4+2,lpad(‘c‘,20,‘c‘) ,‘c‘ from dual connect by level<=2;
commit ;

[email protected]> exec dbms_stats.Gather_table_stats(ownname => user, tabname => ‘T‘,method_opt => ‘FOR ALL COLUMNS size repeat‘,no_invalidate=> false);
PL/SQL procedure successfully completed.

select * from DBA_TAB_COL_STATISTICS where owner=user and table_name=‘T‘ and column_name=‘FLAG‘;

Record View
As of: 2017/6/12 9:38:59

OWNER:          SCOTT
TABLE_NAME:     T
COLUMN_NAME:    FLAG
NUM_DISTINCT:   4
LOW_VALUE:      61
HIGH_VALUE:     64
DENSITY:        0.0000126552145963607
NUM_NULLS:      0
NUM_BUCKETS:    4
LAST_ANALYZED:  2017/6/12 9:38:10
SAMPLE_SIZE:    5432
GLOBAL_STATS:   YES
USER_STATS:     NO
AVG_COL_LEN:    2
HISTOGRAM:      FREQUENCY

--//因为bucket桶变成了4个,直方图依旧是FREQUENCY.

[email protected]> select * from USER_TAB_HISTOGRAMS where table_name=‘T‘ and column_name=‘FLAG‘;
TABLE_NAME COLUMN_NAME ENDPOINT_NUMBER                       ENDPOINT_VALUE ENDPOINT_A
---------- ----------- --------------- ------------------------------------ ----------
T          FLAG                   2775 503652795277878000000000000000000000
T          FLAG                   5430 508845092136413000000000000000000000
T          FLAG                   5431 514037388994948000000000000000000000
T          FLAG                   5432 519229685853483000000000000000000000

[email protected]> alter session set statistics_level=all;
Session altered.

[email protected]> select * from t where flag=‘c‘;
   ID PAD                  F
----- -------------------- -
40003 cccccccccccccccccccc c
40004 cccccccccccccccccccc c

[email protected]> @ &r/dpc ‘‘ ‘‘
PLAN_TABLE_OUTPUT
-------------------------------------
SQL_ID  g3pmd0h5vnw5r, child number 0
-------------------------------------
select * from t where flag=‘c‘

Plan hash value: 1601196873

--------------------------------------------------------------------------------------------------------------------
| Id  | Operation         | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| E-Time   | A-Rows |   A-Time   | Buffers |
--------------------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |      1 |        |       |    68 (100)|          |      2 |00:00:00.01 |     204 |
|*  1 |  TABLE ACCESS FULL| T    |      1 |      7 |   196 |    68   (0)| 00:00:01 |      2 |00:00:00.01 |     204 |
--------------------------------------------------------------------------------------------------------------------
Query Block Name / Object Alias (identified by operation id):
-------------------------------------------------------------
   1 - SEL$1 / [email protected]$1
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter("FLAG"=‘c‘)
23 rows selected.

--//可以发现E-rows 与 A-rows 差距不大,而12c的情况就不同了.12c如果使用method_opt => ‘FOR ALL COLUMNS size repeat‘后,
--//bucket=2,直方图变成了混合型直方图.也就是如果升级12c,要注意分析方法method_opt => ‘FOR ALL COLUMNS size repeat‘带来的问题.
--//再写有点长,另外写看12c的测试.

--//当然如果数据模型没有发生变化,问题可以不考虑.

时间: 2024-10-20 02:05:40

[20170612]FOR ALL COLUMNS SIZE repeat(11g).txt的相关文章

[20170612]FOR ALL COLUMNS SIZE repeat(12c).txt

--//昨天看了https://jonathanlewis.wordpress.com/2017/06/01/histogram-upgrade-2/,提到了直方图的问题,--//特别是FOR ALL COLUMNS SIZE repeat引起的问题,在一些特殊情况要注意. 1.环境:[email protected]> @ ver1PORT_STRING                    VERSION        BANNER                              

[20190219]那个更快(11g).txt

--//前几天测试11g Query Result Cache RC Latches时,链接http://blog.itpub.net/267265/viewspace-2632907/--//有网友指出测试有问题,建立索引唯一,并不会导致select count(*) from t,选择索引执行.实际上执行计划还是全表扫描.--//也就有了如下测试,不过结果有点让我吃惊,设置not null反而更慢.通过测试说明:--//另外我也做了10g下的测试,链接如下:http://blog.itpub

[20171211]ora-16014 11g.txt

--//上午测试了10g下备库log_archive_dest_1参数配置VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES)的错误.在11G也测试看看: 1.环境:[email protected]> @ &r/ver1PORT_STRING                    VERSION        BANNER------------------------------ -------------- ----------------------------

9i oracle数据库迁移到11G

一.迁移前查询110库 活动的用户为以下几个用户(BOSS,MD_QZY,SMART,SRDQ,RIMS) 120库 活动的用户(BOSS,SMART) select distinct username from v$session; BOSSMD_QZYRIMSSMARTSRDQ 关闭监听,杀进程ps -ef |grep ora|awk '{print $2}'|xargs kill -9 查看迁移前的对象个数(不同用户查看):set lin 200 pages 100select owner

[20180828]exadata--豆腐渣系统的保护神.txt

--//昨天看awr报表发现如下,时间8-9点报表,这个时间病房业务很少,主要门诊的业务: 1.awr报表情况:Top 10 Foreground Events by Total Wait Time Event                               Waits     Total Wait Time (sec)     Wait Avg(ms)     % DB time     Wait ClassDB CPU                               

基于oracle的sql优化方法论

Oracle数据库里SQL优化的终极目标就是要缩短目标SQL语句的执行时间.要达到上述目的,我们通常只有如下三种方法可以选择: 1.降低目标SQL语句的资源消耗: 2.并行执行目标SQL语句: 3.平衡系统的资源消耗. "方法1:降低目标SQL语句的资源消耗"以缩短执行时间,这是最常用的SQL优化方法.这种方法的核心是要么通过在不更改业务逻辑的情况下改写SQL来降低目标SQL语句的资源消耗,要么不改SQL但通过调整执行计划或相关表的数据来降低目标SQL语句的资源消耗. 方法2:并行执行

收集oracle统计信息

优化器统计范围: 表统计: --行数,块数,行平均长度:all_tables:NUM_ROWS,BLOCKS,AVG_ROW_LEN:列统计: --列中唯一值的数量(NDV),NULL值的数量,数据分布:             --DBA_TAB_COLUMNS:NUM_DISTINCT,NUM_NULLS,HISTOGRAM:索引统计:--叶块数量,等级,聚簇因子:             --DBA_INDEXES:LEAF_BLOCKS,CLUSTERING_FACTOR,BLEVEL:

exec dbms_stats.gather_schema_stats 手动优化统计

Oracle10g或以上版本.exec dbms_stats.gather_schema_stats(ownname => 'DFMS', options => 'GATHER AUTO',estimate_percent => dbms_stats.auto_sample_size, -- -- 11g取样值比较大,可以使用samplesize,10g好像是5~20%,可以根据需要调整 method_opt => 'for all columns size auto', -- 一

【重磅干货】看了此文,Oracle SQL优化文章不必再看!

听“俊”一席话,胜读十年书.看了这篇由DBA+社群联合发起人丁俊大师(网名:dingjun123)分享的SQL优化大作,其他Oracle SQL优化文章都不必再看了! 专家简介 丁俊 网名:dingjun123 DBA+社群联合发起人 性能优化专家,Oracle ACEA,ITPUB开发版资深版主.8年电信行业从业经验,在某大型电信系统提供商工作7年,任资深工程师,从事过系统开发与维护.业务架构和数据分析.系统优化等工作.擅长基于ORACLE的系统优化,精通SQL.PL/SQL.JAVA等.电子