Support C.UTF-8 locale in the new builtin collation provider.
authorJeff Davis <[email protected]>
Tue, 19 Mar 2024 22:24:41 +0000 (15:24 -0700)
committerJeff Davis <[email protected]>
Tue, 19 Mar 2024 22:24:41 +0000 (15:24 -0700)
commitf69319f2f1fb16eda4b535bcccec90dff3a6795e
tree48077a7e6eb0309218b09a3be483aec37a6f204f
parentfd0398fcb099980fbedbb7750356ef234408c1c9
Support C.UTF-8 locale in the new builtin collation provider.

The builtin C.UTF-8 locale has similar semantics to the libc locale of
the same name. That is, code point sort order (fast, memcmp-based)
combined with Unicode semantics for character operations such as
pattern matching, regular expressions, and
LOWER()/INITCAP()/UPPER(). The character semantics are based on
Unicode simple case mappings.

The builtin provider's C.UTF-8 offers several important advantages
over libc:

 * faster sorting -- benefits from additional optimizations such as
   abbreviated keys and varstrfastcmp_c
 * faster case conversion, e.g. LOWER(), at least compared with some
   libc implementations
 * available on all platforms with identical semantics, and the
   semantics are stable, testable, and documentable within a given
   Postgres major version

Being based on memcmp, the builtin C.UTF-8 locale does not offer
natural language sort order. But it is an improvement for most use
cases that might otherwise use libc's "C.UTF-8" locale, as well as
many use cases that use libc's "C" locale.

Discussion: https://postgr.es/m/ff4c2f2f9c8fc7ca27c1c24ae37ecaeaeaff6b53.camel%40j-davis.com
Reviewed-by: Daniel Vérité, Peter Eisentraut, Jeremy Schneider
17 files changed:
doc/src/sgml/charset.sgml
doc/src/sgml/ref/create_collation.sgml
doc/src/sgml/ref/create_database.sgml
doc/src/sgml/ref/initdb.sgml
src/backend/regex/regc_pg_locale.c
src/backend/utils/adt/formatting.c
src/backend/utils/adt/pg_locale.c
src/bin/initdb/initdb.c
src/bin/initdb/t/001_initdb.pl
src/bin/pg_upgrade/t/002_pg_upgrade.pl
src/bin/scripts/t/020_createdb.pl
src/include/catalog/catversion.h
src/include/catalog/pg_collation.dat
src/test/regress/expected/collate.utf8.out[new file with mode: 0644]
src/test/regress/expected/collate.utf8_1.out[new file with mode: 0644]
src/test/regress/parallel_schedule
src/test/regress/sql/collate.utf8.sql[new file with mode: 0644]