Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c9eeef2

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 d5eeb51 commit c9eeef2

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
@@ -288,9 +288,24 @@ CreateStatistics(CreateStatsStmt *stmt)
288288
Node *expr = selem->expr;
289289
Oid atttype;
290290
TypeCacheEntry *type;
291+
Bitmapset *attnums = NULL;
292+
int k;
291293

292294
Assert(expr != NULL);
293295

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

0 commit comments

Comments
 (0)