[英]How to use GIN index with array column in postgresql?
I have a table that looks similar to this:我有一张看起来与此类似的表:
id uuid
ancestor_ids text[]
I need to perform a query to retrieve the rows where the first element in the ancestor_ids array is any of the input values.我需要执行查询以检索 ancestor_ids 数组中的第一个元素是任何输入值的行。 The query looks something like this:
查询看起来像这样:
select * from table where ancestor_ids[1] in ('multiple', 'input', 'values');
The query is working fine but I'd like to know if adding an index to the ancestor_ids
column would improve the performance given the fact I'm not using any special operator.查询工作正常,但我想知道在我没有使用任何特殊运算符的情况下,向
ancestor_ids
列添加索引是否会提高性能。 Is it possible to optimize the query at all?是否有可能优化查询? (table re-design is not an option)
(表格重新设计不是一种选择)
If it's always the first element, no need for a GIN index.如果它总是第一个元素,则不需要 GIN 索引。 A standard B-Tree will do:
一个标准的 B-Tree 会做:
create index on the_table ( (ancestor_ids[1]) );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.