简体   繁体   English

PostgresQL — GIN索引和B树的交集?

[英]PostgresQL — GIN index and intersection with B-trees?

I have two indexes: 我有两个索引:

CREATE INDEX table_a_b ON table (a, b);
CREATE INDEX table_c_gin ON table USING GIN(c);

My queries look like this: 我的查询如下所示:

SELECT * FROM table WHERE a = 'test' and b = 1 and c @> '{"test1", "test2"}'::text[];

The query planner prints out this: 查询计划器将输出以下内容:

 Index Scan using table_a_b on table  (cost=0.13..8.15 rows=1 width=52)
 Index Cond: (((a)::text = 'test'::text) AND (b = 1))
 Filter: (c @> '{test1, test2}'::text[])

So is there any way I could make the GIN index work, too? 那么,有什么办法可以使GIN索引正常工作吗? Maybe there's a way to create a composite index with two different index types? 也许有一种方法可以创建具有两种不同索引类型的复合索引?

Appreciate any help. 感谢任何帮助。

If the planner would think that it is worth doing, it could use a bitmap index scan on table_a_b and combile the two results. 如果计划者认为值得这样做,则可以对table_a_b使用位图索引扫描并汇总两个结果。 You'd have to look at the output of EXPLAIN to understand why it doesn't choose to do that. 您必须查看EXPLAIN的输出,以了解为什么它不选择这样做。

If you want to create a combined index, you have to install the btree_gin extension. 如果要创建组合索引,则必须安装btree_gin扩展。 Then you can use text and integer columns in a GIN index. 然后,您可以在GIN索引中使用textinteger列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM