os: ubuntu 16.04
postgresql: 9.6.8

ip 规划
192.168.56.102 node2 postgresql

help create index

postgres=# \h create index
Command:     CREATE INDEX
Description: define a new index
Syntax:
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON table_name [ USING method ]( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] )[ WITH ( storage_parameter = value [, ... ] ) ][ TABLESPACE tablespace_name ][ WHERE predicate ]

[ USING method ]
method
要使用的索引方法的名称。可以选择 btree、hash、 gist、spgist、 gin以及brin。 默认方法是btree。

gin

gin 意思是通用倒排索引。
gin 被设计为处理被索引项为组合值的情况,并且这种索引所处理的查询需要搜索出现在组合项中的元素值。例如,项可以是文档,并且查询可以是搜索包含指定词的文档。

我们使用词项来表示要被索引的一个组合值,并且用词键来表示一个元素值。gin 总是存储和搜索键,而不是项值本身。

gin 索引是"倒排索引",它适合于包含多个组成值的数据值,例如数组。

倒排索引中为每一个组成值都包含一个单独的项,它可以高效地处理测试指定组成值是否存在的查询。

简单的说就是 gin 索引接口常被用于多值列的检索,例如全文检索类型、数组类型。

postgres=# drop table tmp_t0;
DROP TABLE
postgres=# create table tmp_t0(c0 tsvector,c1 varchar(100));
CREATE TABLEpostgres=# insert into tmp_t0(c0,c1) select to_tsvector((select string_agg(p0,' ') from regexp_split_to_table(md5(id::varchar),'') as p0)),md5((id)::varchar) from generate_series(1,100000) as id;
INSERT 0 100000postgres=# \x
Expanded display is on.
postgres=# select * from tmp_t0 limit 2;
-[ RECORD 1 ]----------------------------------------------------------------------------------------------------------------------------------
c0 | '0':10,17,22 '2':6,13,16 '3':7,14 '4':2,5,30 '5':21,28 '6':25 '7':27 '8':8,15,29 '9':12,23,31 'b':11,32 'c':1,3,19,20 'd':18 'f':26
c1 | c4ca4238a0b923820dcc509a6f75849b
-[ RECORD 2 ]----------------------------------------------------------------------------------------------------------------------------------
c0 | '0':19 '1':3,27 '2':6,13,31 '3':16 '4':11,28 '6':15,17,20,30 '7':5,21 '8':2,7,23,29 '9':9,24 'c':1,12,25,26,32 'd':8,10 'e':4 'f':14,18,22
c1 | c81e728d9d4c2f636f067f89cc14862c
postgres=# \x
Expanded display is off.postgres=# create index idx_tmp_t0_1 on tmp_t0 using gin (c0);postgres=# \d+ tmp_t0Table "public.tmp_t0"Column |          Type          | Modifiers | Storage  | Stats target | Description
--------+------------------------+-----------+----------+--------------+-------------c0     | tsvector               |           | extended |              | c1     | character varying(100) |           | extended |              |
Indexes:"idx_tmp_t0_1" gin (c0)

gin 索引与这两个参数有关

postgres=# \x
postgres=# select * from pg_settings where name like '%gin%';
-[ RECORD 1 ]---+---------------------------------------------------------------------------
name            | gin_fuzzy_search_limit
setting         | 0
unit            |
category        | Client Connection Defaults / Other Defaults
short_desc      | Sets the maximum allowed result for exact search by GIN.
extra_desc      |
context         | user
vartype         | integer
source          | default
min_val         | 0
max_val         | 2147483647
enumvals        |
boot_val        | 0
reset_val       | 0
sourcefile      |
sourceline      |
pending_restart | f
-[ RECORD 2 ]---+---------------------------------------------------------------------------
name            | gin_pending_list_limit
setting         | 4096
unit            | kB
category        | Client Connection Defaults / Statement Behavior
short_desc      | Sets the maximum size of the pending list for GIN index.
extra_desc      |
context         | user
vartype         | integer
source          | default
min_val         | 64
max_val         | 2147483647
enumvals        |
boot_val        | 4096
reset_val       | 4096
sourcefile      |
sourceline      |
pending_restart | f

社区版本中个人的力量
postgresql 中的 gin 实现主要由 Teodor Sigaev 和 Oleg Bartunov 维护。在他们的网站(http://www.sai.msu.su/~megera/wiki/Gin)上有更多关于 gin 的信息。

在 postgresql 10 中,gin 在多并发的压力下性能有了很高的提升。

btree_gin


参考:
http://postgres.cn/docs/9.6/indexes-types.html
http://postgres.cn/docs/9.6/sql-createindex.html

http://postgres.cn/docs/9.6/functions-array.html
http://postgres.cn/docs/9.6/gin.html

http://postgres.cn/docs/9.6/catalog-pg-am.html

https://postgrespro.com/blog
Indexes in PostgreSQL — 1 https://postgrespro.com/blog/pgsql/3994098
Indexes in PostgreSQL — 2 https://postgrespro.com/blog/pgsql/4161264
Indexes in PostgreSQL — 3 (Hash) https://postgrespro.com/blog/pgsql/4161321
Indexes in PostgreSQL — 4 (Btree) https://postgrespro.com/blog/pgsql/4161516
Indexes in PostgreSQL — 5 (GiST) https://postgrespro.com/blog/pgsql/4175817
Indexes in PostgreSQL — 6 (SP-GiST) https://postgrespro.com/blog/pgsql/4220639
Indexes in PostgreSQL — 7 (GIN) https://postgrespro.com/blog/pgsql/4261647
Indexes in PostgreSQL — 8 (RUM) https://postgrespro.com/blog/pgsql/4262305

postgresql 索引之 gin、btree_gin相关推荐

  1. postgresql索引_PostgreSQL中的索引— 10(Bloom)

    postgresql索引 indexing engine and the interface of access methods, as well as 索引引擎和访问方法的接口,以及hash ind ...

  2. postgresql索引_PostgreSQL中的索引— 8(RUM)

    postgresql索引 indexing engine, the interface of access methods, and main access methods, such as: 索引引 ...

  3. PostgreSQL索引介绍

    梦中彩虹 博客园 首页 新随笔 联系 管理 随笔 - 131  文章 - 1  评论 - 14 PostgreSQL索引介绍 INDEX 索引是增强数据库性能的常用方法.索引使得数据库在查找和检索数据 ...

  4. 掌握查询利器 深入理解PostgreSQL索引原理与优化

    文章目录 一.前言 1.1 PostgreSQL索引的重要性 1.2 本文的结构和目的 二.索引概述 2.1 什么是索引 2.2 为什么要使用索引 2.3 索引如何工作 三.索引类型 3.1 B-tr ...

  5. postgresql 索引状态_PostgreSQL索引思考

    当在看Monetdb列存行只支持IMPRINTS和ORDERED这两种索引,且只支持定长数值类型时,就在思考,对于列存,还有必要建索引吗?在PostgreSQL的索引就要灵活很多,我对常用列建合理的索 ...

  6. PostgreSQL索引膨胀

    PostgreSQL索引膨胀 最后编辑时间:2022年1月23日00:07:27 通常是因为数据乱序写入导致的,索引页中的数据是有序的,而索引字段乱序写入,会导致索引频繁分裂,使得索引页并不是百分百填 ...

  7. postgresql索引_PostgreSQL中的索引— 6(SP-GiST)

    postgresql索引 indexing engine, 索引引擎 , the interface of access methods, and three methods: 访问方法的接口以及三种 ...

  8. PostgreSql索引(B-tree索引 Hash索引 GiST索引 SP-GiST索引 GIN 索引 BRIN 索引)

    索引 语法: CREATE INDEX test1_id_index ON test1 (id); 索引的名字test1_id_index可以自由选择,但我们最好选择一个能让我们想起该索引用途的名字. ...

  9. postgresql 索引状态_PostgreSQL中的锁:3.其他锁

    我们已经讨论了一些对象级锁(特别是关系级锁),以及行级锁及其与对象级锁的连接,还探讨了等待队列.这次我们要来个大杂烩.我们将从死锁开始(实际上,我计划上次讨论死锁,但是这篇文章本身篇幅太长了),然后简 ...

最新文章

  1. linux服务器curl,在Linux系统下使用curl自定义HTTP头的方法
  2. 《JavaScript设计模式与开发实践》模式篇(5)—— 观察者模式
  3. MySQL之三范式:原子性 唯一性 避免数据冗余
  4. 新乡医学院2018计算机考试题,新乡医学院继教2018级局部解剖学复习自测下肢答案...
  5. linux eth0 目录,教程 | Linux常用命令大全
  6. 2018“一带一路”阿里巴巴诸神之战全球创客大赛全面启动
  7. Python实现栅格数据拼接、裁剪等操作
  8. 数据分析进阶 - 评分模型权重计算方法
  9. 6步搞定To B产品竞品分析,值得收藏!
  10. 如何解决苹果Mac大写键CapsLock不能锁定大小写?
  11. 英语情景对话计算机专业,工作有关情景对话英语
  12. Zabbix使用指南
  13. 静态代理的实现-模拟中介代理房东出租房子给房客
  14. 2019.08.12【NOIP提高组】模拟 A 组
  15. 6Attentive Convolutional Neural Network based Speech Emotion Recognition: A Study on the Impact of
  16. 人工智能内行盛会,错过再等一年!
  17. HtmlUnit 使用范例
  18. 【程序】Altera FPGA NIOS实现Scatter-Gather DMA(SGDMA)收发回环测试,描述符和缓冲区全部放在同一块SDRAM里面
  19. ‘数据库基础、MariaDB服务部署、库表基本管理、数据类型’经典案例
  20. 前端性能优化,之还在为多种多样的知识点整理苦恼吗,进来看看吧。(转载)

热门文章

  1. recv/send堵塞和非堵塞
  2. 洛谷-P2550-彩票摇奖
  3. ios系统使用window.open()打开新的页面失效
  4. OptiView® XG 网络分析平板电脑特性(上)
  5. (更新时间)2021年6月4日 商城高并发秒杀系统(.NET Core版) 30-lua文件封装加载和执行
  6. 汇编语言、高级语言(系统语言)、脚本语言的异同
  7. 《伤寒论》的APP设想
  8. 获取实时手机验证码并同步到邮箱服务器
  9. 第七章-数据分析-数据透视表的应用
  10. FlexRay关注事项2_网络总线资源分配问题