-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#7782 - catch when Postgres planning removes all Citus tables #7907
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,7 +151,10 @@ | |
bool hasUnresolvedParams); | ||
static void ConcatenateRTablesAndPerminfos(PlannedStmt *mainPlan, | ||
PlannedStmt *concatPlan); | ||
|
||
static bool CheckPostPlanDistribution(bool isDistributedQuery, | ||
Query *origQuery, | ||
List *rangeTableList, | ||
Query *plannedQuery); | ||
|
||
/* Distributed planner hook */ | ||
PlannedStmt * | ||
|
@@ -272,6 +275,11 @@ | |
planContext.plan = standard_planner(planContext.query, NULL, | ||
planContext.cursorOptions, | ||
planContext.boundParams); | ||
needsDistributedPlanning = CheckPostPlanDistribution(needsDistributedPlanning, | ||
planContext.originalQuery, | ||
rangeTableList, | ||
planContext.query); | ||
|
||
if (needsDistributedPlanning) | ||
{ | ||
result = PlanDistributedStmt(&planContext, rteIdCounter); | ||
|
@@ -2729,3 +2737,41 @@ | |
} | ||
} | ||
} | ||
|
||
|
||
static bool | ||
CheckPostPlanDistribution(bool isDistributedQuery, | ||
Query *origQuery, List *rangeTableList, | ||
Query *plannedQuery) | ||
{ | ||
if (isDistributedQuery) | ||
{ | ||
Node *origQuals = origQuery->jointree->quals; | ||
Node *plannedQuals = plannedQuery->jointree->quals; | ||
Comment on lines
+2749
to
+2750
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any way we can run into this while in a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly... if the target is a local table ... I will verify, thanks for noticing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So a PG17+ |
||
|
||
#if PG_VERSION_NUM >= PG_VERSION_17 | ||
if (IsMergeQuery(origQuery)) | ||
{ | ||
origQuals = origQuery->mergeJoinCondition; | ||
plannedQuals = plannedQuery->mergeJoinCondition; | ||
} | ||
#endif | ||
|
||
/* | ||
* The WHERE quals have been eliminated by the Postgres planner, possibly by | ||
* an OR clause that was simplified to TRUE. In such cases, we need to check | ||
* if the planned query still requires distributed planning. | ||
*/ | ||
if (origQuals != NULL && plannedQuals == NULL) | ||
{ | ||
List *rtesPostPlan = ExtractRangeTableEntryList(plannedQuery); | ||
if (list_length(rtesPostPlan) < list_length(rangeTableList)) | ||
{ | ||
isDistributedQuery = ListContainsDistributedTableRTE( | ||
rtesPostPlan, NULL); | ||
} | ||
} | ||
} | ||
|
||
return isDistributedQuery; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I am a bit confused.
Wasn't the original issue that we skipped distributed planning due to
isDistributedQuery
being false when it should have been true?It looks like the original issue was the other way around, since you are checking if
isDistributedQuery
is true here ...EDIT: I now understood the issue. I had to re-read the PR description carefully.