Fix join type for correlated subquery#19002
Conversation
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
|
Thanks! Can you add a test? Here's a cleaned up query you can use for the test: WITH
t(k, v) AS (VALUES ('A', 1), ('B', NULL), ('C', 2), ('D', 3)),
u(k, v) AS (VALUES (1, 10), (1, 20), (2, 30))
SELECT
k,
(
SELECT max(v)
FROM u
WHERE t.v = u.k
GROUP BY k
) AS cols
FROM tYou can add the test to the suite in |
cdfa0e8 to
f133c08
Compare
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
f133c08 to
b81dbc5
Compare
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
b81dbc5 to
a93a6f3
Compare
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
| correlatedJoinNode.getInput(), | ||
| rewrittenSubquery, | ||
| correlatedJoinNode.getCorrelation(), | ||
| producesSingleRow ? correlatedJoinNode.getType() : LEFT, |
There was a problem hiding this comment.
What scenario fails due to this?
There was a problem hiding this comment.
This is just a accompanying change(no logic change here). This is needed because in subqueryPlanner correlatedJoinNode type is set to LEFT and now when this line is evaluated correlatedJoinNode.getType() will have LEFT(instead of INNER). Made this change just to preserve the logic of using INNER join when subquery has 1 cardinality and LEFT when it has 0 cardinality.
|
@cla-bot check |
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
| subPlan, | ||
| root, | ||
| scalarSubquery.getQuery(), | ||
| CorrelatedJoinNode.Type.INNER, |
There was a problem hiding this comment.
This was actually correct code as EnforceSingleRowNode guarantees exactly single row, so from the "perspective" of CorrelatedJoin INNER is OK.
I've cleaned this up in #19932
Description
INNER join is used in subqueryPlanner's planScalarSubquery. But it will result in incorrect results when the subquery returns zero rows.
Example query:
Actual results:
Expected results:
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( X) Release notes are required, with the following suggested text: