Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql(at)tomd(dot)cc
Cc: pgsql-bugs(at)postgresql(dot)org, Oleg Bartunov <obartunov(at)gmail(dot)com>, Teodor Sigaev <teodor(at)sigaev(dot)ru>
Subject: Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector
Date: 2017-01-26 15:36:36
Message-ID: 3145.1485444996@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> pgsql(at)tomd(dot)cc writes:
>> Basically while `select 'somethingelse'::tsvector @@ '!foo'::tsquery`
>> returns true, `select ''::tsvector @@ '!foo'::tsquery` returns false, which
>> was surprising to me.

> Not sure about this. A plausible reading of '!foo' is "there is a lexeme
> that is not foo". But even if that was Oleg & Teodor's intention,
> I would not want to swear that the tsquery stuff is totally consistent
> about it ...

After further poking at it, I found that a GIN index search will return
empty tsvectors, matching your expectation! So indeed we are being
inconsistent, which means that there is certainly a bug here no matter
which interpretation you favor.

Also, while a GIST index search doesn't return empty entries, it turns
out that that's only because it always applies recheck, so that the
fast-path exit in ts_match_vq() is what's rejecting the empty value
in that case too.

Otherwise, it seems pretty clear to me that the interpretation (most of?)
the code is using is that "!foo" means "foo does not appear in the value".

A look around at other callers of TS_execute indicate that none of the
rest of them are trying to "optimize" empty value, only empty query.

In short, I now agree both that this is a bug, and that you've correctly
identified the cause. Will patch.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message scoutant 2017-01-26 17:00:30 BUG #14517: Inheritance to behave as for OOP
Previous Message Tom Lane 2017-01-26 14:13:52 Re: BUG #14516: misleading error from libpq on out-of-memory