Skip to content
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

Merged
merged 1 commit into from
Feb 27, 2025

Conversation

colm-mchugh
Copy link
Contributor

@colm-mchugh colm-mchugh commented Feb 20, 2025

DESCRIPTION: fix a planning error caused by a redundant WHERE clause

Fix a Citus planning glitch that occurs in a DML query when the WHERE clause of the query is of the form:
WHERE true OR <expression with 1 or more citus tables>
and this is the only place in the query referencing a citus table. Postgres' standard planner transforms the WHERE clause to:
WHERE true
So the query now has no citus tables, confusing the Citus planner as described in issues #7782 and #7783. The fix is to check, after Postgres standard planner, if the Query has been transformed as shown, and re-run the check of whether or not the query needs distributed planning.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.47%. Comparing base (c55bc8c) to head (0b20a9b).
Report is 23 commits behind head on release-13.0.

Additional details and impacted files
@@               Coverage Diff                @@
##           release-13.0    #7907      +/-   ##
================================================
- Coverage         89.48%   89.47%   -0.02%     
================================================
  Files               276      276              
  Lines             60063    60022      -41     
  Branches           7524     7520       -4     
================================================
- Hits              53747    53704      -43     
- Misses             4166     4169       +3     
+ Partials           2150     2149       -1     

@colm-mchugh colm-mchugh marked this pull request as draft February 20, 2025 14:52
@colm-mchugh colm-mchugh force-pushed the colm/issue_7782 branch 3 times, most recently from 7cf5873 to 63725bf Compare February 21, 2025 13:39
@colm-mchugh colm-mchugh marked this pull request as ready for review February 21, 2025 14:28
@naisila
Copy link
Member

naisila commented Feb 22, 2025

What an interesting failure! Thanks for this PR.

We modify the distributed_planner function very rarely. Hopefully I will review when I am back from OOO.

@colm-mchugh
Copy link
Contributor Author

What an interesting failure! Thanks for this PR.

We modify the distributed_planner function very rarely. Hopefully I will review when I am back from OOO.

Sure; this seems to be the best (only?) way to deal with this planning quirk, but lmk what you think.

Comment on lines +2749 to +2750
Node *origQuals = origQuery->jointree->quals;
Node *plannedQuals = plannedQuery->jointree->quals;
Copy link
Member

@naisila naisila Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we can run into this while in a MERGE query? Given that in PG17 we have a separate mergeJoinClause?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a PG17+ MERGE query was not covered by the fix - have updated the PR correspondingly.

Query *origQuery, List *rangeTableList,
Query *plannedQuery)
{
if (isDistributedQuery)
Copy link
Member

@naisila naisila Feb 26, 2025

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.

DESCRIPTION: fix a planning error caused by a redundant WHERE clause
(of the form WHERE true OR <expression>)

Fix a Citus planning glitch, where the WHERE clause of
the query is of the form:
` WHERE true OR <expression with 1 or more citus tables> `
and this is the only place in the query referencing a citus
table. Postgres' standard planner transforms the WHERE clause to:
` WHERE true `
So the query now has no citus tables, confusing the Citus planner
as described in issues #7782 and #7783. The fix is to check, after
Postgres standard planner, if the Query has been transformed as
shown, and re-run the check of whether or not the query needs
distributed planning.
Copy link
Member

@naisila naisila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀
I don't see an easy way to fix this outside distributed_planner

@colm-mchugh colm-mchugh merged commit 86107ca into release-13.0 Feb 27, 2025
119 checks passed
@colm-mchugh colm-mchugh deleted the colm/issue_7782 branch February 27, 2025 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A logic bug with distributed table A logic bug caused by a UPDATE statement with distributed table
2 participants