文章归档

a little experience on hacking clustering_factor

有些时候,系统中会出现部分SQL语句, 由于数据分布的原因, 无法正常使用索引,,基本的情形在前面翻译的Jonathan Lewis的文章中已经有所涉及.

下面是一个简单的Hack clustering_factor的方法(注意: 尽量不要使用,只有在正常分析表无法解决问题的时候, 又很难通过使用SPM或者SQL Profile的时候才可以考虑一试).
这样做会有以下几个弊端:

  • 1. 这么做的结果可能导致后续的维护有困难,,因为你的后任可能根本不知道你这么处理了.
  • 2. hack 系统的信息, 不是一种好的处理方式..:-)

下面是一个基本的处理过程

  • 1. 对于当前的SQL运行EXPLAIN PLAN, 并检查cost的大小
  • explain plan for
    select column_list
    from table_name m
    where m.column_name = ‘Y’
    and m.column_name2 in ( :1 , :2 , :3 , :4 , :5 , :6 , :7 , :8 , :9 );

  • 2. 添加使用index的提示,,运行EXPLAIN PLAN, 并检查cost的大小
  • explain plan for
    select /*+ index(m)*/column_list
    from table_name m
    where m.column_name = ‘Y’
    and m.column_name2 in ( :1 , :2 , :3 , :4 , :5 , :6 , :7 , :8 , :9 );

  • 3. 检查index segment的blocks以及当前的clustering_factor
  • select clustering_factor from dba_indexes where index_name = ‘INDEX_NAME’;
    select blocks from dba_segments where segment_name = ‘INDEX_NAME’;

  • 4. 设置clustering_factor
  • DBMS_STATS.SET_INDEX_STATS (ownname =>’OWNER’,indname => ‘INDEX_NAME’,clstfct => 100);

  • 5. 重做第1,2两步确认是否已经生效
  • No related posts.

    Leave a Reply

     

     

     

    You can use these HTML tags

    <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>