索引优化系列十四--啥时分区索引性能反而低
admin
2023-05-14 21:42:30
0

drop table part_tab purge;

create table part_tab (id int,col2 int,col3 int)

        partition by range (id)

        (

        partition p1 values less than (10000),

        partition p2 values less than (20000),

        partition p3 values less than (30000),

        partition p4 values less than (40000),

        partition p5 values less than (50000),

        partition p6 values less than (60000),

        partition p7 values less than (70000),

        partition p8 values less than (80000),

        partition p9 values less than (90000),

        partition p10 values less than (100000),

        partition p11 values less than (maxvalue)

        )

        ;

insert into part_tab select rownum,rownum+1,rownum+2 from dual connect by rownum <=110000;

commit;

create  index idx_par_tab_col2 on part_tab(col2) local;

create  index idx_par_tab_col3 on part_tab(col3) ;


drop table norm_tab purge;

create table norm_tab  (id int,col2 int,col3 int);

insert into norm_tab select rownum,rownum+1,rownum+2 from dual connect by rownum <=110000;

commit;

create  index idx_nor_tab_col2 on norm_tab(col2) ;

create  index idx_nor_tab_col3 on norm_tab(col3) ;


set autotrace traceonly

set linesize 1000

set timing on 

select * from part_tab where col2=8 ;

执行计划

-----------------------------------------------------------------------------------------------------------------------

| Id  | Operation                          | Name             | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |

-----------------------------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT                   |                  |     1 |    39 |    13   (0)| 00:00:01 |       |       |

|   1 |  PARTITION RANGE ALL               |                  |     1 |    39 |    13   (0)| 00:00:01 |     1 |    11 |

|   2 |   TABLE ACCESS BY LOCAL INDEX ROWID| PART_TAB         |     1 |    39 |    13   (0)| 00:00:01 |     1 |    11 |

|*  3 |    INDEX RANGE SCAN                | IDX_PAR_TAB_COL2 |     1 |       |    12   (0)| 00:00:01 |     1 |    11 |

-----------------------------------------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

         24  consistent gets

          0  physical reads

          0  redo size

        539  bytes sent via SQL*Net to client

        416  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed

          

          

select * from norm_tab where col2=8 ;


执行计划

------------------------------------------------------------------------------------------------

| Id  | Operation                   | Name             | Rows  | Bytes | Cost (%CPU)| Time     |

------------------------------------------------------------------------------------------------

|   0 | SELECT STATEMENT            |                  |     1 |    39 |     2   (0)| 00:00:01 |

|   1 |  TABLE ACCESS BY INDEX ROWID| NORM_TAB         |     1 |    39 |     2   (0)| 00:00:01 |

|*  2 |   INDEX RANGE SCAN          | IDX_NOR_TAB_COL2 |     1 |       |     1   (0)| 00:00:01 |

------------------------------------------------------------------------------------------------

统计信息

----------------------------------------------------------

          0  recursive calls

          0  db block gets

          4  consistent gets

          0  physical reads

          0  redo size

        543  bytes sent via SQL*Net to client

        416  bytes received via SQL*Net from client

          2  SQL*Net roundtrips to/from client

          0  sorts (memory)

          0  sorts (disk)

          1  rows processed

        

        

        

          

select * from part_tab where col2=8 and id=2;

select * from norm_tab where col2=8 and id=2;


--查看索引高度等信息

select index_name,

          blevel,

          leaf_blocks,

          num_rows,

          distinct_keys,

          clustering_factor

     from user_ind_statistics

    where table_name in( 'NORM_TAB');

    

select index_name,

          blevel,

          leaf_blocks,

          num_rows,

          distinct_keys,

          clustering_factor FROM USER_IND_PARTITIONS where index_name like 'IDX_PAR_TAB%';



相关内容

热门资讯

产学研各界代表齐聚一堂,共议A... 封面新闻记者 易弋力 20支战队4小时巅峰对决;三位大咖三个不同视角解读“技术打法+产业路径+数据洞...
评论丨香蕉复仇、蓝莓出轨?警惕... AI技术降低了创作门槛,不等于降低了质量门槛和责任门槛;可以利用AI“手搓”短剧,但不应没下限地制造...
人工智能如何重塑电影行业?中国... 北京5月15日电 (记者 孙自法)人工智能生成内容(AIGC)正为众多行业带来深刻巨变,引发广泛关注...
济南隆超取得便捷式喷涂装置专利... 国家知识产权局信息显示,济南隆超石油机械锻造有限公司取得一项名为“一种便捷式喷涂装置”的专利,授权公...
原创 国... ## 国际空间站宇航员在微重力环境下与新鲜水果合影 维生素C很重要,即使在太空中也是如此。 来源:...
原创 低... 手机厂商的618活动陆续都开启了,在苹果宣布iPhone 17 Pro系列降价千元后,华为也迅速跟进...
微信第一行代码曝光! IT之家 5 月 15 日消息,据 CCF 计算机博物馆官方消息,2026 年 5 月 15 日,中...
光鼎电子取得LED数码管灌胶设... 国家知识产权局信息显示,连云港光鼎电子有限公司取得一项名为“一种LED数码管灌胶设备”的专利,授权公...
“兰州瓜农刺死城管”案二审维持... “兰州瓜农刺死城管”案有新进展。澎湃新闻从瓜农王爱文及其辩护律师处了解到,5月15日,甘肃省高院对此...
美国随访记者吐槽在北京被罚款,... 执笔/胡一刀&月半刀&宝刀刀美国福克斯新闻台的主持人,想在北京街头,拍一个阴阳中国社会治理的故事。当...