pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #14515: tsquery with only a negative term doesn't match empty tsvector
4+ messages / 3 participants
[nested] [flat]

* BUG #14515: tsquery with only a negative term doesn't match empty tsvector
@ 2017-01-26 02:55  pgsql@tomd.cc
  0 siblings, 1 reply; 4+ messages in thread

From: pgsql@tomd.cc @ 2017-01-26 02:55 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      14515
Logged by:          Tom Dunstan
Email address:      pgsql@tomd.cc
PostgreSQL version: 9.5.5
Operating system:   Linux
Description:        

Hi all

Not sure if this is a bug or just ambiguity in the docs, but I certainly
found it counter-intuitive.

Basically while `select 'somethingelse'::tsvector @@ '!foo'::tsquery`
returns true, `select ''::tsvector @@ '!foo'::tsquery` returns false, which
was surprising to me.

I would expect a tsvector (empty or not) that doesn't contain foo to match
!foo.

It seems like the behaviour is "match a term that isn't foo" rather than
"match if no terms match foo".

Not sure if this is intentional (in which case maybe the docs could be a bit
more clear) or if it's just a bug. IMO the former behaviour isn't very
useful as it forces us to either code around it by writing extra SQL to
handle the case, or insert a dummy term to match against. Neither is very
nice.

It may be unintentional: there's a fast-path out of the match function here
https://github.com/postgres/postgres/blob/f21a563d25dbae153937aec062161184189478b8/src/backend/utils...
that returns false when the vector is empty. Perhaps it just wasn't taking
the negative-only case into account.

Cheers

Tom



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector
@ 2017-01-26 03:32  Tom Lane <tgl@sss.pgh.pa.us>
  parent: pgsql@tomd.cc
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2017-01-26 03:32 UTC (permalink / raw)
  To: pgsql@tomd.cc; +Cc: pgsql-bugs@postgresql.org, Oleg Bartunov <obartunov@gmail.com>; Teodor Sigaev <teodor@sigaev.ru>

pgsql@tomd.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 ...

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector
@ 2017-01-26 15:36  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 4+ messages in thread

From: Tom Lane @ 2017-01-26 15:36 UTC (permalink / raw)
  To: pgsql@tomd.cc; +Cc: pgsql-bugs@postgresql.org, Oleg Bartunov <obartunov@gmail.com>; Teodor Sigaev <teodor@sigaev.ru>

I wrote:
> pgsql@tomd.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


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: BUG #14515: tsquery with only a negative term doesn't match empty tsvector
@ 2017-01-27 05:08  Tom Dunstan <pgsql@tomd.cc>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Dunstan @ 2017-01-27 05:08 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@postgresql.org, Oleg Bartunov <obartunov@gmail.com>; Teodor Sigaev <teodor@sigaev.ru>


> On 27 Jan 2017, at 2:06 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> 
> In short, I now agree both that this is a bug, and that you've correctly
> identified the cause.  Will patch.

Thanks Tom!



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2017-01-27 05:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-01-26 02:55 BUG #14515: tsquery with only a negative term doesn't match empty tsvector pgsql@tomd.cc
2017-01-26 03:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-01-26 15:36   ` Tom Lane <tgl@sss.pgh.pa.us>
2017-01-27 05:08     ` Tom Dunstan <pgsql@tomd.cc>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox