Skip to content

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

Conversation

yuzefovich
Copy link
Member

@yuzefovich yuzefovich commented Jul 1, 2025

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.

@yuzefovich yuzefovich force-pushed the blathers/backport-release-25.2-149093 branch from 5bb9043 to 77f4ae1 Compare July 1, 2025 02:32
@yuzefovich yuzefovich requested a review from a team as a code owner July 1, 2025 02:32
@yuzefovich yuzefovich requested review from michae2 and removed request for a team July 1, 2025 02:32
@blathers-crl blathers-crl bot added blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. labels Jul 1, 2025
@blathers-crl blathers-crl bot requested a review from DrewKimball July 1, 2025 02:33
Copy link

blathers-crl bot commented Jul 1, 2025

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.

@blathers-crl blathers-crl bot added the backport Label PR's that are backports to older release branches label Jul 1, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

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.
@yuzefovich yuzefovich force-pushed the blathers/backport-release-25.2-149093 branch from 77f4ae1 to 39501ea Compare July 1, 2025 03:40
Copy link
Collaborator

@michae2 michae2 left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)

Copy link
Collaborator

@michae2 michae2 left a 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: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @DrewKimball)

@michae2 michae2 requested a review from rytaft July 1, 2025 05:39
@michae2
Copy link
Collaborator

michae2 commented Jul 1, 2025

Oh, 25.2 is not yet in LTS. So I guess this doesn't apply yet.

@yuzefovich
Copy link
Member Author

Yeah, I think we don't need a more extensive review given 25.2 is not LTS yet. TFTR!

@yuzefovich yuzefovich merged commit b39c685 into cockroachdb:release-25.2 Jul 2, 2025
15 checks passed
@yuzefovich yuzefovich deleted the blathers/backport-release-25.2-149093 branch July 2, 2025 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Label PR's that are backports to older release branches blathers-backport This is a backport that Blathers created automatically. O-robot Originated from a bot. target-release-25.2.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants