Rethink extraction of collation dependencies.
authorTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Apr 2021 02:23:46 +0000 (22:23 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Sat, 17 Apr 2021 02:23:46 +0000 (22:23 -0400)
commitf24b156997059c257c697b825f022d115825091d
treeee6ee6b0a2e24c955258b6ee17443dd08b4de9fd
parent8a2df442b652f83b1c189822737091b90f343965
Rethink extraction of collation dependencies.

As it stands, find_expr_references_walker() pays attention to leaf-node
collation fields while ignoring the input collations of actual function
and operator nodes.  That seems exactly backwards from a semantic
standpoint, and it leads to reporting dependencies on collations that
really have nothing to do with the expression's behavior.

Hence, rewrite to look at function input collations instead.  This
isn't completely perfect either; it fails to account for the behavior
of record_eq and its siblings.  (The previous coding at least gave an
approximation of that, though I think it could be fooled pretty easily
into considering the columns of irrelevant composite types.)  We may
be able to improve on this later, but for now this should satisfy the
buildfarm members that didn't like ef387bed8.

In passing fix some oversights in GetTypeCollations(), and get
rid of its duplicative de-duplications.  (I'm worried that it's
still potentially O(N^2) or worse, but this makes it a little
better.)

Discussion: https://postgr.es/m/3564817.1618420687@sss.pgh.pa.us
src/backend/catalog/dependency.c
src/backend/catalog/pg_type.c
src/test/regress/expected/collate.icu.utf8.out
src/test/regress/sql/collate.icu.utf8.sql