postgresqlb-treepostgresql-performancegwt-gintrigram

Postgresql BTREE_GIN index with gin_trgm_ops option?


On https://www.postgresql.org/docs/current/static/pgtrgm.html it is explained how special GIN idexes with gin_trgm_ops option can be used to facilitate trigram similarity operator performance.

CREATE INDEX trgm_idx ON test_trgm USING GIN (t gin_trgm_ops);

It is also said:

These indexes do not support equality nor simple comparison operators, so you may need a regular B-tree index too.

However, there is also BTREE_GIN extension which should allow GIN indexes to be used as substitute for BTREE indexes. https://www.postgresql.org/docs/current/static/btree-gin.html

My question is: If I install BTREE_GIN extension, could pg_trgm GIN index (with gin_trgm_ops option) be used as substitute for BTREE index? Does it combine properties of both BTREE_GIN and trigram GIN index, or additional BTREE index is still needed for joining and equality expressions etc.?


Solution

  • No, if you install btree_gin, you can create a GIN index over “basic” data types like integer, varchar or text.

    This is normally useless, since you can use such an index for nothing that wouldn't be done better by a regular B-tree index, but it is very useful if you want to create a multicolumn GIN index including a column with such a data type, for example if you want to create a combined index for an expression like tscol @@ to_tsquery('big data') AND intcol = 42.