Support PostgreSQL 18’s new RTE kinds in Citus deparser to fix OID 0

Enhance set_relation_column_names to handle relid validation and support for synthetic PG 18 RTEs

Handle unnamed groups in set_rtable_names by using the group's name
m3hm3t/pg18_dev_relation_oid_0
Mehmet Yilmaz 2025-05-08 15:46:04 +00:00
parent 3f9e12e010
commit 8aaf7bca34
2 changed files with 31 additions and 2 deletions

1
citus-tools Submodule

@ -0,0 +1 @@
Subproject commit 3376bd6845f0614908ed304f5033bd644c82d3bf

View File

@ -795,6 +795,11 @@ set_rtable_names(deparse_namespace *dpns, List *parent_namespaces,
/* Unnamed join has no refname */ /* Unnamed join has no refname */
refname = NULL; refname = NULL;
} }
else if (rte->rtekind == RTE_GROUP)
{
/* Use the name of the group */
refname = NULL;
}
else else
{ {
/* Otherwise use whatever the parser assigned */ /* Otherwise use whatever the parser assigned */
@ -1191,8 +1196,9 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
* real_colnames[] will be indexed by physical column number, with NULL * real_colnames[] will be indexed by physical column number, with NULL
* entries for dropped columns. * entries for dropped columns.
*/ */
if (rte->rtekind == RTE_RELATION || if ((rte->rtekind == RTE_RELATION ||
GetRangeTblKind(rte) == CITUS_RTE_SHARD) GetRangeTblKind(rte) == CITUS_RTE_SHARD) &&
OidIsValid(rte->relid))
{ {
/* Relation --- look to the system catalogs for up-to-date info */ /* Relation --- look to the system catalogs for up-to-date info */
Relation rel; Relation rel;
@ -1214,6 +1220,28 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte,
real_colnames[i] = pstrdup(NameStr(attr->attname)); real_colnames[i] = pstrdup(NameStr(attr->attname));
} }
relation_close(rel, AccessShareLock); relation_close(rel, AccessShareLock);
}
else if (GetRangeTblKind(rte) == CITUS_RTE_SHARD)
{
/* shard RTE without relid (pulled-up clone in PG18) */
/* use the column aliases already stored in rte->eref->colnames */
ncolumns = list_length(rte->eref->colnames);
real_colnames = (char **) palloc0(ncolumns * sizeof(char *));
for (i = 0; i < ncolumns; i++)
real_colnames[i] = pstrdup(strVal(list_nth(rte->eref->colnames, i)));
/* keep changed_any / has_anonymous defaults */
}
else if (rte->rtekind == RTE_GROUP)
{
/* ----- synthetic PG 18 RTE for GROUP BY / HAVING ----- */
ncolumns = list_length(rte->eref->colnames);
real_colnames = (char **) palloc0(ncolumns * sizeof(char *));
for (i = 0; i < ncolumns; i++)
real_colnames[i] = pstrdup(strVal(list_nth(rte->eref->colnames, i)));
} }
else else
{ {