sql: provide optimized single-request, CAS-style UPDATE
#85328
Labels
A-read-committed
Related to the introduction of Read Committed
C-enhancement
Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
T-sql-queries
SQL Queries Team
Projects
Is your feature request related to a problem? Please describe.
In some distributed storage systems like HashiCorp Consul, there is support for
CAS
operations (see https://www.consul.io/commands/kv/put#cas). In that system, the operation is atomic and happens in a single command.In cockroach, one can express a CAS put as an
UPDATE
where all of the old and new columns are implied and constrained to a single row. If the table had no unique secondary indexes, one could imagine turning the operation into a single batch containingCPut
operations and commit in that same batch. If there is a failure, the execution engine could interpret it to mean that the update affected zero rows.In today's cockroach, this operation is a
SELECT FOR UPDATE
followed by a the operations to update the row. This is ultimately two round-trips instead of one.Describe the solution you'd like
It'd be cool to have a way to do CAS updates as a single round-trip when all of the conditions properly align. Ideally we'd just have a single batch with a single
r82: sending batch 1 CPut, 1 EndTxn to (n1,s1):1
.Jira issue: CRDB-18191
The text was updated successfully, but these errors were encountered: