Commit 66061077 authored by Tomas Vondra's avatar Tomas Vondra

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 a4d75c86, 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
parent 2a9a34c3
...@@ -287,9 +287,24 @@ CreateStatistics(CreateStatsStmt *stmt) ...@@ -287,9 +287,24 @@ CreateStatistics(CreateStatsStmt *stmt)
Node *expr = selem->expr; Node *expr = selem->expr;
Oid atttype; Oid atttype;
TypeCacheEntry *type; TypeCacheEntry *type;
Bitmapset *attnums = NULL;
int k;
Assert(expr != NULL); 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. * Disallow data types without a less-than operator.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment