]> granicus.if.org Git - postgresql/commit
Allow regex operations to be terminated early by query cancel requests.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Mar 2014 20:21:11 +0000 (15:21 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 1 Mar 2014 20:21:11 +0000 (15:21 -0500)
commit43af0e8c6c1a455d038730f3ec33a5f23a560fe2
tree90cf0224f167786415ea2432f7f74408f978986a
parent1e0fb6a2c69541e2def2d4364513fbef02c0dbd2
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.
src/backend/regex/regc_nfa.c
src/backend/regex/regcomp.c
src/backend/regex/regexec.c
src/backend/utils/adt/regexp.c
src/backend/utils/adt/varlena.c
src/include/regex/regerrs.h
src/include/regex/regex.h
src/include/regex/regguts.h