Skip to content

Commit 6606107

Browse files
committed
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 a4d75c8, 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
1 parent 2a9a34c commit 6606107

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/backend/commands/statscmds.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,24 @@ CreateStatistics(CreateStatsStmt *stmt)
287287
Node *expr = selem->expr;
288288
Oid atttype;
289289
TypeCacheEntry *type;
290+
Bitmapset *attnums = NULL;
291+
int k;
290292

291293
Assert(expr != NULL);
292294

295+
/* Disallow expressions referencing system attributes. */
296+
pull_varattnos(expr, 1, &attnums);
297+
298+
k = -1;
299+
while ((k = bms_next_member(attnums, k)) >= 0)
300+
{
301+
AttrNumber attnum = k + FirstLowInvalidHeapAttributeNumber;
302+
if (attnum <= 0)
303+
ereport(ERROR,
304+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
305+
errmsg("statistics creation on system columns is not supported")));
306+
}
307+
293308
/*
294309
* Disallow data types without a less-than operator.
295310
*

0 commit comments

Comments
 (0)