-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
opt: left lookup join pair does not correctly null-extend unmatched rows #81968
Comments
Thanks for the report and the detailed repro steps! I think #58261 is to blame (which was merged in 22.1 time frame). |
Here is the plan:
I believe what's happening is the following:
This is where the bug is - we should have returned |
Thank you for the report, @50U10FCA7, and for the initial investigation, @yuzefovich. It looks like this is the same situation as we were seeing in #58892 for inverted joins. Since #58892 was already fixed, we see correct results if the example from above is tweaked slightly to use an inverted join:
The fix for this issue will be the same as the fix for #58892, but applied to I will submit a PR to fix this shortly. |
Prior to this patch, it was possible for a paired join to produce incorrect results for a left lookup join. In particular, some output rows had non-NULL values for right-side columns when the right-side columns should have been NULL. This commit fixes the issue by updating the optimizer to ensure that only columns from the second join in the paired join (the index join) are projected, not columns from the first (the lookup join). Fixes cockroachdb#81968 Release note (bug fix): Fixed an issue where a left lookup join could have incorrect results. In particular, some output rows could have non-NULL values for right-side columns when the right-side columns should have been NULL. This issue only exists in 22.1.0 and prior development releases of 22.1.
82054: opt: fix bug with incorrect results produced by paired left lookup join r=rytaft a=rytaft Prior to this patch, it was possible for a paired join to produce incorrect results for a left lookup join. In particular, some output rows had non-NULL values for right-side columns when the right-side columns should have been NULL. This commit fixes the issue by updating the optimizer to ensure that only columns from the second join in the paired join (the index join) are projected, not columns from the first (the lookup join). Fixes #81968 Release note (bug fix): Fixed an issue where a left lookup join could have incorrect results. In particular, some output rows could have non-NULL values for right-side columns when the right-side columns should have been NULL. This issue only exists in 22.1.0 and prior development releases of 22.1. Co-authored-by: Rebecca Taft <becca@cockroachlabs.com>
Prior to this patch, it was possible for a paired join to produce incorrect results for a left lookup join. In particular, some output rows had non-NULL values for right-side columns when the right-side columns should have been NULL. This commit fixes the issue by updating the optimizer to ensure that only columns from the second join in the paired join (the index join) are projected, not columns from the first (the lookup join). Fixes cockroachdb#81968 Release note (bug fix): Fixed an issue where a left lookup join could have incorrect results. In particular, some output rows could have non-NULL values for right-side columns when the right-side columns should have been NULL. This issue only exists in 22.1.0 and prior development releases of 22.1.
The fix for this issue will be available as part of v22.1.1, which is scheduled to be released next week. In the meantime, users who think they may be affected by this issue should take the following steps: To determine whether your queries may be affected by this issue on v22.1.0, you should examine the query plans of any queries with left joins or correlated subqueries by using
To mitigate this problem for affected queries on v22.1.0, ensure that tables used by queries with a left join or correlated subquery have only covering secondary indexes. That is, any secondary indexes on these tables should include (either as a key column or a Alternatively, non-covering indexes can be dropped. |
@50U10FCA7 Thank you so much for finding and filing this issue, we really appreciate it. We're always looking to improve our testing coverage, so we'd love to understand your use cases and workload. If you are willing to share, would you mind reaching out to support@cockroachlabs.com (please mention this GitHub issue in the email)? Thank you! |
Describe the problem
Found a problem with subqueries which is using columns of the main query table.
To Reproduce
MRE:
Expected behavior
Select returns
0
.Additional data / screenshots
cockroach sql
session log:Log of the same execution but without
chat_id_idx
index:Environment:
cockroach sql
]Additional context
The problem is not reproducible on the previous versions of
CockroachDB
(latest-v21.2
image tag), so I think some bug in the last update.Jira issue: CRDB-16146
The text was updated successfully, but these errors were encountered: