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. SAP Easy tree

    *&---------------------------------------------------------------------* *& Include SIMPLE_T ...

  2. 基于JavaFX图形界面演示的迷宫创建与路径寻找

    事情的起因是收到了一位网友的请求,他的java课设需要设计实现迷宫相关的程序--如标题概括. 我这边不方便透露相关信息,就只把任务要求写出来. 演示视频指路: 视频过审后就更新链接 完整代码链接: 网 ...

  3. 安装pystaller

    安装命令 # -i指定下载地址,此处采用清华大学镜像 pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package pyin ...

  4. 配置svn,httpd启动报错 Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

    查看httpd的状态,发现80端口被占用,因为我的nginx的80端口. systemctl status httpd.service  解决: 把Apache的端口该成别的端口 vi /etc/ht ...

  5. Java创建TXT文件并写入 内容

    public static void main(String[] args) { String filePath = "E:/" + "1.txt"; Stri ...

  6. 扩展新的WCV到标准的WC后,不能在业务角色里面看见视图解决方法

    by zyi 感谢群主红枣的分享 1.把你的WCVIEW扩展进WC中 2.使用UI Designer打开你的WCVIEW 3.更改你的WCVIEW名字

  7. Overfitting & Train Set & Test Set

    假设数据集是独立同分布的,可以将数据集划分为不同的比例:Train Set and Test Set. 同时在Train Set and Test Set上做精度测试,或者隔一段时间在Test Set ...

  8. 浅学hello world

    Hello world 1.随便新建一个文件夹,存放代码 2.新建一个java文件 .后缀名为.java .Hello.java .[注意点]系统没显示后缀名的可以自己手动打开 3.编写代码 publ ...

  9. Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round(C,D题解)

    Codeforces Round #801 (Div. 2) and EPIC Institute of Technology Round C - Zero Path 在这道题目中,不可以真正地进行寻 ...

  10. SSH远程登录:两台或多台服务器之间免密登录设置

    有两台(或多台)同局域网的服务器A:192.168.2.21,B:192.168.2.25.让A,B这两台服务器之间能两两互相免密登录,并且每台服务器都可以自我免密登录(自我免密登录即:ssh loc ...