Collations with nondeterministic comparison
authorPeter Eisentraut <peter@eisentraut.org>
Fri, 22 Mar 2019 11:09:32 +0000 (12:09 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Fri, 22 Mar 2019 11:12:43 +0000 (12:12 +0100)
commit5e1963fb764e9cc092e0f7b58b28985c311431d9
tree544492f24e3d48d00bd2a19c11663f84f1e18ce4
parent2ab6d28d233af17987ea323e3235b2bda89b4f2e
Collations with nondeterministic comparison

This adds a flag "deterministic" to collations.  If that is false,
such a collation disables various optimizations that assume that
strings are equal only if they are byte-wise equal.  That then allows
use cases such as case-insensitive or accent-insensitive comparisons
or handling of strings with different Unicode normal forms.

This functionality is only supported with the ICU provider.  At least
glibc doesn't appear to have any locales that work in a
nondeterministic way, so it's not worth supporting this for the libc
provider.

The term "deterministic comparison" in this context is from Unicode
Technical Standard #10
(https://unicode.org/reports/tr10/#Deterministic_Comparison).

This patch makes changes in three areas:

- CREATE COLLATION DDL changes and system catalog changes to support
  this new flag.

- Many executor nodes and auxiliary code are extended to track
  collations.  Previously, this code would just throw away collation
  information, because the eventually-called user-defined functions
  didn't use it since they only cared about equality, which didn't
  need collation information.

- String data type functions that do equality comparisons and hashing
  are changed to take the (non-)deterministic flag into account.  For
  comparison, this just means skipping various shortcuts and tie
  breakers that use byte-wise comparison.  For hashing, we first need
  to convert the input string to a canonical "sort key" using the ICU
  analogue of strxfrm().

Reviewed-by: Daniel Verite <daniel@manitou-mail.org>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://www.postgresql.org/message-id/flat/1ccc668f-4cbc-0bef-af67-450b47cdfee7@2ndquadrant.com
69 files changed:
contrib/bloom/bloom.h
contrib/bloom/blutils.c
doc/src/sgml/catalogs.sgml
doc/src/sgml/charset.sgml
doc/src/sgml/citext.sgml
doc/src/sgml/func.sgml
doc/src/sgml/ref/create_collation.sgml
src/backend/access/hash/hashfunc.c
src/backend/access/spgist/spgtextproc.c
src/backend/catalog/pg_collation.c
src/backend/commands/collationcmds.c
src/backend/commands/extension.c
src/backend/executor/execExpr.c
src/backend/executor/execGrouping.c
src/backend/executor/execPartition.c
src/backend/executor/execReplication.c
src/backend/executor/nodeAgg.c
src/backend/executor/nodeGroup.c
src/backend/executor/nodeHash.c
src/backend/executor/nodeHashjoin.c
src/backend/executor/nodeRecursiveunion.c
src/backend/executor/nodeSetOp.c
src/backend/executor/nodeSubplan.c
src/backend/executor/nodeUnique.c
src/backend/executor/nodeWindowAgg.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/plan/createplan.c
src/backend/optimizer/util/tlist.c
src/backend/partitioning/partbounds.c
src/backend/partitioning/partprune.c
src/backend/regex/regc_pg_locale.c
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/like.c
src/backend/utils/adt/like_support.c
src/backend/utils/adt/name.c
src/backend/utils/adt/orderedsetaggs.c
src/backend/utils/adt/pg_locale.c
src/backend/utils/adt/ri_triggers.c
src/backend/utils/adt/varchar.c
src/backend/utils/adt/varlena.c
src/backend/utils/cache/catcache.c
src/backend/utils/cache/lsyscache.c
src/bin/initdb/initdb.c
src/bin/pg_dump/pg_dump.c
src/bin/psql/describe.c
src/include/catalog/catversion.h
src/include/catalog/pg_collation.h
src/include/executor/executor.h
src/include/executor/hashjoin.h
src/include/executor/nodeHash.h
src/include/nodes/execnodes.h
src/include/nodes/plannodes.h
src/include/optimizer/planmain.h
src/include/optimizer/tlist.h
src/include/partitioning/partbounds.h
src/include/utils/lsyscache.h
src/include/utils/pg_locale.h
src/test/regress/expected/collate.icu.utf8.out
src/test/regress/expected/collate.linux.utf8.out
src/test/regress/expected/collate.out
src/test/regress/expected/subselect.out
src/test/regress/sql/collate.icu.utf8.sql
src/test/regress/sql/collate.linux.utf8.sql
src/test/regress/sql/collate.sql
src/test/regress/sql/subselect.sql
src/test/subscription/Makefile
src/test/subscription/t/012_collation.pl [new file with mode: 0644]