Re: Collation & ctype method table, and extension hooks
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: Andreas Karlsson <andreas@proxel.se>, pgsql-hackers@postgresql.org
Date: 2024-11-19T21:32:47Z
Lists: pgsql-hackers
Attachments
- v8-0001-Perform-provider-specific-initialization-code-in-.patch (text/x-patch) patch v8-0001
- v8-0002-Control-collation-behavior-with-a-method-table.patch (text/x-patch) patch v8-0002
- v8-0003-Control-ctype-behavior-internally-with-a-method-t.patch (text/x-patch) patch v8-0003
- v8-0004-Remove-provider-field-from-pg_locale_t.patch (text/x-patch) patch v8-0004
- v8-0005-Make-provider-data-in-pg_locale_t-an-opaque-point.patch (text/x-patch) patch v8-0005
- v8-0006-Don-t-include-ICU-headers-in-pg_locale.h.patch (text/x-patch) patch v8-0006
- v8-0007-Introduce-hooks-for-creating-custom-pg_locale_t.patch (text/x-patch) patch v8-0007
On Fri, 2024-11-01 at 14:08 +0100, Andreas Karlsson wrote:
> I think adding such a small file would make life easier for people
> new
> to the collation part of the code base. It would be a nice symmetry
> between collation providers and where code for them can be found.
Done.
> >
> For me combining them would make the intention of the code easier to
> understand since aren't the casemap functions just a set of
> "ctype_methods"?
Done.
There is a bit of weirdness in libc because:
* Single byte encodings use the single-byte isupper(), toupper(), etc.
* UTF8 encoding uses wide character iswupper(), towupper(), etc.
* Non-UTF8 multibyte encodings use isupper() for pattern matching but
towupper() for case mapping
that weirdness existed before, but it's a bit more obvious what's
happening now.
> > > This commit makes me tempted to handle the ctype_is_c logic for
> > > character classes also in callbacks and remove the if in
> > > functions
> > > like
> > > pg_wc_ispunct(). But this si something that would need to be
> > > benchmarked.
I like this idea, but it can be a follow up.
Attached new patchset.
I also tried some performance tests again. I used smalltext (a table of
10M ~30-character strings) and bigtext (a table of 32768 rows, each
containing the 100KiB source of https://en.wikipedia.org/wiki/Diacritic
). And I then ran the following regex on each:
select count(*) from thetable
where t ~
'[[:digit:]][[:space:]][[:punct:]][[:alpha:]][[:lower:]][[:upper:]]';
for "C", "en_US", and "en-US-x-icu". The timings for smalltext were
indistinguishable between master and the patched version. The timings
for bigtext were pretty noisy so it's hard to tell if there was a
regression or not, but I saw some evidence in the profile that
char_properties has a cost (~1%). I'm not sure if that's a significant
concern or not.
Which API do you think is the right one? Individual functions testing
individual properties, or something like char_properties() that can
test several at once?
Regards,
Jeff Davis
Commits
-
Remove provider field from pg_locale_t.
- 8af0d0ab01b4 19 (unreleased) landed
-
Control ctype behavior internally with a method table.
- 5a38104b3642 19 (unreleased) landed
-
Control collation behavior with a method table.
- a2f17f004d22 18.0 landed
-
Move code for collation version into provider-specific files.
- 4f5cef2607c1 18.0 landed
-
Refactor string case conversion into provider-specific files.
- 86a5d6006aff 18.0 landed
-
Move check for ucol_strcollUTF8 to pg_locale_icu.c
- 7167e05fc7d1 18.0 landed
-
Perform provider-specific initialization in new functions.
- 1ba0782ce90c 18.0 landed
-
Refactor the code to create a pg_locale_t into new function.
- 3aa2373c1141 18.0 landed