cockroach
cockroach copied to clipboard
opt: propagate extra columns for lock operators
A lock operator needs access to all primary key columns of the relations it locks. Therefore, all primary key columns should be propagated by a SELECT clause with locking even if they weren't explicitly projected. Previously, only explicitly projected columns were considered when handling a nested scope, as for a subquery. This could lead to an internal error when the lock operator did not have access to the expected columns. This commit fixes the bug by propgating all primary key columns, not just explicit ones.
Fixes #129647
Release note (bug fix): Fixed a bug that could cause an internal error if a table with an implicit (rowid) primary key was locked from within a subquery, like this:
SELECT * FROM (SELECT * FROM foo WHERE x = 2) FOR UPDATE;
pkg/sql/opt/optbuilder/locking.go line 280 at r1 (raw file):
Previously, mgartner (Marcus Gartner) wrote…
nit: add this method to avoid the potential colset allocations and slightly costly iteration over a large set:
func (s *scope) forEachColWithExtras(fn func(col *scopeColumn)) { for i := range s.cols { fn(&s.cols[i]) } for i := range s.extraCols { fn(&s.extraCols[i]) } }
This would also avoid the extra interation in inScope.getColumn
bors r+
Build succeeded:
Based on the specified backports for this PR, I applied new labels to the following linked issue(s). Please adjust the labels as needed to match the branches actually affected by the issue(s), including adding any known older branches.
Issue #129647: branch-release-23.2, branch-release-24.1.
:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.
Encountered an error creating backports. Some common things that can go wrong:
- The backport branch might have already existed.
- There was a merge conflict.
- The backport branch contained merge commits.
You might need to create your backport manually using the backport tool.
error creating merge commit from 5dcf84be164945224b61aafdfab401a4afaf19cc to blathers/backport-release-23.2-129768: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []
you may need to manually resolve merge conflicts with the backport tool.
Backport to branch 23.2.x failed. See errors above.
error creating merge commit from 5dcf84be164945224b61aafdfab401a4afaf19cc to blathers/backport-release-24.2-129768: POST https://api.github.com/repos/cockroachdb/cockroach/merges: 409 Merge conflict []
you may need to manually resolve merge conflicts with the backport tool.
Backport to branch 24.2.x failed. See errors above.
:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.
@DrewKimball Don't forget to manually backport to 24.2 and 23.2, if that is still necessary.