Skip to content

Commit

Permalink
Fix HideCitusDependentObjectsOnQueriesOfPgMetaTables function
Browse files Browse the repository at this point in the history
The function should take into account the new entry for
MERGE joins that is introduced in PG17
-> mergeJoinCondition
  • Loading branch information
naisila committed Dec 20, 2024
1 parent 8d4b53e commit f6a8223
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/backend/distributed/utils/citus_depended_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f6a8223

Please sign in to comment.