zoukankan      html  css  js  c++  java
  • 压缩索引与普通索引对比

    SQL> drop table t1 purge;

    表已删除。

    SQL> create table t1 as select  * from emp;

    表已创建。

    SQL> insert into t1 select * from t1;

    已创建 14 行。

    SQL> /

    已创建 28 行。

    SQL> /

    已创建 56 行。

    SQL> /

    已创建 112 行。

    SQL> /

    已创建 224 行。

    SQL> /

    已创建 448 行。

    SQL> /

    已创建 896 行。

    SQL> /

    已创建 1792 行。

    SQL> /

    已创建 3584 行。

    SQL> /

    已创建 7168 行。

    SQL> /

    已创建 14336 行。

    SQL> /

    已创建 28672 行。

    SQL> commit;

    提交完成。

    SQL> drop table t2;
    drop table t2
               *
    第 1 行出现错误:
    ORA-00942: 表或视图不存在

    SQL> create table t2 as select * from t1;

    表已创建。

    SQL> create index i1 on t1(empno);

    索引已创建。

    SQL> create index i2 on t2(empno) compress;

    索引已创建。

    SQL> select blocks,lf_blks,lf_rows from index_stats;

    未选定行

    SQL> analyze index i1 validate structure;

    索引已分析

    SQL> select blocks,lf_blks,lf_rows from index_stats;

        BLOCKS    LF_BLKS    LF_ROWS
    ---------- ---------- ----------
           256        120      57344

    SQL> analyze index i2 validate structure;

    索引已分析

    SQL> select blocks,lf_blks,lf_rows from index_stats;

        BLOCKS    LF_BLKS    LF_ROWS
    ---------- ---------- ----------
           104         89      57344

    SQL> drop index i1;

    索引已删除。

    SQL> c/1/2
      1* drop index i2
    SQL> /

    索引已删除。

    SQL> alter table t1 modify(empno number);

    表已更改。

    SQL> c/1/2
      1* alter table t2 modify(empno number)
    SQL> /

    表已更改。

    SQL> update t1 set empno=rownum;

    已更新57344行。

    SQL> c/1/2
      1* update t2 set empno=rownum
    SQL> /

    已更新57344行。

    SQL> commit;

    提交完成。

    SQL> create index i1 on t1(empno);

    索引已创建。

    SQL> create index i2 on t2(empno) compress;

    索引已创建。

    SQL> analyze index i2 validate structure;

    索引已分析

    SQL> select blocks,lf_blks,lf_rows from index_stats;

        BLOCKS    LF_BLKS    LF_ROWS
    ---------- ---------- ----------
           256        175      57344

    SQL>
    SQL> analyze index i1 validate structure;

    索引已分析

    SQL> select blocks,lf_blks,lf_rows from index_stats;

        BLOCKS    LF_BLKS    LF_ROWS
    ---------- ---------- ----------
           256        127      57344

    分析:
    1.重复值较多时,压缩索引所占的块数和leaf blocks 都少于普通索引
    2.重复值较少时,压缩索引所占的块数和普通索引差不多,但是leaf blocks多余普通索引。
    3.压缩索引在update后重建,压缩索引所占的块数和leaf blocks会暴涨。

    结论:
    压缩索引适用于重复值多,且update较少的表。

  • 相关阅读:
    Microsoft Artificial Intelligence Conference(2018.05.21)
    Insider Dev Tour(2018.06.28)
    AWS re:Invent(2019.01.09)
    OPPO Developers Conference(2018.12.26)
    Tencent Cloud Developers Conference(2018.12.15)
    China Intelligent Office Summit(2018.11.21)
    International Programming Retreat Day(2018.11.17)
    Intel Artificial Intelligence Conference(2018.11.14)
    OSC Source Code Innovation Salon(2018.10.20)
    Java CAS 比较并且更换值
  • 原文地址:https://www.cnblogs.com/afx1007/p/4065966.html
Copyright © 2011-2022 走看看