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. vue开发必须知道的小技巧

    近年来,vue越来越火,使用它的人也越来越多.vue基本用法很容易上手,但是还有很多优化的写法你就不一定知道了.本文列举了一些vue常用的开发技巧.require.context() 在实际开发中,绝 ...

  2. 【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧

    前言:随着工业化的进一步发展,制造业.工业自动化等多领域,都可能用到上位监控系统.而WPF在上位监控系统方面,应该算是当下最流行的前端框架之一了.而随着监控体系的不断完善与更新迭代,监控画面会变得越来 ...

  3. 基于springBoot项目如何配置多数据源

    前言 有时,在一个项目中会用到多数据源,现在对自己在项目中多数据源的操作总结如下,有不到之处敬请批评指正! 1.pom.xml的依赖引入 <dependency> <groupId& ...

  4. 零基础学Python:元组(Tuple)详细教程

    Python的元组与列表类似,不同之处在于元组的元素不能修改,元组使用小括号,列表使用方括号,元组创建很简单,只需要在括号中添加元素,并使用逗号隔开即可https://jq.qq.com/?_wv=1 ...

  5. ArrayList分析2 :Itr、ListIterator以及SubList中的坑

    ArrayList分析2 : Itr.ListIterator以及SubList中的坑 转载请注明出处:https://www.cnblogs.com/funnyzpc/p/16409137.html ...

  6. Contest

    Contest 题目 链接 题目描述 \(n\) 支队伍一共参加了三场比赛. 一支队伍 \(x\) 认为自己比另一支队伍 \(y\) 强当且仅当 \(x\) 在至少一场比赛中比 \(y\) 的排名高. ...

  7. Android Studio 的初次使用

    记录我第一次使用Android Studio时遇到的问题以及一些简单的笔记. 我所使用的是Android Studio 2.2版本 遇到的问题 创建一个Hello World!项目无疑是相当简单的,我 ...

  8. 从 1.5 开始搭建一个微服务框架——日志追踪 traceId

    你好,我是悟空. 前言 最近在搭一个基础版的项目框架,基于 SpringCloud 微服务框架. 如果把 SpringCloud 这个框架当做 1,那么现在已经有的基础组件比如 swagger/log ...

  9. Neural Networks

    神经网络能够使用torch.nn包构建神经网络. 现在你已经对autogard有了初步的了解,nn基于autograd来定义模型并进行微分.一个nn.Module包含层,和一个forward(inpu ...

  10. javaweb 03: jsp

    JSP 我的第一个JSP程序: 在WEB-INF目录之外创建一个index.jsp文件,然后这个文件中没有任何内容. 将上面的项目部署之后,启动服务器,打开浏览器,访问以下地址: http://loc ...