-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql/opt: add implicit SELECT FOR UPDATE support for UPSERT statements #50180
Copy link
Copy link
Closed
Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Description
Address this TODO:
cockroach/pkg/sql/opt/exec/execbuilder/mutation.go
Lines 981 to 989 in 01a780b
| // tryApplyImplicitLockingToUpsertInput determines whether or not the builder | |
| // should apply a FOR UPDATE row-level locking mode to the initial row scan of | |
| // an UPSERT statement. | |
| // | |
| // TODO(nvanbenschoten): implement this method to match on appropriate Upsert | |
| // expression trees and apply a row-level locking mode. | |
| func (b *Builder) shouldApplyImplicitLockingToUpsertInput(ups *memo.UpsertExpr) bool { | |
| return false | |
| } |
Specifically, UPSERT statements can occasionally hit a fast-path where they perform a blind PutRequest. However, for those that can't (e.g. writing a subset of columns or need to update a secondary index), an initial row scan must be used, just like with UPDATE statements. We should apply a FOR UPDATE row-level locking mode to the initial row scan of an UPSERT statement, in accordance with the enable_implicit_select_for_update session variable.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-sql-optimizerSQL logical planning and optimizations.SQL logical planning and optimizations.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)