pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix full text search to handle NOT above a phrase search correct
5+ messages / 1 participants
[nested] [flat]

* pgsql: Fix full text search to handle NOT above a phrase search correct
@ 2020-04-27 16:21  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-04-27 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/072a863275e93147cf5987b915815e041322b8be

Modified Files
--------------
src/backend/utils/adt/tsginidx.c      |  23 ++-
src/backend/utils/adt/tsvector_op.c   | 269 +++++++++++++++++++++++-----------
src/test/regress/data/tsearch.data    |  40 ++---
src/test/regress/expected/tsearch.out | 246 ++++++++++++++++++++++++++++++-
src/test/regress/expected/tstypes.out |  78 ++++++++++
src/test/regress/sql/tsearch.sql      |  40 +++++
src/test/regress/sql/tstypes.sql      |  13 ++
7 files changed, 594 insertions(+), 115 deletions(-)



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

* pgsql: Fix full text search to handle NOT above a phrase search correct
@ 2020-04-27 16:21  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-04-27 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e81e5741a6c5d2000b70ea4d5aeceb7669fbccbf

Modified Files
--------------
src/backend/utils/adt/tsginidx.c      |  23 ++-
src/backend/utils/adt/tsvector_op.c   | 269 ++++++++++++++++---------
src/test/regress/data/tsearch.data    |  40 ++--
src/test/regress/expected/tsearch.out | 366 +++++++++++++++++++++++++++++++++-
src/test/regress/expected/tstypes.out |  78 ++++++++
src/test/regress/sql/tsearch.sql      |  60 ++++++
src/test/regress/sql/tstypes.sql      |  13 ++
7 files changed, 734 insertions(+), 115 deletions(-)



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

* pgsql: Fix full text search to handle NOT above a phrase search correct
@ 2020-04-27 16:21  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-04-27 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/98a4d6950b24bd02a4573813b7157f2710f1ec7a

Modified Files
--------------
src/backend/utils/adt/tsginidx.c      |  23 ++-
src/backend/utils/adt/tsvector_op.c   | 269 +++++++++++++++++++++++-----------
src/test/regress/data/tsearch.data    |  40 ++---
src/test/regress/expected/tsearch.out | 246 ++++++++++++++++++++++++++++++-
src/test/regress/expected/tstypes.out |  78 ++++++++++
src/test/regress/sql/tsearch.sql      |  40 +++++
src/test/regress/sql/tstypes.sql      |  13 ++
7 files changed, 594 insertions(+), 115 deletions(-)



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

* pgsql: Fix full text search to handle NOT above a phrase search correct
@ 2020-04-27 16:21  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-04-27 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/18f7e856cde4734b55844243e54dd8614efbd9eb

Modified Files
--------------
src/backend/utils/adt/tsginidx.c      |  23 ++-
src/backend/utils/adt/tsvector_op.c   | 269 +++++++++++++++++++++++-----------
src/test/regress/data/tsearch.data    |  40 ++---
src/test/regress/expected/tsearch.out | 246 ++++++++++++++++++++++++++++++-
src/test/regress/expected/tstypes.out |  78 ++++++++++
src/test/regress/sql/tsearch.sql      |  40 +++++
src/test/regress/sql/tstypes.sql      |  13 ++
7 files changed, 594 insertions(+), 115 deletions(-)



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

* pgsql: Fix full text search to handle NOT above a phrase search correct
@ 2020-04-27 16:21  Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Tom Lane @ 2020-04-27 16:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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

Queries such as '!(foo<->bar)' failed to find matching rows when
implemented as a GiST or GIN index search.  That's because of
failing to handle phrase searches as tri-valued when considering
a query without any position information for the target tsvector.
We can only say that the phrase operator might match, not that it
does match; and therefore its NOT also might match.  The previous
coding incorrectly inverted the approximate phrase result to
decide that there was certainly no match.

To fix, we need to make TS_phrase_execute return a real ternary result,
and then bubble that up accurately in TS_execute.  As long as we have
to do that anyway, we can simplify the baroque things TS_phrase_execute
was doing internally to manage tri-valued searching with only a bool
as explicit result.

For now, I left the externally-visible result of TS_execute as a plain
bool.  There do not appear to be any outside callers that need to
distinguish a three-way result, given that they passed in a flag
saying what to do in the absence of position data.  This might need
to change someday, but we wouldn't want to back-patch such a change.

Although tsginidx.c has its own TS_execute_ternary implementation for
use at upper index levels, that sadly managed to get this case wrong
as well :-(.  Fixing it is a lot easier fortunately.

Per bug #16388 from Charles Offenbacher.  Back-patch to 9.6 where
phrase search was introduced.

Discussion: https://postgr.es/m/16388-98cffba38d0b7e6e@postgresql.org

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/22dcb6c206ac72d0ea722d22e89e5755beed7b76

Modified Files
--------------
src/backend/utils/adt/tsginidx.c      |  23 ++-
src/backend/utils/adt/tsvector_op.c   | 269 +++++++++++++++++++++++-----------
src/test/regress/data/tsearch.data    |  40 ++---
src/test/regress/expected/tsearch.out | 246 ++++++++++++++++++++++++++++++-
src/test/regress/expected/tstypes.out |  78 ++++++++++
src/test/regress/sql/tsearch.sql      |  40 +++++
src/test/regress/sql/tstypes.sql      |  13 ++
7 files changed, 594 insertions(+), 115 deletions(-)



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


end of thread, other threads:[~2020-04-27 16:21 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-04-27 16:21 pgsql: Fix full text search to handle NOT above a phrase search correct Tom Lane <tgl@sss.pgh.pa.us>
2020-04-27 16:21 pgsql: Fix full text search to handle NOT above a phrase search correct Tom Lane <tgl@sss.pgh.pa.us>
2020-04-27 16:21 pgsql: Fix full text search to handle NOT above a phrase search correct Tom Lane <tgl@sss.pgh.pa.us>
2020-04-27 16:21 pgsql: Fix full text search to handle NOT above a phrase search correct Tom Lane <tgl@sss.pgh.pa.us>
2020-04-27 16:21 pgsql: Fix full text search to handle NOT above a phrase search correct Tom Lane <tgl@sss.pgh.pa.us>

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