pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix issues around strictness of SIMILAR TO.
Date: Sat, 07 Sep 2019 18:22:09 +0000
Message-ID: <E1i6fLd-0000YV-3l@gemulon.postgresql.org> (raw)

Fix issues around strictness of SIMILAR TO.

As a result of some long-ago quick hacks, the SIMILAR TO operator
and the corresponding flavor of substring() interpreted "ESCAPE NULL"
as selecting the default escape character '\'.  This is both
surprising and not per spec: the standard is clear that these
functions should return NULL for NULL input.

Additionally, because of inconsistency of the strictness markings
of 3-argument substring() and similar_escape(), the planner could not
inline the SQL definition of substring(), resulting in a substantial
performance penalty compared to the underlying POSIX substring()
function.

The simplest fix for this would be to change the strictness marking
of similar_escape(), but if we do that we risk breaking existing views
that depend on that function.  Hence, leave similar_escape() as-is
as a compatibility function, and instead invent a new function
similar_to_escape() that comes in two strict variants.

There are a couple of other behaviors in this area that are also
not per spec, but they are documented and seem generally at least
as sane as the spec's definition, so leave them alone.  But improve
the documentation to describe them fully.

Patch by me; thanks to Álvaro Herrera and Andrew Gierth for review
and discussion.

Discussion: https://postgr.es/m/14047.1557708214@sss.pgh.pa.us

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/func.sgml                | 50 ++++++++++++++++-----
src/backend/parser/gram.y             | 16 +++----
src/backend/utils/adt/regexp.c        | 85 +++++++++++++++++++++++++++++------
src/include/catalog/catversion.h      |  2 +-
src/include/catalog/pg_proc.dat       | 15 ++++---
src/test/regress/expected/strings.out | 51 ++++++++++++++++++++-
src/test/regress/sql/strings.sql      | 15 ++++++-
7 files changed, 193 insertions(+), 41 deletions(-)



Message-ID: <E1i6fLd-0000YV-3l@gemulon.postgresql.org>
Permalink:  ../E1i6fLd-0000YV-3l@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1i6fLd-0000YV-3l@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix issues around strictness of SIMILAR TO.
  In-Reply-To: <E1i6fLd-0000YV-3l@gemulon.postgresql.org>
  References: <E1i6fLd-0000YV-3l@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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