gin索引字段entry构造的TREE,在末端posting tree|list 里面存储的是entry对应的行号. 别无其他信息。rum索引,与GIN类似,但是在posting list|tree的每一个ctid(itempoint)后面会追加一些属性值。因此,有些场景,使用rum 索引,性能会优很多。以下举个例子比较下。

Note: KingbaseES v8r6c5b0023 版本,附带了rum插件。

一、构造数据

create table t1 as select name,short_desc from pg_settings;
alter table t1 add column tsv tsvector;
update t1 set tsv=to_tsvector(short_desc); --number for 紧邻的只有一条
test=# select short_desc from t1 where to_tsvector(short_desc) @@ to_tsquery('number <-> for');
short_desc
-------------------------
Top SQL number for kddm
(1 row) --同时包含number and for 的有7条
test=# select short_desc from t1 where to_tsvector(short_desc) @@ to_tsquery('number & for');
short_desc
-------------------------------------------------------------------------------
Sets the number of digits displayed for floating-point values.
Sets the maximum number of simultaneously open files for each server process.
Sets the number of connection slots reserved for superusers.
Top SQL number for kddm
Sets the number of disk-page buffers in shared memory for WAL.
Sets the number of WAL files held for standby servers.
Sets the number of locks used for concurrent xlog insertions.
(7 rows)

二、例子1:距离查询

1、gin 索引

创建gin 索引:

create index ind_t1_gin on t1 using gin(tsv);

查看gin索引执行计划:通过索引返回7条记录,也就是索引没有包含位置的信息,需要访问表数据。

test=# explain analyze select short_desc from t1 where tsv @@ to_tsquery('number <-> for');
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t1 (cost=12.32..30.68 rows=9 width=55) (actual time=0.111..0.195 rows=1 loops=1)
Recheck Cond: (tsv @@ to_tsquery('number <-> for'::text))
Rows Removed by Index Recheck: 6
Heap Blocks: exact=4
-> Bitmap Index Scan on ind_t1_gin (cost=0.00..12.32 rows=9 width=0) (actual time=0.058..0.058 rows=7 loops=1)
Index Cond: (tsv @@ to_tsquery('number <-> for'::text))
Planning Time: 0.199 ms
Execution Time: 0.227 ms
(8 rows)

2、rum 索引

创建索引:

test=# create extension rum;
CREATE EXTENSION
test=# create index ind_t1_rum on t1 using rum(tsv);
CREATE INDEX

查看执行计划:可以看到索引返回的记录就一条,也就是索引包含有位置信息。

test=# explain analyze select short_desc from t1 where tsv @@ to_tsquery('number <-> for');
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on t1 (cost=12.32..30.68 rows=9 width=55) (actual time=0.041..0.042 rows=1 loops=1)
Recheck Cond: (tsv @@ to_tsquery('number <-> for'::text))
Heap Blocks: exact=1
-> Bitmap Index Scan on ind_t1_rum (cost=0.00..12.32 rows=9 width=0) (actual time=0.038..0.039 rows=1 loops=1)
Index Cond: (tsv @@ to_tsquery('number <-> for'::text))
Planning Time: 0.297 ms
Execution Time: 0.068 ms
(7 rows)

三、例子2:相关性排序

1、gin 索引

需要所有符合的数据,再进行排序

test=# create index ind_t1_gin on t1 using gin(tsv);
CREATE INDEX
test=# explain analyze select short_desc from t1 where tsv @@ to_tsquery('number & for') order by tsv <=> to_tsquery('number & for') limit 1;
QUERY PLAN
--------------------------------------------------------------------------------------------------------------------------------
Limit (cost=33.00..33.00 rows=1 width=59) (actual time=0.134..0.135 rows=1 loops=1)
-> Sort (cost=33.00..33.02 rows=9 width=59) (actual time=0.133..0.134 rows=1 loops=1)
Sort Key: ((tsv <=> to_tsquery('number & for'::text)))
Sort Method: top-N heapsort Memory: 25kB
-> Bitmap Heap Scan on t1 (cost=12.32..32.95 rows=9 width=59) (actual time=0.102..0.125 rows=7 loops=1)
Recheck Cond: (tsv @@ to_tsquery('number & for'::text))
Heap Blocks: exact=4
-> Bitmap Index Scan on ind_t1_gin (cost=0.00..12.32 rows=9 width=0) (actual time=0.084..0.084 rows=7 loops=1)
Index Cond: (tsv @@ to_tsquery('number & for'::text))
Planning Time: 0.237 ms
Execution Time: 0.177 ms
(11 rows)

2、rum 索引

test=# explain analyze select short_desc from t1 where tsv @@ to_tsquery('number & for') order by tsv <=> to_tsquery('number & for') limit 1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------
Limit (cost=8.25..12.52 rows=1 width=59) (actual time=0.077..0.077 rows=1 loops=1)
-> Index Scan using ind_t1_rum on t1 (cost=8.25..46.68 rows=9 width=59) (actual time=0.076..0.076 rows=1 loops=1)
Index Cond: (tsv @@ to_tsquery('number & for'::text))
Order By: (tsv <=> to_tsquery('number & for'::text))
Planning Time: 0.236 ms
Execution Time: 0.101 ms
(6 rows)

  

GIN and RUM 索引性能比较的更多相关文章

  1. 第七章——DMVs和DMFs(2)——用DMV和DMF监控索引性能

    原文:第七章--DMVs和DMFs(2)--用DMV和DMF监控索引性能 本文继续介绍使用DMO来监控,这次讲述的是监控索引性能.索引是提高查询性能的关键性手段.即使你的表上有合适的索引,你也要时时刻 ...

  2. Oracle B-tree、位图、全文索引三大索引性能比较及优缺点汇总

    引言:大家都知道“效率”是数据库中非常重要的一个指标,如何提高效率大家可能都会想起索引,但索引又这么多种,什么场合应该使用什么索引呢?哪种索引可以提高我们的效率,哪种索引可以让我们的效率大大降低(有时 ...

  3. oracle使用索引和不使用索引性能分析

    首先准备一张百万条数据的表,这样分析数据差距更形象! 下面用分页表数据对表进行分析,根据EMP_ID 字段排序,使用索引和不使用索引性能差距! sql查询语法准备,具体业务根据具体表书写sql语法: ...

  4. MySQL 索引性能分析概要

    上一篇文章 MySQL 索引设计概要 介绍了影响索引设计的几大因素,包括过滤因子.索引片的宽窄与大小以及匹配列和过滤列.在文章的后半部分介绍了 数据库索引设计与优化 一书中,理想的三星索引的设计流程和 ...

  5. mysql索引性能验证,高性能的索引策略

    索引性能验证 1.无索引列的查询 在where条件中查询没有添加索引的列,性能会比较差.我们可以先在sqlyog中打开表t_user的数据,然后复制一个名字出来进行查询. /*无索引列的查询,索引不会 ...

  6. Mysql 复合键索引性能

    数据库的常见的索引一般是单个字段,如果多个字段的组合,那么就组成了复合索引.对于组合索引,如果 对其中一字段做为条件查询,会出现什么情况呢? 一.例子 mysql> show create ta ...

  7. Oracle中索引的使用 索引性能优化调整

    索引是由Oracle维护的可选结构,为数据提供快速的访问.准确地判断在什么地方需要使用索引是困难的,使用索引有利于调节检索速度. 当建立一个索引时,必须指定用于跟踪的表名以及一个或多个表列.一旦建立了 ...

  8. MongoDB学习笔记(四)--索引 && 性能优化

    索引                                                                                             基础索引 ...

  9. Mysql优化系列之索引性能

    实际上,前面的数据类型和表结构设计优化不能算优化,只能算规范,也就是说在设计表的时候,应该且必须做到这些 索引是sql优化的核心部分,在<高性能Mysql>中单独抽出一章讲,也印证了其重要 ...

随机推荐

  1. LVGL库入门教程 - 颜色和图像

    颜色 构造颜色 在 LVGL 中,颜色以结构 lv_color_t 表示.在最开始移植整个工程时,曾经在 lv_conf.h 中修改过颜色深度: /*Color depth: 1 (1 byte pe ...

  2. 配置nginx多域名虚拟主机

    1.先做域名映射,由于我们使用的是阿里云域名. 登录阿里云控制台-->域名与网站(万网)-->域名-->选择一个域名-->域名解析-->添加记录 配置静态资源下载转发: ...

  3. uipath 如何利用函数split切割换行符?

    uipath 如何利用函数split切割换行符? 答案在这 https://rpazj.com/thread-178-1-1.html

  4. python采集一下美团外卖数据~~

    所需知识点(https://jq.qq.com/?_wv=1027&k=Ap5XvyNN) 1.动态数据抓包演示2.json数据解析3.requests模块的使用4.保存csv 安装命令:re ...

  5. Java去除字符串中 除数字和逗号以外的符号

    例: public static void main(String[] args) { // 去除字符串中 除数字和逗号以外的符号 String str = "_1066,_1068,_10 ...

  6. List集合五种遍历方式

    一.使用Iterator接口遍历 二.普通for循环遍历 三.增强for循环遍历 四.List集合自带迭代器 五.Lambda(JDK8新增特性) //使用多态方式创建对象 List<Strin ...

  7. HDFS存储目录分析

    一.介绍 HDFS metadata以树状结构存储整个HDFS上的文件和目录,以及相应的权限.配额和副本因子(replication factor)等.本文基于Hadoop2.6版本介绍HDFS Na ...

  8. Min_25 筛与杜教筛

    杜教筛 \(\) 是 \(\) 的前缀和,\(\), \(\) 同理. 假设 \( × = ℎ\) ,并且 \(, \) 易求出,\(\) 难求出. 那么 \[H () = \sum_{ \cdot ...

  9. 可变参数和Collections集合工具类的方法_addAll&shuffle

    可变参数 可变参数:是JDK1.5之后出现的新特性 使用前提:当方法的参数列表数据类型已经确定,但是参数的个数不确定,就可以使用可变参数 使用格式:定义方法时使用 ~修饰符 返回值类型 方法名(数据类 ...

  10. Collection集合和Collection集合常用功能

    Collection集合常用功能 方法: boolean add(E e); 向集合中添加元素 boolean remove(E e); 删除集合中的某个元素 void clear(); 清空集合所有 ...