Skip to content

sql/opt: add implicit SELECT FOR UPDATE support for UPSERT statements #50180

@nvb

Description

@nvb

Address this TODO:

// 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.

Metadata

Metadata

Assignees

Labels

A-sql-optimizerSQL logical planning and optimizations.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions