Postgres数组可以重叠(&&)运算符使用索引吗?

我们有一个带有索引数组列的表格:

CREATE TABLE mention (
  id SERIAL,
  phraseIds integer[],
  PRIMARY KEY (id)
);
CREATE INDEX indx_mentions_phraseIds on mention USING GIN (phraseids public.gin__int_ops);

在此列上使用“重叠”操作符的查询似乎不使用索引:

explain analyze select m.id FROM mention m WHERE m.phraseIds && ARRAY[11638,11639];

Seq Scan on mention m  (cost=0.00..933723.44 rows=1404 width=4) (actual time=103.018..3751.525 rows=1101 loops=1)
Filter: (phraseids && '{11638,11639}'::integer[])
Rows Removed by Filter: 7019974
Total runtime: 3751.618 ms

是否有可能让Postgresql使用索引? 或者我们应该做其他事情吗?

更新:我重复了'SET enable_seqscan TO off'的测试,索引仍然没有被使用。

更新:我应该提到我在9.2中使用intarray扩展。

更新:似乎intarray扩展是这个问题的一部分。 我重新创建表而不使用intarray扩展名,并且按预期使用索引。 任何人都知道如何让索引与intarray扩展一起使用? 文档(http://www.postgresql.org/docs/9.2/static/intarray.html)表示索引支持&&。


我在PostgreSQL 9.2中构建了一个类似的表; 不同之处在于USING GIN (phraseids); 出于某种原因,我似乎在这种情况下没有int_ops可用。 我加载了几千行随机(ish)数据。

设置enable_seqscan off可让PostgreSQL使用索引。

PostgreSQL将连续扫描的成本计算为小于位图堆扫描的成本。 顺序扫描的实际时间为位图堆扫描的实际时间的10%,但顺序扫描的总运行时间略多于位图堆扫描的总运行时间。

链接地址: http://www.djcxy.com/p/15287.html

上一篇: Can the Postgres array overlap (&&) operator use an index?

下一篇: TypeError: must be string without null bytes, not str