PostgreSQL里面给全文检索或者模糊查询加索引提速的时候,一般会有两个选项,一个是GIST类型,一个是GIN类型,官网给出的参考如下:

There are substantial performance differences between the two index types, so it is important to understand their characteristics.

A GiST index is lossy, meaning that the index may produce false matches, and it is necessary to check the actual table row to eliminate such false matches. (PostgreSQL does this automatically when needed.) GiST indexes are lossy because each document is represented in the index by a fixed-length signature. The signature is generated by hashing each word into a single bit in an n-bit string, with all these bits OR-ed together to produce an n-bit document signature. When two words hash to the same bit position there will be a false match. If all words in the query have matches (real or false) then the table row must be retrieved to see if the match is correct.

Lossiness causes performance degradation due to unnecessary fetches of table records that turn out to be false matches. Since random access to table records is slow, this limits the usefulness of GiST indexes. The likelihood of false matches depends on several factors, in particular the number of unique words, so using dictionaries to reduce this number is recommended.

GIN indexes are not lossy for standard queries, but their performance depends logarithmically on the number of unique words. (However, GIN indexes store only the words (lexemes) of tsvector values, and not their weight labels. Thus a table row recheck is needed when using a query that involves weights.)

In choosing which index type to use, GiST or GIN, consider these performance differences:

GIN index lookups are about three times faster than GiST

GIN indexes take about three times longer to build than GiST

GIN indexes are moderately slower to update than GiST indexes, but about 10 times slower if fast-update support was disabled (see Section 54.3.1 for details)

GIN indexes are two-to-three times larger than GiST indexes

As a rule of thumb, GIN indexes are best for static data because lookups are faster. For dynamic data, GiST indexes are faster to update. Specifically, GiST indexes are very good for dynamic data and fast if the number of unique words (lexemes) is under 100,000, while GIN indexes will handle 100,000+ lexemes better but are slower to update.

Note that GIN index build time can often be improved by increasing maintenance_work_mem, while GiST index build time is not sensitive to that parameter

参考:http://www.postgresql.org/docs/9.2/static/textsearch-indexes.html

最新文章

  1. ASP.NET一些公共方法commTools
  2. linux笔记:文件处理命令touch,cat,more,less,head,tail
  3. Jupyter增加内核
  4. c++中返回对象与返回引用的区别
  5. 知识点摸清 - - function()——JavaScript 函数名后什么时候加括号,什么时候不
  6. ASP.NET中分布式事务的使用
  7. 窗口嵌入到另一个窗口(VC和QT都有)
  8. Linux环境下jdk1.8压缩包下载
  9. glusterfs 4.0.1 api 分析笔记1
  10. [lua]写个简单的Lua拓展-sleep函数
  11. 如何成为一个优秀的DBA
  12. npm 安装 sass-loader 失败的解决办法
  13. sas data infile 语句选项
  14. 从零开始学 Web 之 CSS3(七)多列布局,伸缩布局
  15. 谷歌浏览器升级引起的BUG
  16. Next generation sequencing (NGS)二代测序数据预处理与分析
  17. node 常用指令 node 扩展链接
  18. Linux操作系统-基本命令(一)
  19. JDBC处理Transaction
  20. 【Foreign】不等式 [数论]

热门文章

  1. 剑指Offer面试题:6.旋转数组中的最小数字
  2. 微软白板Excel xls列号数字转字母
  3. 使用.NET Remoting开发分布式应用——配置文件篇
  4. 用dwr封装表单项提交表单
  5. JMeter启动时显示Could not open/create prefs root node Software\JavaSoft\Prefs at root 0X80000002
  6. zabbix 3.0.2自定义脚本
  7. SVN报错:sqlite[S5]:database is locked
  8. phpcms文档
  9. linux(centos7) 安装nginx
  10. 怎么样使用yum来安装mysql