-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: multiple mutations on same row can cause inconsistency #70731
Copy link
Copy link
Open
Labels
A-sql-executionRelating to SQL execution.Relating to SQL execution.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-erroneous-edge-caseDatabase produces or stores erroneous data without visible error/warning, in rare edge cases.Database produces or stores erroneous data without visible error/warning, in rare edge cases.T-kvKV TeamKV TeamT-sql-queriesSQL Queries TeamSQL Queries Teamdocs-donedocs-known-limitation
Metadata
Metadata
Assignees
Labels
A-sql-executionRelating to SQL execution.Relating to SQL execution.C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-erroneous-edge-caseDatabase produces or stores erroneous data without visible error/warning, in rare edge cases.Database produces or stores erroneous data without visible error/warning, in rare edge cases.T-kvKV TeamKV TeamT-sql-queriesSQL Queries TeamSQL Queries Teamdocs-donedocs-known-limitation
Type
Projects
Status
Backlog
In #44466 we found that an upsert statement modifying the same row twice could lead to inconsistencies, due to the upsert operator not reading its own writes. This was fixed in #45372 by checking that the input to the upsert is distinct on PKs.
But now @florence-crl and @erikgrinaker have discovered another way to upsert the same row multiple times in a single statement: using CTEs.
For example:
Now, another execution of the last statement fails with a dupe key error (confusingly on a non-unique secondary index, but this is because the PK values are also the same, so it is a duplicate key from KV's perspective):
And furthermore we can see the inconsistency directly:
Jira issue: CRDB-10192