From 2e024f83bd428fe32a2284452f31288c163a1190 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 26 Jan 2017 12:17:47 -0500 Subject: Ensure that a tsquery like '!foo' matches empty tsvectors. !foo means "the tsvector does not contain foo", and therefore it should match an empty tsvector. ts_match_vq() overenthusiastically supposed that an empty tsvector could never match any query, so it forcibly returned FALSE, the wrong answer. Remove the premature optimization. Our behavior on this point was inconsistent, because while seqscans and GIST index searches both failed to match empty tsvectors, GIN index searches would find them, since GIN scans don't rely on ts_match_vq(). That makes this certainly a bug, not a debatable definition disagreement, so back-patch to all supported branches. Report and diagnosis by Tom Dunstan (bug #14515); added test cases by me. Discussion: https://postgr.es/m/20170126025524.1434.97828@wrigleys.postgresql.org --- src/backend/utils/adt/tsvector_op.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/tsvector_op.c') diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index e7bf567cadc..d0a8b436ebd 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -784,7 +784,8 @@ ts_match_vq(PG_FUNCTION_ARGS) CHKVAL chkval; bool result; - if (!val->size || !query->size) + /* empty query matches nothing */ + if (!query->size) { PG_FREE_IF_COPY(val, 0); PG_FREE_IF_COPY(query, 1); -- cgit v1.2.3