From 8aaf7bca34092bd958bc735cbe5cda6cad322f2b Mon Sep 17 00:00:00 2001 From: Mehmet Yilmaz Date: Thu, 8 May 2025 15:46:04 +0000 Subject: [PATCH] =?UTF-8?q?Support=20PostgreSQL=2018=E2=80=99s=20new=20RTE?= =?UTF-8?q?=20kinds=20in=20Citus=20deparser=20to=20fix=20OID=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- citus-tools | 1 + .../distributed/deparser/ruleutils_18.c | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 160000 citus-tools diff --git a/citus-tools b/citus-tools new file mode 160000 index 000000000..3376bd684 --- /dev/null +++ b/citus-tools @@ -0,0 +1 @@ +Subproject commit 3376bd6845f0614908ed304f5033bd644c82d3bf diff --git a/src/backend/distributed/deparser/ruleutils_18.c b/src/backend/distributed/deparser/ruleutils_18.c index 31d78b122..29a45c828 100644 --- a/src/backend/distributed/deparser/ruleutils_18.c +++ b/src/backend/distributed/deparser/ruleutils_18.c @@ -795,6 +795,11 @@ set_rtable_names(deparse_namespace *dpns, List *parent_namespaces, /* Unnamed join has no refname */ refname = NULL; } + else if (rte->rtekind == RTE_GROUP) + { + /* Use the name of the group */ + refname = NULL; + } else { /* 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 * entries for dropped columns. */ - if (rte->rtekind == RTE_RELATION || - GetRangeTblKind(rte) == CITUS_RTE_SHARD) + if ((rte->rtekind == RTE_RELATION || + GetRangeTblKind(rte) == CITUS_RTE_SHARD) && + OidIsValid(rte->relid)) { /* Relation --- look to the system catalogs for up-to-date info */ Relation rel; @@ -1215,6 +1221,28 @@ set_relation_column_names(deparse_namespace *dpns, RangeTblEntry *rte, } 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 { /* Otherwise get the column names from eref or expandRTE() */