pgsql: Allow regex operations to be terminated early by query cancel re - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Allow regex operations to be terminated early by query cancel re
Date
Msg-id E1WJqPu-0007X4-Mt@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Allow regex operations to be terminated early by query cancel requests.

The regex code didn't have any provision for query cancel; which is
unsurprising given its non-Postgres origin, but still problematic since
some operations can take a long time.  Introduce a callback function to
check for a pending query cancel or session termination request, and
call it in a couple of strategic spots where we can make the regex code
exit with an error indicator.

If we ever actually split out the regex code as a standalone library,
some additional work will be needed to let the cancel callback function
be specified externally to the library.  But that's straightforward
(certainly so by comparison to putting the locale-dependent character
classification logic on a similar arms-length basis), and there seems
no need to do it right now.

A bigger issue is that there may be more places than these two where
we need to check for cancels.  We can always add more checks later,
now that the infrastructure is in place.

Since there are known examples of not-terribly-long regexes that can
lock up a backend for a long time, back-patch to all supported branches.
I have hopes of fixing the known performance problems later, but adding
query cancel ability seems like a good idea even if they were all fixed.

Branch
------
REL8_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/b6e143458505708ac139520f067060f66b222e5b

Modified Files
--------------
src/backend/regex/regc_nfa.c    |   12 ++++++++++++
src/backend/regex/regcomp.c     |   20 ++++++++++++++++++++
src/backend/regex/regexec.c     |    4 ++++
src/backend/utils/adt/regexp.c  |   12 ++++++++++++
src/backend/utils/adt/varlena.c |    1 +
src/include/regex/regerrs.h     |    4 ++++
src/include/regex/regex.h       |    1 +
src/include/regex/regguts.h     |    3 +++
8 files changed, 57 insertions(+)


pgsql-committers by date:

Previous
From: Thom Brown
Date:
Subject: Re: pgsql: Introduce replication slots.
Next
From: Tom Lane
Date:
Subject: pgsql: Allow regex operations to be terminated early by query cancel re