diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-14 12:22:16 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2017-05-14 12:22:25 -0400 |
commit | b5b0db19b895f033ada35bc7c337183be7356977 (patch) | |
tree | 2ef2429aaf1963d59d440462f65a53a61f1af6e8 /src/backend/commands/statscmds.c | |
parent | 65b655b53ec1cb91fda0d34e5176f8cdcfcf2e3d (diff) | |
download | postgresql-b5b0db19b895f033ada35bc7c337183be7356977.tar.gz postgresql-b5b0db19b895f033ada35bc7c337183be7356977.zip |
Fix handling of extended statistics during ALTER COLUMN TYPE.
ALTER COLUMN TYPE on a column used by a statistics object fails since
commit 928c4de30, because the relevant switch in ATExecAlterColumnType
is unprepared for columns to have dependencies from OCLASS_STATISTIC_EXT
objects.
Although the existing types of extended statistics don't actually need us
to do any work for a column type change, it seems completely indefensible
that that assumption is hidden behind the failure of an unrelated module
to contain any code for the case. Hence, create and call an API function
in statscmds.c where the assumption can be explained, and where we could
add code to deal with the problem when it inevitably becomes real.
Also, the reason this wasn't handled before, neither for extended stats
nor for the last half-dozen new OCLASS kinds :-(, is that the default:
in that switch suppresses compiler warnings, allowing people to miss the
need to consider it when adding an OCLASS. We don't really need a default
because surely getObjectClass should only return valid values of the enum;
so remove it, and add the missed OCLASS entries where they should be.
Discussion: https://postgr.es/m/20170512221010.nglatgt5azzdxjlj@alvherre.pgsql
Diffstat (limited to 'src/backend/commands/statscmds.c')
-rw-r--r-- | src/backend/commands/statscmds.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index cab54c962c6..94865b395b7 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -378,3 +378,31 @@ RemoveStatisticsById(Oid statsOid) heap_close(relation, RowExclusiveLock); } + +/* + * Update a statistics object for ALTER COLUMN TYPE on a source column. + * + * This could throw an error if the type change can't be supported. + * If it can be supported, but the stats must be recomputed, a likely choice + * would be to set the relevant column(s) of the pg_statistic_ext tuple to + * null until the next ANALYZE. (Note that the type change hasn't actually + * happened yet, so one option that's *not* on the table is to recompute + * immediately.) + */ +void +UpdateStatisticsForTypeChange(Oid statsOid, Oid relationOid, int attnum, + Oid oldColumnType, Oid newColumnType) +{ + /* + * Currently, we don't actually need to do anything here. For both + * ndistinct and functional-dependencies stats, the on-disk representation + * is independent of the source column data types, and it is plausible to + * assume that the old statistic values will still be good for the new + * column contents. (Obviously, if the ALTER COLUMN TYPE has a USING + * expression that substantially alters the semantic meaning of the column + * values, this assumption could fail. But that seems like a corner case + * that doesn't justify zapping the stats in common cases.) + * + * Future types of extended stats will likely require us to work harder. + */ +} |