KingbaseES 提供了对于分区表 global index 的支持。global index 不仅提供了对于唯一索引功能的改进(无需包含分区键),而且在性能上相比非global index (local index)有很大的提升(无法提供分区条件情况下)。以下举例说明二者在性能方面的差异。

1、准备数据

create table t1(id1 integer,id2 integer,name text) partition by hash(id1) partitions 200;

insert into t1 select generate_series(1,10000000),generate_series(1,10000000),repeat('a',500);

2、本地索引的性能

没有提供分区条件时

create index ind_t1_id2 on t1(id2);

test=# \di+ ind_t1_id2
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+------------+-------------------+--------+-------+---------+-------------
public | ind_t1_id2 | partitioned index | system | t1 | 0 bytes |
(1 row) test=# explain analyze select * from t1 where id2=10004;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
Append (cost=0.29..1662.50 rows=200 width=512) (actual time=1.324..3.249 rows=1 loops=1)
-> Index Scan using t1_p0_id2_idx on t1_p0 (cost=0.29..8.31 rows=1 width=512) (actual time=0.054..0.055 rows=0 loops=1)
Index Cond: (id2 = 10004)
-> Index Scan using t1_p1_id2_idx on t1_p1 (cost=0.29..8.31 rows=1 width=512) (actual time=0.065..0.065 rows=0 loops=1)
Index Cond: (id2 = 10004)
......
-> Index Scan using t1_p198_id2_idx on t1_p198 (cost=0.29..8.31 rows=1 width=512) (actual time=0.031..0.031 rows=0 loops=1)
Index Cond: (id2 = 10004)
-> Index Scan using t1_p199_id2_idx on t1_p199 (cost=0.29..8.31 rows=1 width=512) (actual time=0.025..0.025 rows=0 loops=1)
Index Cond: (id2 = 10004)
Planning Time: 39.262 ms
Execution Time: 5.673 ms
(403 rows)

使用非全局索引,并且没有提供分区条件情况下,优化器需要读取所有索引分区及表分区的统计数据,才能确定最优的执行计划。对于数据访问,同样需要访问所有分区的索引(即使该分区没有所需要的数据)。

提供分区条件时

test=# explain analyze select * from t1 where id2=10004 and id1=10004;
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
Index Scan using t1_p71_id2_idx on t1_p71 (cost=0.29..8.31 rows=1 width=512) (actual time=0.045..0.046 rows=1 loops=1)
Index Cond: (id2 = 10004)
Filter: (id1 = 10004)
Planning Time: 0.346 ms
Execution Time: 0.064 ms
(5 rows)

在提供分区条件情况下,只需要访问单个索引分区及表分区的统计数据,因此,所需的语句的解析时间更少。

3、全局索引的性能

create unique index ind_t1_id2 on t1(id2) global;

test=# \di+ ind_t1_id2
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+------------+--------------+--------+-------+--------+-------------
public | ind_t1_id2 | global index | system | t1 | 215 MB |
(1 row) test=# explain analyze select * from t1 where id2=10004;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------
Global Index Scan using ind_t1_id2 on t1 (cost=0.38..8.39 rows=200 width=512) (actual time=0.136..0.137 rows=1 loops=1)
Index Cond: (id2 = 10004)
Planning Time: 9.896 ms
Execution Time: 0.264 ms
(4 rows)

  

可以SQL 解析与执行时间都比本地索引的情景快很多。

全局索引与分区索引对于SQL性能影响的比较的更多相关文章

  1. oralce索引和分区索引的使用

    oracle分区表和分区索引的本质就是将数据分段存储,包括表和索引(索引从本质上来讲也是表),表分区会将表分成多个段分别存储.由此数据查询过程改变为先根据查询条件定位分区表,然后从该表中查询数据,从而 ...

  2. Oracle Spatial分区应用研究之七:同等分区粒度下全局索引优于分区索引的原因分析

    1.实验结论 同等分区粒度下,使用分区空间索引进行空间查询,比使用全局空间索引进行查询,对数据字典表的访问次数更多.假设分区数为X,则大概多3X次访问.具体说明见6实验结论. 2.实验目的 在之前的测 ...

  3. SQL Server创建复合索引时,复合索引列顺序对查询的性能影响

    说说复合索引 写索引的博客太多了,一直不想动手写,有一下两个原因:一是觉得有炒剩饭的嫌疑,有兄弟曾说:索引吗,只要在查询条件上建索引就行了,真的可以这么暴力吗?二来觉得,索引是个非常大的话题,很难概括 ...

  4. Oracle 分区表的索引、分区索引

    对于分区表,可以建立不分区索引.也就是说表分区,但是索引不分区.以下着重介绍分区表的分区索引. 索引与表一样,也可以分区.索引分为两类:locally partition index(局部分区索引). ...

  5. Atitit.分区对索引的影响 分区索引和全局索引 attilax总结

    Atitit.分区对索引的影响 分区索引和全局索引 attilax总结 1. 分区的好处1 2. 分区键:2 3. 分区的建议:2 4. 分区索引和全局索引:2 5. 全局索引就是在全表上创建索引, ...

  6. Oracle非分区索引,全局分区索引和本地分区索引。

    1.如果按照索引是否分区作为划分依据,Oracle 的索引类型可以分为非分区索引,全局分区索引和本地分区索引. 2.创建演示实例 --创建非分区表create table test_partition ...

  7. PLSQL_Oracle分区表和相应的分区索引管理和使用(案例)

    2014-08-22 Created By BaoXinjian

  8. 深入学习Oracle分区表及分区索引

    关于分区表和分区索引(About Partitioned Tables and Indexes)对于10gR2而言,基本上可以分成几类: •       Range(范围)分区 •       Has ...

  9. oracle 分区表和分区索引

    很复杂的样子,自己都没有看完,以备后用 http://hi.baidu.com/jsshm/item/cbfed8491d3863ee1e19bc3e ORACLE分区表.分区索引ORACLE对于分区 ...

随机推荐

  1. UiPath官网认证中文教程

    RPA之家公众号:RPA之家 RPA之家官网:http://rpazj.com 斗鱼直播:http://www.douyu.com/rpazj UiPath中文社区QQ群:465630324 RPA& ...

  2. python小题目练习(七)

    题目:实现如下图所示结果 代码实现: """Author:mllContent:模拟火车订票系统Date:2020-11-16"""# 定义 ...

  3. SpringBoot项目集成Swagger启动报错: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is

    使用的Swagger版本是2.9.2.knife4j版本是2.0.4. SpringBoot 版本是2.6.2将SpringBoot版本回退到2.5.6就可以正常启动

  4. docker安装node

    #1.拉取镜像 docker pull node:latest #2.运行 docker run -itd --name node-test --restart=always node #--rest ...

  5. 链表设计与Java实现,手写LinkedList这也太清楚了吧!!!

    链表设计与实现 在谈链表之前,我们先谈谈我们平常编程会遇到的很常见的一个问题.如果在编程的时候,某个变量在后续编程中仍需使用,我们可以用一个局部变量来保存该值,除此之外一个更加常用的方法就是使用容器了 ...

  6. shell判断参数值是否在数组内的方法

    比如定义数组: arr=("one" "tow" "thr" "three" "four") 1. ...

  7. ClickHouse(04)如何搭建ClickHouse集群

    ClickHouse集群的搭建和部署和单机的部署是类似的,主要在于配置的不一致,如果需要了解ClickHouse单机的安装设部署,可以看看这篇文章,ClickHouse(03)ClickHouse怎么 ...

  8. 01 开发App真机调试问题

    逍遥安卓模拟器 :https://juejin.cn/post/7062922018710093831 HBuilderX真机调试插上手机却提示"未检测到手机或浏览器"的问题:ht ...

  9. 微信公众号授权登录后报redirect_uri参数错误的问题

      在进行微信公众号二次开发的时候,需要通过授权码模式来进行微信授权.比如,在进行登录的时候,用户点击了登录按钮,然后弹出一个授权框,用户点击同意后,就可以获取用户的OpenId等信息了.这篇文章主要 ...

  10. YII事件EVENT示例

    模型中/** * 在初始化时进行事件绑定 */ public function init() { $this->on(self::EVENT_HELLO,[$this,'sendMail']); ...