-
Notifications
You must be signed in to change notification settings - Fork 671
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
Fix Test Failure in subquery_in_where, set_operations in PG17 (#7741) #7745
base: naisila/pg17_support
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## naisila/pg17_support #7745 +/- ##
========================================================
- Coverage 89.61% 89.60% -0.01%
========================================================
Files 274 274
Lines 59689 59689
Branches 7446 7446
========================================================
- Hits 53490 53485 -5
- Misses 4069 4073 +4
- Partials 2130 2131 +1 |
@@ -134,7 +134,7 @@ SELECT * FROM test a WHERE x NOT IN (SELECT x FROM test b WHERE y = 1 UNION SELE | |||
SELECT * FROM test a WHERE x IN (SELECT x FROM test b UNION SELECT y FROM test c) ORDER BY 1,2; | |||
|
|||
-- correlated subquery with union in WHERE clause | |||
SELECT * FROM test a WHERE x IN (SELECT x FROM test b UNION SELECT y FROM test c WHERE a.x = c.x) ORDER BY 1,2; | |||
SELECT * FROM test a WHERE (x + random()) IN (SELECT x FROM test b UNION SELECT y FROM test c WHERE a.x = c.x) ORDER BY 1,2; |
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.
A similar approach was taken for existing regress tests in the postgres commit.
They followed this approach in the postgres tests because they were having EXPLAIN
diffs, and they wanted to avoid adding a new alternative test output file for PG17. In Citus, note that in these two tests, we are trying to run the query, not to explain it. So, we try to run these queries, both of them unexpectedly work.
My point is, we also need to understand what changed in the Citus planner path, in the codebase, and make sure that Citus is running these queries correctly.
Current fix is great, by the way, no extra output file, but we may need to test this more extensively in Citus through this PR.
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.
Got it. I think that the Citus planner is running the queries correctly (in pg17) because it is getting a different plan from the pg planner, but I will verify, and see what tests can be added (maybe to pg17 regress test?) to test the new behavior in pg17.
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.
Thank you, that sounds great.
maybe to pg17 regress test
Yes, makes sense.
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.
The latest push contains a pg17 regress test that tests the pg17 feature of pulling up correlated ANY subqueries. It can be extended to test other 17-related functionality as appropriate.
By the way, can we add a similar fix to |
0cb74b8
to
1a6ef7c
Compare
Yes, it looks like |
…in PG17 (#7741) Change the queries causing the test failures so that the ANY subquery cannot be folded to a join, preserving the expected output of the test. Add pg17 regress test for pg17 features.
1a6ef7c
to
7b7d2d0
Compare
@colm-mchugh please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
Fix Test Failure in subquery_in_where, set_operations in PG17 #7741
The test failures are caused by this commit in PG17, which enables correlated subqueries to be pulled up to a join. Prior to this, the correlated subquery was implemented as a subplan. In citus, it is not possible to pushdown a correlated subplan, but with a different plan in PG17 the query can be executed, per the test diff from
subquery_in_where
:This is because with pg17
= ANY subquery
in the queries can be implemented as a join, instead of as a subplan filter on a table scan. For example,SELECT * FROM test a WHERE x IN (SELECT x FROM test b UNION SELECT y FROM test c WHERE a.x = c.x) ORDER BY 1,2
(from set_operations) has this plan in pg17; note that the subquery is the inner side of a nested loop join:and this plan in pg16 (and previous pg versions); the subquery is a correlated subplan filter on a table scan:
The fix Modifies the queries causing the test failures so that an ANY subquery is not folded to a join, preserving the expected output of the tests. A similar approach was taken for existing regress tests in the postgres commit. See the
join
regress test, for example.