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@postgresql.org
Subject: pgsql: Make locale-dependent regex character classes work for large cha
Date: Mon, 05 Sep 2016 21:07:14 +0000
Message-ID: <E1bh16o-0001sW-FW@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>

Make locale-dependent regex character classes work for large char codes.

Previously, we failed to recognize Unicode characters above U+7FF as
being members of locale-dependent character classes such as [[:alpha:]].
(Actually, the same problem occurs for large pg_wchar values in any
multibyte encoding, but UTF8 is the only case people have actually
complained about.)  It's impractical to get Spencer's original code to
handle character classes or ranges containing many thousands of characters,
because it insists on considering each member character individually at
regex compile time, whether or not the character will ever be of interest
at run time.  To fix, choose a cutoff point MAX_SIMPLE_CHR below which
we process characters individually as before, and deal with entire ranges
or classes as single entities above that.  We can actually make things
cheaper than before for chars below the cutoff, because the color map can
now be a simple linear array for those chars, rather than the multilevel
tree structure Spencer designed.  It's more expensive than before for
chars above the cutoff, because we must do a binary search in a list of
high chars and char ranges used in the regex pattern, plus call iswalpha()
and friends for each locale-dependent character class used in the pattern.
However, multibyte encodings are normally designed to give smaller codes
to popular characters, so that we can expect that the slow path will be
taken relatively infrequently.  In any case, the speed penalty appears
minor except when we have to apply iswalpha() etc. to high character codes
at runtime --- and the previous coding gave wrong answers for those cases,
so whether it was faster is moot.

Tom Lane, reviewed by Heikki Linnakangas

Discussion: <15563.1471913698@sss.pgh.pa.us>

Branch
------
master

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

Modified Files
--------------
src/backend/regex/README                       |  96 ++-
src/backend/regex/regc_color.c                 | 885 +++++++++++++++++--------
src/backend/regex/regc_cvec.c                  |   4 +-
src/backend/regex/regc_locale.c                |  89 ++-
src/backend/regex/regc_pg_locale.c             |  36 +-
src/backend/regex/regcomp.c                    |  62 +-
src/backend/regex/regexport.c                  |  86 +--
src/backend/regex/regprefix.c                  |   5 +-
src/include/regex/regcustom.h                  |  10 +
src/include/regex/regex.h                      |   1 -
src/include/regex/regguts.h                    | 141 ++--
src/test/regress/expected/regex.linux.utf8.out | 164 +++++
src/test/regress/sql/regex.linux.utf8.sql      |  46 ++
13 files changed, 1106 insertions(+), 519 deletions(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1bh16o-0001sW-FW@gemulon.postgresql.org>
Permalink:  ../E1bh16o-0001sW-FW@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1bh16o-0001sW-FW@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: Make locale-dependent regex character classes work for large cha
  In-Reply-To: <E1bh16o-0001sW-FW@gemulon.postgresql.org>
  References: <E1bh16o-0001sW-FW@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