diff options
author | Tomas Vondra <tomas.vondra@postgresql.org> | 2021-09-20 00:34:57 +0200 |
---|---|---|
committer | Tomas Vondra <tomas.vondra@postgresql.org> | 2021-09-20 00:34:57 +0200 |
commit | c9eeef2a15c02ff7dd2bf3251dbee925b050fc0f (patch) | |
tree | 52e6559cacf62a8e13636f67d3bb16199d453872 /src/backend | |
parent | d5eeb51bc053d75f647136026de522d6ee3bf725 (diff) | |
download | postgresql-c9eeef2a15c02ff7dd2bf3251dbee925b050fc0f.tar.gz postgresql-c9eeef2a15c02ff7dd2bf3251dbee925b050fc0f.zip |
Disallow extended statistics on system columns
Since introduction of extended statistics, we've disallowed references
to system columns. So for example
CREATE STATISTICS s ON ctid FROM t;
would fail. But with extended statistics on expressions, it was possible
to work around this limitation quite easily
CREATE STATISTICS s ON (ctid::text) FROM t;
This is an oversight in a4d75c86bf, fixed by adding a simple check.
Backpatch to PostgreSQL 14, where support for extended statistics on
expressions was introduced.
Backpatch-through: 14
Discussion: https://postgr.es/m/20210816013255.GS10479%40telsasoft.com
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/commands/statscmds.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/backend/commands/statscmds.c b/src/backend/commands/statscmds.c index 78917844dee..afe6744e237 100644 --- a/src/backend/commands/statscmds.c +++ b/src/backend/commands/statscmds.c @@ -288,9 +288,24 @@ CreateStatistics(CreateStatsStmt *stmt) Node *expr = selem->expr; Oid atttype; TypeCacheEntry *type; + Bitmapset *attnums = NULL; + int k; Assert(expr != NULL); + /* Disallow expressions referencing system attributes. */ + pull_varattnos(expr, 1, &attnums); + + k = -1; + while ((k = bms_next_member(attnums, k)) >= 0) + { + AttrNumber attnum = k + FirstLowInvalidHeapAttributeNumber; + if (attnum <= 0) + ereport(ERROR, + (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), + errmsg("statistics creation on system columns is not supported"))); + } + /* * Disallow data types without a less-than operator. * |