[20130809]12c Clustering Factor(2).txt

[20130809]12c Clustering Factor(2).txt

参考以下链接,自己重复测试:

http://richardfoote.wordpress.com/2013/05/14/clustering-factor-calculation-improvement-part-ii-blocks-on-blocks/

1.测试环境:

SQL> @ver
BANNER                                                                               CON_ID
-------------------------------------------------------------------------------- ----------
Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production              0

2.测试1:

SQL> create table major_tom (id number, DOB date, text varchar2(30));
Table created.
SQL> insert into major_tom select rownum,  sysdate-trunc(dbms_random.value(0, 20000)), 'DAVID BOWIE' from dual connect by level 
2000000 rows created.
SQL> commit;
Commit complete.
SQL> create index major_tom_dob_i on major_tom(dob);
Index created.
SQL> EXEC dbms_stats.gather_table_stats(ownname=>user, tabname=>'MAJOR_TOM', estimate_percent=> null, cascade=> true, method_opt=>'FOR ALL COLUMNS SIZE 1');
PL/SQL procedure successfully completed.
SQL>SELECT t.table_name, i.index_name, t.blocks, t.num_rows, i.clustering_factor FROM user_tables t, user_indexes i WHERE
t.table_name = i.table_name AND i.index_name='MAJOR_TOM_DOB_I';
TABLE_NAME INDEX_NAME                         BLOCKS   NUM_ROWS CLUSTERING_FACTOR
---------- ------------------------------ ---------- ---------- -----------------
MAJOR_TOM  MAJOR_TOM_DOB_I                      9077    2000000           1988246

--可以发现插入的日期非常随机,CF很大。接近NUM_ROWS。

SQL> exec dbms_stats.set_table_prefs(ownname=>user, tabname=>'MAJOR_TOM', pname=>'TABLE_CACHED_BLOCKS', pvalue=>255);
PL/SQL procedure successfully completed.
SQL> EXEC dbms_stats.gather_index_stats(ownname=>user, indname=>'MAJOR_TOM_DOB_I', estimate_percent=> null);
PL/SQL procedure successfully completed.
SQL> SELECT t.table_name, i.index_name, t.blocks, t.num_rows, i.clustering_factor FROM user_tables t, user_indexes i WHERE
t.table_name = i.table_name AND i.index_name='MAJOR_TOM_DOB_I';
TABLE_NAME INDEX_NAME                         BLOCKS   NUM_ROWS CLUSTERING_FACTOR
---------- ------------------------------ ---------- ---------- -----------------
MAJOR_TOM  MAJOR_TOM_DOB_I                      9077    2000000           1941549

--可以发现CF几乎没有变化,255块被cache,相比9077块仅仅占用很少的一部分。
--看来这个参数对CF的增强非常有限,特别是一些大表,几乎没有作用。

3.测试2:

SQL> create table ziggy (id number, code number, text varchar2(30));
Table created.
SQL> insert into ziggy select rownum,  trunc(dbms_random.value(0, 100)), 'DAVID BOWIE' from dual connect by level 
2000000 rows created.
SQL> commit;
Commit complete.
SQL> create index ziggy_code_i on ziggy(code);
Index created.
SQL> EXEC dbms_stats.gather_table_stats(ownname=>user, tabname=>'ZIGGY', estimate_percent=> null, cascade=> true,method_opt=>'FOR ALL COLUMNS SIZE 1');
PL/SQL procedure successfully completed.
SQL> SELECT t.table_name, i.index_name, t.blocks, t.num_rows, i.clustering_factor FROM user_tables t, user_indexes i WHERE
t.table_name = i.table_name AND i.index_name='ZIGGY_CODE_I';
TABLE_NAME INDEX_NAME                         BLOCKS   NUM_ROWS CLUSTERING_FACTOR
---------- ------------------------------ ---------- ---------- -----------------
ZIGGY      ZIGGY_CODE_I                         7048    2000000            662624

SQL> exec dbms_stats.set_table_prefs(ownname=>user, tabname=>'ZIGGY', pname=>'TABLE_CACHED_BLOCKS', pvalue=>255);
PL/SQL procedure successfully completed.
SQL> EXEC dbms_stats.gather_index_stats(ownname=>user, indname=>'ZIGGY_CODE_I', estimate_percent=>null);
PL/SQL procedure successfully completed.
SELECT t.table_name, i.index_name, t.blocks, t.num_rows, i.clustering_factor
FROM user_tables t, user_indexes i
WHERE t.table_name = i.table_name AND i.index_name='ZIGGY_CODE_I';
TABLE_NAME INDEX_NAME                         BLOCKS   NUM_ROWS CLUSTERING_FACTOR
---------- ------------------------------ ---------- ---------- -----------------
ZIGGY      ZIGGY_CODE_I                         7048    2000000            662624

--可以发现几乎没有变化,按照作者的解析:

    The table has some 7048 blocks but each distinct CODE value has some 20,000 occurrences on average. Therefore, each
value is going to be found 20000/7048 = roughly 2 to 3 times per block. As the index is in CODE order and for each CODE
in rowid order, the CF is going to increment for each CODE value for each distinct block we visit. We will therefore
only go back to a previously visited table block (except for the 2 to 3 visits to the current block) when the CODE value
changes but this will take us all the way back to the first block which is always going to be some 7047 blocks away from
the current one. As 7047 is much greater than the 255 the CF calculation will only cater for, the CF is going to remain
unchanged from the default calculation as a result.

-- code 的变化仅仅从0-99,100种变化,每个值出现20,000次,这样1个值在一个块中出现 20000/7048 ,约2-3次,这样cache=255,对于
-- CF的计算影响很小。

--总之,这个参数在许多情况下,改进很小。

时间: 2024-08-26 04:07:53

[20130809]12c Clustering Factor(2).txt的相关文章

[20130809]12c Clustering Factor.txt

[20130809]12c Clustering Factor.txt 以前在11G以前,如果使用assm,表的CF经常会很大,即使你插入的像顺序号这样的字段,由于多个会话同时操作,插入的数据分布的不同的块中,以顺序号为索引的CF也会变得很大,甚至接近记录的数量.这个在<基于成本的优化>里面也有介绍. 但是在12g可以设置一个参数改善这种情况,做一些测试看看. 参考了Richard Foote大师的blog:http://richardfoote.wordpress.com/2013/05/0

[20170620]11G 12c expand sql text.txt

[20170620]11G 12c expand sql text.txt --//原来写的脚本只能分别在11g,12c单独使用.上午花一点点时间.把两者整合起来. --//讨论链接:http://www.itpub.net/thread-2088981-1-1.html --//再次感谢solomon_007的指点: set long 20000 set serveroutput on declare     L_sqltext clob := null;     l_version varc

[20170114]12c varchar2类型直方图.txt

[20170114]12c varchar2类型直方图.txt --我曾经提到慎用nvarchar2数据类型,链接:http://blog.itpub.net/267265/viewspace-2120925/ --我那里提到数据类型nvarchar2类型,因为1个字符占用2个字节,这样如果前面16个字符重复很多,直方图的建立就是鸡肋, --毫无用处(因为分析仅仅对前面32个字节有效),12c 直方图支持更多类型: 高度直方图,频率直方图.混和类型(HYBRID). --看看12c关于直方图方面

[20170603]12c Top Frequency histogram.txt

[20170603]12c Top Frequency histogram.txt --//个人对直方图了解很少,以前2种直方图类型对于目前的许多应用来讲已经足够,或者讲遇到的问题很少. --//抽一点点时间,简单探究12c Top Frequency histogram. --//以前的频率直方图Frequency histogram,受限bucket(桶的大小),如果有255个不同值,oracle分析后不会建立频率直方图,而是建立高 --//度直方图.这样的情况会导致一些流行值的统计在显示执

[20160806]12c 与 WMSYS.WM_CONCAT.txt

[20160806]12c 与 WMSYS.WM_CONCAT.txt --前几天有人问临时表空间消耗的问题,链接: http://www.itpub.net/thread-2065053-1-1.html --我提到11g的wmsys.wm_concat也会使用临时表空间. --链接:http://blog.itpub.net/267265/viewspace-1356256/ --但是在12c测试发现12c已经不存在WMSYS.WM_CONCAT,看来要建议开发不要在使用它连接字符串. --

[20131109]deferred segment creation与12c的exp命令.txt

[20131109]deferred segment creation与12c的exp命令.txt 参考链接:http://space.itpub.net/267265/viewspace-713311 昨天想导出一些数据在自己的12c测试环境,发现具有段延迟建立特性的表使用exp也能导出. 例子如下: SCOTT@test01p> @ver BANNER                                                                       

[20131128]12c的dbms_utility.expand_sql_text.txt

[20131128]12c的dbms_utility.expand_sql_text.txt SCOTT@ztest> @verBANNER                                                                              CON_ID-------------------------------------------------------------------------------- ----------Oracl

[20130803]ORACLE 12C RMAN 功能增强.txt

[20130803]ORACLE 12C RMAN 功能增强.txt 在oracle 12c rman中可以直接输入sql语句,缺点就是仅仅输出最大仅仅80列,不知道如何调整. d:\tmp>rman target sys/xxxx@test01p Recovery Manager: Release 12.1.0.1.0 - Production on Fri Aug 2 22:53:49 2013 Copyright (c) 1982, 2013, Oracle and/or its affi

Oracle聚簇因子(Clustering factor,CF)

Oracle 聚簇因子(Clustering factor)   聚簇因子是 Oracle 统计信息中在CBO优化器模式下用于计算cost的参数之一,决定了当前的SQL语句是否走索引,还是全表扫描以及是否作为嵌套连接外部表等.如此这般,那到底什么是聚簇因子,那些情况下会影响到聚簇因子,以及如何提高聚簇因子?本文将对此展开描述.   1.堆表的存储方式    Oralce 数据库系统中最普通,最为常用的即为堆表.     堆表的数据存储方式为无序存储,也就是任意的DML操作都可能使得当前数据块存在