当 Postgres 使用位图堆扫描来评估包含 的 tsquery 时!
,它给我的结果与执行 seqscan 时不同。
任何人都可以对此有所了解吗?简单地启用/禁用位图扫描会改变查询结果,这对我来说就像一个错误。有什么解决方法吗?我在下面为我的玩具查询找到了一个(使用NOT
),但是对于我拥有的一些复杂的 tsquery 参数,我不确定我是否能做到这一点。
CREATE TABLE examples (content text);
CREATE INDEX ts_idx ON examples USING gin(to_tsvector('simple', content));
INSERT INTO examples VALUES ('Example with a word');
/* Incorrectly returns no results */
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;
SET enable_bitmapscan = ON;
SELECT * FROM examples
WHERE to_tsvector('simple', content) @@ to_tsquery('simple', '!(example<->word)')
/* Correctly returns results */
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;
SET enable_bitmapscan = OFF; /* disabled */
SELECT * FROM examples
WHERE to_tsvector('simple', content) @@ to_tsquery('simple', '!(example<->word)')
/* Also correctly returns results by using index and NOT keyword */
SET enable_seqscan = OFF;
SET enable_indexscan = OFF;
SET enable_bitmapscan = ON; /* enabled */
SELECT * FROM examples
WHERE NOT to_tsvector('simple', content) @@ to_tsquery('simple', '(example<->word)')
/* Latest version of Postgres 11 */
SELECT VERSION();
/* PostgreSQL 11.7 (Ubuntu 11.7-0ubuntu0.19.10.1) on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 9.2.1-9ubuntu2) 9.2.1 20191008, 64-bit */