-
Notifications
You must be signed in to change notification settings - Fork 3.9k
release-25.2: execbuilder: fix locked indexes info in an edge case #149301
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
release-25.2: execbuilder: fix locked indexes info in an edge case #149301
Conversation
5bb9043
to
77f4ae1
Compare
Thanks for opening a backport. Before merging, please confirm that the change does not break backwards compatibility and otherwise complies with the backport policy. Include a brief release justification in the PR description explaining why the backport is appropriate. All backports must be reviewed by the TL for the owning area. While the stricter LTS policy does not yet apply, please exercise judgment and consider gating non-critical changes behind a disabled-by-default feature flag when appropriate. |
For buffered writes project, in 5e968e6 we started propagating information about which indexes have been locked which allows us to use non-locking Puts and Dels when mutating those indexes. That change had an incorrect assumption that any indexes we lock belong to the same table as the one being mutated. However, we just saw a user report where this wasn't the case - in some cases we might perform the initial scan on a different table (in the example, it was a FK referencing us), so we could incorrectly treat some indexes as having been locked when they haven't. With buffered writes enabled, this could lead to difference in blocking behavior (but no corruption or correctness issues since we still would find the concurrent write on COMMIT); with buffered writes disabled, the locked indexes info doesn't have any impact, so we could only hit an internal error when a given index ordinal doesn't exist in the target table. Furthermore, there is no point in locking an index of a different table since we might not actually modify it (this will depend on whether there exists a CASCADE action and which action it is). Release note (bug fix): CockroachDB previously could hit an internal error when performing a DELETE, an UPDATE, or an UPSERT statement where the initial scan of the mutation is locking and is on a table different from the one being mutated. As a workaround, one could do `SET enable_implicit_select_for_update = false`, but note that it might increase contention, so use with caution. The bug was introduced in 25.2 version and is now fixed.
77f4ae1
to
39501ea
Compare
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.
Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)
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.
IMO this counts as "breaking working and widely used functionality" because it fixes a bug that breaks statements such as DELETE ... WHERE ... (SELECT)
and UPDATE ... WHERE ... (SELECT)
which worked before v25.2.
I agree that this is already behind the existing enable_implicit_select_for_update
session variable.
Tagging @rytaft because I'm not sure if this is the kind of change that needs committee approval.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)
Oh, 25.2 is not yet in LTS. So I guess this doesn't apply yet. |
Yeah, I think we don't need a more extensive review given 25.2 is not LTS yet. TFTR! |
Backport 1/1 commits from #149093 on behalf of @yuzefovich.
For buffered writes project, in 5e968e6 we started propagating information about which indexes have been locked which allows us to use non-locking Puts and Dels when mutating those indexes. That change had an incorrect assumption that any indexes we lock belong to the same table as the one being mutated. However, we just saw a user report where this wasn't the case - in some cases we might perform the initial scan on a different table (in the example, it was a FK referencing us), so we could incorrectly treat some indexes as having been locked when they haven't. With buffered writes enabled, this could lead to difference in blocking behavior (but no corruption or correctness issues since we still would find the concurrent write on COMMIT); with buffered writes disabled, the locked indexes info doesn't have any impact, so we could only hit an internal error when a given index ordinal doesn't exist in the target table.
Furthermore, there is no point in locking an index of a different table since we might not actually modify it (this will depend on whether there exists a CASCADE action and which action it is).
Fixes: #148650.
Release note (bug fix): CockroachDB previously could hit an internal error when performing a DELETE, an UPDATE, or an UPSERT statement where the initial scan of the mutation is locking and is on a table different from the one being mutated. As a workaround, one could do
SET enable_implicit_select_for_update = false
, but note that it might increase contention, so use with caution. The bug was introduced in 25.2 version and is now fixed.Release justification: low-risk bug fix that can be disabled via existing
enable_implicit_select_for_update
session variable. Disabling the fix by default doesn't make sense.