Fix crash on create statistics with non-RangeVar type (#8213)

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.

pg18 commit: https://github.com/postgres/postgres/commit/3eea4dc2c

Fixes #8212
m3hm3t/pg18_rc1_conf^2
Naisila Puka 2025-10-01 00:09:11 +03:00 committed by GitHub
parent 5eb1d93be1
commit bb840e58a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 3 deletions

View File

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

View File

@ -4,11 +4,17 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 18 AS server_version_ge_18
\gset
-- test invalid statistics
-- behavior is same among PG versions, error message differs
-- relevant PG18 commit: 3eea4dc2c7
CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;
ERROR: cannot create statistics on the specified relation
DETAIL: CREATE STATISTICS only supports tables, foreign tables and materialized views.
\if :server_version_ge_18
\else
\q
\endif
-- PG17-specific tests go here.
-- PG18-specific tests go here.
--
-- Purpose: Verify PG18 behavior that NOT NULL constraints are materialized
-- as pg_constraint rows with contype = 'n' on both coordinator and

View File

@ -4,6 +4,11 @@
SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 18 AS server_version_ge_18
\gset
-- test invalid statistics
-- behavior is same among PG versions, error message differs
-- relevant PG18 commit: 3eea4dc2c7
CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;
ERROR: only a single relation is allowed in CREATE STATISTICS
\if :server_version_ge_18
\else
\q

View File

@ -5,12 +5,17 @@ SHOW server_version \gset
SELECT substring(:'server_version', '\d+')::int >= 18 AS server_version_ge_18
\gset
-- test invalid statistics
-- behavior is same among PG versions, error message differs
-- relevant PG18 commit: 3eea4dc2c7
CREATE STATISTICS tst ON a FROM (VALUES (x)) AS foo;
\if :server_version_ge_18
\else
\q
\endif
-- PG17-specific tests go here.
-- PG18-specific tests go here.
--
-- Purpose: Verify PG18 behavior that NOT NULL constraints are materialized