rename a few more functions

onur-leftjoin_push-improvements
Onur Tirtir 2025-08-18 10:20:17 +03:00
parent 08ae68e5db
commit 2cbea6528f
5 changed files with 37 additions and 32 deletions

View File

@ -209,11 +209,11 @@ UpdateTaskQueryString(Query *query, Task *task)
/* /*
* DefineQualsForShardInterval creates the necessary qual conditions over the * CreateQualsForShardInterval creates the necessary qual conditions over the
* given attnum and rtindex for the given shard interval. * given attnum and rtindex for the given shard interval.
*/ */
Node * Node *
DefineQualsForShardInterval(RelationShard *relationShard, int attnum, int rtindex) CreateQualsForShardInterval(RelationShard *relationShard, int attnum, int rtindex)
{ {
uint64 shardId = relationShard->shardId; uint64 shardId = relationShard->shardId;
Oid relationId = relationShard->relationId; Oid relationId = relationShard->relationId;
@ -322,11 +322,11 @@ DefineQualsForShardInterval(RelationShard *relationShard, int attnum, int rtinde
/* /*
* UpdateWhereClauseForOuterJoinWalker walks over the query tree and * UpdateWhereClauseToPushdownRecurringOuterJoinWalker walks over the query tree and
* updates the WHERE clause for outer joins satisfying feasibility conditions. * updates the WHERE clause for outer joins satisfying feasibility conditions.
*/ */
bool bool
UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList) UpdateWhereClauseToPushdownRecurringOuterJoinWalker(Node *node, List *relationShardList)
{ {
if (node == NULL) if (node == NULL)
{ {
@ -335,14 +335,16 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList)
if (IsA(node, Query)) if (IsA(node, Query))
{ {
UpdateWhereClauseForOuterJoin((Query *) node, relationShardList); UpdateWhereClauseToPushdownRecurringOuterJoin((Query *) node, relationShardList);
return query_tree_walker((Query *) node, UpdateWhereClauseForOuterJoinWalker, return query_tree_walker((Query *) node,
UpdateWhereClauseToPushdownRecurringOuterJoinWalker,
relationShardList, QTW_EXAMINE_RTES_BEFORE); relationShardList, QTW_EXAMINE_RTES_BEFORE);
} }
if (!IsA(node, RangeTblEntry)) if (!IsA(node, RangeTblEntry))
{ {
return expression_tree_walker(node, UpdateWhereClauseForOuterJoinWalker, return expression_tree_walker(node,
UpdateWhereClauseToPushdownRecurringOuterJoinWalker,
relationShardList); relationShardList);
} }
@ -351,7 +353,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList)
/* /*
* UpdateWhereClauseForOuterJoin * UpdateWhereClauseToPushdownRecurringOuterJoin
* *
* Inject shard interval predicates into the query WHERE clause for certain * Inject shard interval predicates into the query WHERE clause for certain
* outer joins to make the join semantically correct when distributed. * outer joins to make the join semantically correct when distributed.
@ -367,7 +369,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList)
* *
* What the function does: * What the function does:
* 1. Iterate over the top-level jointree->fromlist. * 1. Iterate over the top-level jointree->fromlist.
* 2. For each JoinExpr call CheckPushDownFeasibilityAndComputeIndexes() which: * 2. For each JoinExpr call CanPushdownRecurringOuterJoinExtended() which:
* - Verifies shape / join type is eligible. * - Verifies shape / join type is eligible.
* - Returns: * - Returns:
* outerRtIndex : RT index whose column we will constrain, * outerRtIndex : RT index whose column we will constrain,
@ -376,7 +378,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList)
* This is compared to partition column of innerRte. * This is compared to partition column of innerRte.
* 3. Find the RelationShard for the inner distributed table (innerRte->relid) * 3. Find the RelationShard for the inner distributed table (innerRte->relid)
* in relationShardList; skip if absent (no fixed shard chosen). * in relationShardList; skip if absent (no fixed shard chosen).
* 4. Build the shard qualification with DefineQualsForShardInterval(): * 4. Build the shard qualification with CreateQualsForShardInterval():
* (minValue < hash(partcol) AND hash(partcol) <= maxValue) * (minValue < hash(partcol) AND hash(partcol) <= maxValue)
* and, for the first shard only, OR (partcol IS NULL). * and, for the first shard only, OR (partcol IS NULL).
* The Var refers to (outerRtIndex, attnum) so the restriction applies to * The Var refers to (outerRtIndex, attnum) so the restriction applies to
@ -386,7 +388,7 @@ UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList)
* The function does not return anything, it modifies the query in place. * The function does not return anything, it modifies the query in place.
*/ */
void void
UpdateWhereClauseForOuterJoin(Query *query, List *relationShardList) UpdateWhereClauseToPushdownRecurringOuterJoin(Query *query, List *relationShardList)
{ {
if (query == NULL) if (query == NULL)
{ {
@ -416,8 +418,8 @@ UpdateWhereClauseForOuterJoin(Query *query, List *relationShardList)
RangeTblEntry *outerRte = NULL; RangeTblEntry *outerRte = NULL;
int outerRtIndex = -1; int outerRtIndex = -1;
int attnum; int attnum;
if (!CheckPushDownFeasibilityAndComputeIndexes(joinExpr, query, &outerRtIndex, if (!CanPushdownRecurringOuterJoinExtended(joinExpr, query, &outerRtIndex,
&outerRte, &innerRte, &attnum)) &outerRte, &innerRte, &attnum))
{ {
continue; continue;
} }
@ -438,7 +440,7 @@ UpdateWhereClauseForOuterJoin(Query *query, List *relationShardList)
continue; continue;
} }
Node *shardIntervalBoundQuals = DefineQualsForShardInterval(relationShard, attnum, Node *shardIntervalBoundQuals = CreateQualsForShardInterval(relationShard, attnum,
outerRtIndex); outerRtIndex);
if (fromExpr->quals == NULL) if (fromExpr->quals == NULL)
{ {

View File

@ -2622,7 +2622,8 @@ QueryPushdownTaskCreate(Query *originalQuery, int shardIndex,
if (updateQualsForOuterJoin) if (updateQualsForOuterJoin)
{ {
UpdateWhereClauseForOuterJoinWalker((Node *) taskQuery, relationShardList); UpdateWhereClauseToPushdownRecurringOuterJoinWalker((Node *) taskQuery,
relationShardList);
} }

View File

@ -2859,7 +2859,7 @@ JoinTreeContainsLateral(Node *node, List *rtable)
/* /*
* CheckPushDownFeasibilityAndComputeIndexes checks if the given join expression * CanPushdownRecurringOuterJoinExtended checks if the given join expression
* is an outer join between recurring rel -on outer part- and a distributed * is an outer join between recurring rel -on outer part- and a distributed
* rel -on the inner side- and if it is feasible to push down the join. If feasible, * rel -on the inner side- and if it is feasible to push down the join. If feasible,
* it computes the outer relation's range table index, the outer relation's * it computes the outer relation's range table index, the outer relation's
@ -2867,9 +2867,9 @@ JoinTreeContainsLateral(Node *node, List *rtable)
* attribute number of the partition column in the outer relation. * attribute number of the partition column in the outer relation.
*/ */
bool bool
CheckPushDownFeasibilityAndComputeIndexes(JoinExpr *joinExpr, Query *query, CanPushdownRecurringOuterJoinExtended(JoinExpr *joinExpr, Query *query,
int *outerRtIndex, RangeTblEntry **outerRte, int *outerRtIndex, RangeTblEntry **outerRte,
RangeTblEntry **distRte, int *attnum) RangeTblEntry **distRte, int *attnum)
{ {
if (!EnableRecurringOuterJoinPushdown) if (!EnableRecurringOuterJoinPushdown)
{ {
@ -3013,8 +3013,8 @@ CheckPushDownFeasibilityAndComputeIndexes(JoinExpr *joinExpr, Query *query,
/* /*
* CanPushdownRecurringOuterJoin initializes input variables to call * CanPushdownRecurringOuterJoin initializes input variables to call
* CheckPushDownFeasibilityAndComputeIndexes. * CanPushdownRecurringOuterJoinExtended.
* See CheckPushDownFeasibilityAndComputeIndexes for more details. * See CanPushdownRecurringOuterJoinExtended for more details.
*/ */
bool bool
CanPushdownRecurringOuterJoin(JoinExpr *joinExpr, Query *query) CanPushdownRecurringOuterJoin(JoinExpr *joinExpr, Query *query)
@ -3023,6 +3023,6 @@ CanPushdownRecurringOuterJoin(JoinExpr *joinExpr, Query *query)
RangeTblEntry *outerRte = NULL; RangeTblEntry *outerRte = NULL;
RangeTblEntry *innerRte = NULL; RangeTblEntry *innerRte = NULL;
int attnum; int attnum;
return CheckPushDownFeasibilityAndComputeIndexes(joinExpr, query, &outerRtIndex, return CanPushdownRecurringOuterJoinExtended(joinExpr, query, &outerRtIndex,
&outerRte, &innerRte, &attnum); &outerRte, &innerRte, &attnum);
} }

View File

@ -25,10 +25,12 @@
extern void RebuildQueryStrings(Job *workerJob); extern void RebuildQueryStrings(Job *workerJob);
extern bool UpdateRelationToShardNames(Node *node, List *relationShardList); extern bool UpdateRelationToShardNames(Node *node, List *relationShardList);
extern void UpdateWhereClauseForOuterJoin(Query *query, List *relationShardList); extern void UpdateWhereClauseToPushdownRecurringOuterJoin(Query *query,
extern bool UpdateWhereClauseForOuterJoinWalker(Node *node, List *relationShardList); List *relationShardList);
Node * DefineQualsForShardInterval(RelationShard *relationShard, int attnum, int extern bool UpdateWhereClauseToPushdownRecurringOuterJoinWalker(Node *node,
outerRtIndex); List *relationShardList);
Node * CreateQualsForShardInterval(RelationShard *relationShard, int attnum,
int outerRtIndex);
extern void SetTaskQueryIfShouldLazyDeparse(Task *task, Query *query); extern void SetTaskQueryIfShouldLazyDeparse(Task *task, Query *query);
extern void SetTaskQueryString(Task *task, char *queryString); extern void SetTaskQueryString(Task *task, char *queryString);
extern void SetTaskQueryStringList(Task *task, List *queryStringList); extern void SetTaskQueryStringList(Task *task, List *queryStringList);

View File

@ -54,11 +54,11 @@ extern bool IsRecursivelyPlannableRelation(RangeTblEntry *rangeTableEntry);
extern bool IsRelationLocalTableOrMatView(Oid relationId); extern bool IsRelationLocalTableOrMatView(Oid relationId);
extern bool ContainsReferencesToOuterQuery(Query *query); extern bool ContainsReferencesToOuterQuery(Query *query);
extern void UpdateVarNosInNode(Node *node, Index newVarNo); extern void UpdateVarNosInNode(Node *node, Index newVarNo);
extern bool CheckPushDownFeasibilityAndComputeIndexes(JoinExpr *joinExpr, Query *query, extern bool CanPushdownRecurringOuterJoinExtended(JoinExpr *joinExpr, Query *query,
int *outerRtIndex, int *outerRtIndex,
RangeTblEntry **outerRte, RangeTblEntry **outerRte,
RangeTblEntry **distRte, RangeTblEntry **distRte,
int *attnum); int *attnum);
bool ResolveBaseVarFromSubquery(Var *var, Query *query, Var **baseVar, bool ResolveBaseVarFromSubquery(Var *var, Query *query, Var **baseVar,
RangeTblEntry **baseRte); RangeTblEntry **baseRte);
#endif /* RECURSIVE_PLANNING_H */ #endif /* RECURSIVE_PLANNING_H */