KingbaseES 全局索引
概述:在分区表上创建的索引可分为全局索引和本地索引。全局索引包括全局非分区索引(Global Nonpartitioned Indexes)和全局分区索引(Global Partitioned Indexes)。
- 全局分区索引(Global Partitioned Indexes)是指与分区表有不同分区方式的索引,它是在分区表的所有分区数据基础上创建的分区索引,目前KingbaseES 暂不支持。
- 本地索引(本地分区索引,Local Partitioned Indexes),是指在每个表分区上单独创建的索引,是一种局部索引,也是一种分区索引,某一个索引分区只能索引到一个表分区。
- 需要启用 enable_globalindexscan = on; 才能使用全局索引。目前只支持select 操作使用全局索引。
1、全局索引例子
create table t1_part(id1 integer,id2 integer,id3 integer)
partition by range(id1)
(
partition part01 values less than(10000),
partition part02 values less than(20000),
partition part03 values less than(30000),
partition part04 values less than(40000),
partition part05 values less than(50000),
partition part06 values less than(60000),
partition part07 values less than(70000),
partition part08 values less than(80000),
partition part09 values less than(90000),
partition part10 values less than(maxvalue)
); create unique index idx1_t1_part on t1_part(id1) global ;
create unique index idx2_t1_part on t1_part(id2) global ;
create index idx3_t1_part on t1_part(id2) global ;
注意:并不是global 就一定是全局索引。当创建全局索引时,首先尝试创建本地索引。当不满足本地索引的条件(唯一索引的索引列不包括全部分区列或者分区条件为表达式)时会创建全局索引。同样,启用分区表上的主键/唯一约束时,先尝试创建本地索引,不满足时则创建全局唯一索引。可以看到,只有第二个索引才是全局索引。
test=# \di+ idx1_t1_part
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+--------------+-------------------+--------+---------+---------+-------------
public | idx1_t1_part | partitioned index | system | t1_part | 0 bytes |
(1 row) test=# \di+ idx2_t1_part
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+--------------+--------------+--------+---------+------------+-------------
public | idx2_t1_part | global index | system | t1_part | 8192 bytes |
(1 row) test=# \di+ idx3_t1_part
List of relations
Schema | Name | Type | Owner | Table | Size | Description
--------+--------------+-------------------+--------+---------+---------+-------------
public | idx3_t1_part | partitioned index | system | t1_part | 0 bytes |
(1 row)
全局索引支持条件索引,不支持全局分区索引。全局索引不支持排他约束。
2、全局索引存在的限制
DML操作不允许针对子表 使用全局索引。
test=# delete from t1_part_part04 where id2=31111; --使用全局索引访问子表
ERROR: cannot modify partition t1_part_part04 with global indexes, maintain the partitioned table directly
test=# select * from t1_part_part04 where id2=31111;
id1 | id2 | id3
-----+-----+-----
(0 rows)
test=# delete from t1_part where id2=31111;
DELETE 1
3、分区索引与全局索引的性能比较
继续以上的例子,插入100000 条记录:
insert into t1_part select generate_series(1,100000),generate_series(1,100000),generate_series(1,100000);
来看执行性能的差异:
test=# declare
test-# v_result integer;
test-# begin
test-# for i in 1..100000 loop
test-# select id3 into v_result from t1_part where id1=i;
test-# end loop;
test-# end;
test-# /
ANONYMOUS BLOCK
Time: 1320.094 ms (00:01.320)
test=#
test=# declare
test-# v_result integer;
test-# begin
test-# for i in 1..100000 loop
test-# select id3 into v_result from t1_part where id2=i;
test-# end loop;
test-# end;
test-# /
ANONYMOUS BLOCK
Time: 4281.198 ms (00:04.281)
比较结果分析:
1、local 索引的访问效率是 global 索引3倍左右
2、Oracle 的rowid 直接定位数据文件的数据块,而KingbaseES 的ctid 只是对象文件的第几块,因此,KingbaseES 的全局索引需要先定位该 ctid 属于哪个分区的。
3、KingbaseES 全局索引在索引值包含对象 OID,通过OID找到对应的文件,再通过ctid 访问。这必然有性能的损耗,但这是因为ctid 的结构所导致的。
4、全局索引暂时不支持index_only_scan
KingbaseES 全局索引的更多相关文章
- KingbaseES 全局索引是否因为DDL操作而变为Unusable ?
前言 Oracle 在对分区做DDL操作时,会使分区全局索引失效,需要加上关键字update global indexes.KingbaseES 同样支持全局索引.那么,如果对分区表进行DDL操作,那 ...
- 全局索引与分区索引对于SQL性能影响的比较
KingbaseES 提供了对于分区表 global index 的支持.global index 不仅提供了对于唯一索引功能的改进(无需包含分区键),而且在性能上相比非global index (l ...
- KingbaseES 全局临时表
Postgresql 支持会话级别的临时表,表的存续期只在创建临时表的会话存活期间,会话退出后,临时表自动删除,表结构及数据也无法跨会话共享.KingbaseES 除了支持PG原生的临时表机制外,还支 ...
- ORACLE 全局索引和本地索引
Oracle数据库中,有两种类型的分区索引,全局索引和本地索引,其中本地索引又可以分为本地前缀索引和本地非前缀索引.下面就分别看看每种类型的索引各自的特点. 全局索引以整个表的数据为对象建立索引,索引 ...
- Oracle 12C 新特性之表分区带 异步全局索引异步维护(一次add、truncate、drop、spilt、merge多个分区)
实验准备:-- 创建实验表CREATE TABLE p_andy(ID number(10), NAME varchar2(40))PARTITION BY RANGE (id)(PARTITION ...
- [z]分区truncate操作的介绍及对全局索引和空间释放影响的案例解析
[z]https://www.2cto.com/database/201301/181226.html 环境: [sql] [oracle@localhost ~]$ uname -r 2.6.18- ...
- Oracle12c中性能优化&功能增强新特性之全局索引DROP和TRUNCATE 分区的异步维护
Oracle 12c中,通过延迟相关索引的维护可以优化某些DROP和TRUNCATE分区命令的性能,同时,保持全局索引为有效. 1. 设置 下面的例子演示带全局索引的表创建和加载数据的过程. -- ...
- Atitit.分区对索引的影响 分区索引和全局索引 attilax总结
Atitit.分区对索引的影响 分区索引和全局索引 attilax总结 1. 分区的好处1 2. 分区键:2 3. 分区的建议:2 4. 分区索引和全局索引:2 5. 全局索引就是在全表上创建索引, ...
- Oracle Spatial分区应用研究之七:同等分区粒度下全局索引优于分区索引的原因分析
1.实验结论 同等分区粒度下,使用分区空间索引进行空间查询,比使用全局空间索引进行查询,对数据字典表的访问次数更多.假设分区数为X,则大概多3X次访问.具体说明见6实验结论. 2.实验目的 在之前的测 ...
随机推荐
- zabbix实时监控mysql业务数据
1. 安装zabbix agent 下载zabbix:过往的软件包都有:https://sourceforge.mirrorservice.org/z/za/zabbix/ZABBIX%20Lates ...
- 无语——真的好用到不行的7个Python小技巧
本文总结了我几个我在学习python过程中,用到的几个超好用的操作,这里分享给大家,我相信你们也会非常喜欢,目录如下.这里提前索要再看,记得点一点再看哦.这只是其中一些技巧,以后会慢慢和大家分享. 1 ...
- 3行python代码翻译70种语言,这个OCR神奇太赞了
写在前面的一些P话: 今天给大家介绍一个超级简单且强大的OCR文本识别工具:easyocr. 这个模块支持70多种语言的即用型OCR,包括中文,日文,韩文和泰文等.完全满足了大家对于语言的要求,不管你 ...
- 使用C#编程语言开发Windows Service服务
转载-https://www.cnblogs.com/yubao/p/8443455.html Create Windows Service project using Visual Studio C ...
- OutputStreamWriter介绍&代码实现和InputStreamReader介绍&代码实现
java.io.OutputStreamWriter extends Writer OutputStreamWriter: 是字符流通向字节流的桥梁:可使用指定的 charset 将要写入流中的字符编 ...
- SpringBoot接口 - 如何优雅的对参数进行校验?
在以SpringBoot开发Restful接口时, 对于接口的查询参数后台也是要进行校验的,同时还需要给出校验的返回信息放到上文我们统一封装的结构中.那么如何优雅的进行参数的统一校验呢? @pdai ...
- 常用API(Java)
常用API Object toString方法 场景:当我们使用toString方法想要输出对象变量时,官方提供的toString方法会直接输出对象所在的地址,而不是我们想要的对象变量,所以我们要把t ...
- SpringCloudAlibaba分布式事务解决方案Seata实战与源码分析-上
概述 定义 Spring Cloud Alibaba Seata 官网地址 https://seata.io/zh-cn/ 最新版本1.5.2 Spring Cloud Alibaba Seata 文 ...
- 160_技巧_Power BI 新函数-计算工作日天数
160_技巧_Power BI 新函数-计算工作日天数 一.背景 Power BI 2022 年 7 月 14 日更新了最新版本的,版本号为:2.107.683.0 . 更多更新内容可以查看官方博客: ...
- GIS技术在医疗行业的应用:利用切片地图发布技术解决dmetrix数字病理切片在线浏览
最近一直在研究切片地图发布技术,解决各种矢量和栅格数据的切片地图制作和发布问题.这块的技术在土地评估和调查类公司中应用较多,因为他们经常需要使用各地地图,传统的文件管理方式很难适应工作现状,如果将各种 ...