diff --git a/src/backend/distributed/utils/citus_depended_object.c b/src/backend/distributed/utils/citus_depended_object.c index 3babf76f0..bc14490b5 100644 --- a/src/backend/distributed/utils/citus_depended_object.c +++ b/src/backend/distributed/utils/citus_depended_object.c @@ -243,12 +243,24 @@ HideCitusDependentObjectsOnQueriesOfPgMetaTables(Node *node, void *context) if (OidIsValid(metaTableOid)) { + bool mergeJoinCondition = false; +#if PG_VERSION_NUM >= PG_VERSION_17 + + /* + * In Postgres 17, the query tree has a specific field for the merge condition. + * So we shouldn't modify the jointree, but rather the mergeJoinCondition here + * Relevant PG17 commit: 0294df2f1 + */ + mergeJoinCondition = query->mergeJoinCondition; +#endif + /* * We found a valid pg meta class in query, * so we assert below conditions. */ - Assert(query->jointree != NULL); - Assert(query->jointree->fromlist != NULL); + Assert(mergeJoinCondition || + (query->jointree != NULL && + query->jointree->fromlist != NULL)); Node *citusDependentObjExpr = CreateCitusDependentObjectExpr(varno, metaTableOid); @@ -257,8 +269,18 @@ HideCitusDependentObjectsOnQueriesOfPgMetaTables(Node *node, void *context) * We do not use security quals because a postgres vanilla test fails * with a change of order for its result. */ - query->jointree->quals = make_and_qual( - query->jointree->quals, citusDependentObjExpr); + if (!mergeJoinCondition) + { + query->jointree->quals = make_and_qual( + query->jointree->quals, citusDependentObjExpr); + } + else + { +#if PG_VERSION_NUM >= PG_VERSION_17 + query->mergeJoinCondition = make_and_qual( + query->mergeJoinCondition, citusDependentObjExpr); +#endif + } } MemoryContextSwitchTo(originalContext);