pgsql: Fix lquery's NOT handling, and add ability to quantify non-'*' i

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix lquery's NOT handling, and add ability to quantify non-'*' i
Дата
Msg-id E1jJIbP-0001xN-Gh@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix lquery's NOT handling, and add ability to quantify non-'*' items.

The existing implementation of the ltree ~ lquery match operator is
sufficiently complex and undocumented that it's hard to tell exactly
what it does.  But one thing it clearly gets wrong is the combination
of NOT symbols (!) and '*' symbols.  A pattern such as '*.!foo.*'
should, by any ordinary understanding of regular expression behavior,
match any ltree that has at least one label that's not "foo".  As best
we can tell by experimentation, what it's actually matching is any
ltree in which *no* label is "foo".  That's surprising, and not at all
what the documentation says.

Now, that's arguably a useful behavior, so if we rewrite to fix the
bug we should provide some other way to get it.  To do so, add the
ability to attach lquery quantifiers to non-'*' items as well as '*'s.
Then the pattern '!foo{,}' expresses "any ltree in which no label is
foo".  For backwards compatibility, the default quantifier for non-'*'
items has to be "{1}", although the default for '*' items is '{,}'.
I wouldn't have done it like that in a green field, but it's not
totally horrible.

Armed with that, rewrite checkCond() from scratch.  Treating '*' and
non-'*' items alike makes it simpler, not more complicated, so that
the function actually gets a lot shorter than it was.

Filip Rembiałkowski, Tom Lane, Nikita Glukhov, per a very
ancient bug report from M. Palm

Discussion: https://postgr.es/m/CAP_rww=waX2Oo6q+MbMSiZ9ktdj6eaJj0cQzNu=Ry2cCDij5fw@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/70dc4c509b330fdd965d795e8d7f41f09d56c9ae

Modified Files
--------------
contrib/ltree/expected/ltree.out | 110 +++++++++++---
contrib/ltree/lquery_op.c        | 304 +++++++++++----------------------------
contrib/ltree/ltree.h            |  11 +-
contrib/ltree/ltree_io.c         |  45 +++++-
contrib/ltree/sql/ltree.sql      |  14 ++
doc/src/sgml/ltree.sgml          |  38 +++--
6 files changed, 262 insertions(+), 260 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Alexander Korotkov
Дата:
Сообщение: pgsql: Improve error reporting in opclasscmds.c
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Back-patch addition of stack overflow and interrupt checks for l