From 5a8ee9f2dbe040b9a0cb7f73a4376633f93b4ab4 Mon Sep 17 00:00:00 2001 From: Tomas Vondra Date: Thu, 18 Jul 2019 12:28:16 +0200 Subject: Use column collation for extended statistics The current extended statistics code was a bit confused which collation to use. When building the statistics, the collations defined as default for the data types were used (since commit 5e0928005). The MCV code was however using the column collations for MCV serialization, and then DEFAULT_COLLATION_OID when computing estimates. So overall the code was using all three possible options, inconsistently. This uses the column colation everywhere - this makes it consistent with what 5e0928005 did for regular stats. We however do not track the collations in a catalog, because we can derive them from column-level information. This may need to change in the future, e.g. after allowing statistics on expressions. Reviewed-by: Tom Lane Discussion: https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.eu Backpatch-to: 12 --- src/backend/commands/statscmds.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/backend/commands/statscmds.c') diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index cf406f6f96b..34d11c2a980 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -485,6 +485,10 @@ RemoveStatisticsById(Oid statsOid) * * For MCV lists that's not the case, as those statistics store the datums * internally. In this case we simply reset the statistics value to NULL. + * + * Note that "type change" includes collation change, which means we can rely + * on the MCV list being consistent with the collation info in pg_attribute + * during estimation. */ void UpdateStatisticsForTypeChange(Oid statsOid, Oid relationOid, int attnum, -- cgit v1.2.3