From 9cb35fc7b8bb06c2dc9187c35084468b90d9e9e3 Mon Sep 17 00:00:00 2001 From: naisila Date: Mon, 22 Sep 2025 19:32:55 +0300 Subject: [PATCH] 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 --- src/backend/distributed/commands/statistics.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/backend/distributed/commands/statistics.c b/src/backend/distributed/commands/statistics.c index b43f6335e..f537e7dd6 100644 --- a/src/backend/distributed/commands/statistics.c +++ b/src/backend/distributed/commands/statistics.c @@ -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())