GiST 和 GIN 索引的区别

Difference between GiST and GIN index

我正在实施一个 table,它有一个数据类型为 tsvector 的列,我想了解使用哪个索引更好?

GIN 还是 GiST?

在浏览 postgres documentation here 时,我似乎明白了:

好的,那么为什么会有人想要一个 gist 索引字段而不是 gin?如果要点会给你错误的结果?在这上面肯定有一些优势(外在表现)。

当我想使用 GIN 与 GiST 时,谁能通俗易懂地解释一下?

我认为我无法解释得比 the manual 已经做的更好:

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 [...]

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

Link 和 quote 参考 Postgres 9.4 手册。大小和性能估计似乎已经有点过时了。 With Postgres 9.4 the odds have shifted substantially in favor of GIN.
release notes of Postgres 9.4包括:

  • Reduce GIN index size (Alexander Korotkov, Heikki Linnakangas) [...]

  • Improve speed of multi-key GIN lookups (Alexander Korotkov, Heikki Linnakangas)

大小和性能估计已从手册中删除。

请注意,special use cases 需要其中之一。

有一件事你误解了:你从来没有使用 GiST 索引得到错误的结果。索引对哈希值进行操作,可能 导致索引中出现误报。这应该只与文档中的大量不同单词相关。在任何情况下,重新检查实际行后都会消除误报。 The manual:

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.)

大胆强调我的。