Fix crash on create statistics when it's not created on relation

This crash has been there for a while, but wasn't tested before pg18.
PG18 added this test:

CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;

which tries to create statistics on a derived-on-the-fly table
(which is not allowed)

However Citus assumes we always have a valid table when intercepting
CREATE STATISTICS command to check for Citus tables

Added a check to return early if needed
naisila/pg18_testing
naisila 2025-09-22 19:32:55 +03:00
parent d9f872058f
commit 9cb35fc7b8
1 changed files with 6 additions and 0 deletions

View File

@ -70,6 +70,12 @@ PreprocessCreateStatisticsStmt(Node *node, const char *queryString,
CreateStatsStmt *stmt = castNode(CreateStatsStmt, node);
RangeVar *relation = (RangeVar *) linitial(stmt->relations);
if (!IsA(relation, RangeVar))
{
return NIL;
}
Oid relationId = RangeVarGetRelid(relation, ShareUpdateExclusiveLock, false);
if (!IsCitusTable(relationId) || !ShouldPropagate())