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较少的表。

  • 相关阅读:
    小程序请求Django后台及路由跳转
    git操作
    github 介绍
    小程序01
    HTML5要点(四)对象全整理
    JavaScript要点(十二) HTML DOM 事件
    JavaScript要点(九)HTML DOM
    JavaScript要点(八) 闭包
    inferred 和 freefrom
    MySql数据库实现分布式的主从结构
  • 原文地址:https://www.cnblogs.com/afx1007/p/4065966.html
Copyright © 2011-2022 走看看