BUG #16388: Different results when bitmap scan enabled/disabled

The Post Office <noreply@postgresql.org>

From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: charlie@torqinterface.com
Date: 2020-04-24T20:06:41Z
Lists: pgsql-bugs
The following bug has been logged on the website:

Bug reference:      16388
Logged by:          Charles Offenbacher
Email address:      charlie@torqinterface.com
PostgreSQL version: 11.7
Operating system:   Ubuntu
Description:        

Hi pgsql-bugs,

When Postgres uses a bitmap heap scan to evaluate a tsquery that includes !,
it is giving me different (and incorrect) results compared to when it
performs a seqscan.

Can anybody shed some light on this? Simply enabling / disabling bitmapscan
changes the query results, which feels like a bug to me. Are there any
workarounds? I found one for my repro below (using NOT) but for some of the
complicated tsquery queries that I have in production, I'm not sure I can
make that work.

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)')

Thanks for your time, and any thoughts that you might have to spare.
-Charlie

Commits

  1. Fix full text search to handle NOT above a phrase search correctly.