-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sql: the updated values on ON CONFLICT do not get constraint-checked properly #23699
Labels
A-sql-mutations
Mutation statements: UPDATE/INSERT/UPSERT/DELETE.
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
docs-done
docs-known-limitation
S-0-visible-logical-error
Database stores inconsistent data in some cases, or queries return invalid results silently.
Milestone
Comments
knz
added
the
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
label
Mar 10, 2018
cc @BramGruneir should see if this is an issue with FKs too. |
I checked - FKs do get checked properly, they use a different code path (in the RowInserter/RowUpdater from sqlbase) which is properly run in this case. |
Thanks!. Let's make sure we get test coverage though all the same, as this is a really easy mutation path to overlook. |
Documented as a known limitation in cockroachdb/docs#2823. |
knz
added
S-0-corruption-or-data-loss
Unrecoverable corruption, data loss, or other catastrophic issues that can’t be fixed by upgrading.
backport-2.0.x
labels
Apr 24, 2018
knz
added
S-0-visible-logical-error
Database stores inconsistent data in some cases, or queries return invalid results silently.
and removed
S-0-corruption-or-data-loss
Unrecoverable corruption, data loss, or other catastrophic issues that can’t be fixed by upgrading.
labels
Apr 29, 2018
craig bot
pushed a commit
that referenced
this issue
Jun 13, 2018
26642: sql: Check CHECK constraints on upsert when updating a conflicting row r=emsal1863 a=emsal1863 * Before: On a table with a CHECK constraint, such as: ``` CREATE TABLE ex(foo INT PRIMARY KEY, bar INT, CHECK (bar < 2) ``` an upsert on the table would not properly check the CHECK constraints, e.g. ``` INSERT INTO ex(foo, bar) VALUES(1, 2); INSERT INTO ex(foo, bar) VALUES(1, 2) ON CONFLICT (foo) DO UPDATE SET bar = 3 ``` would update the row, violating the check constraint. * After: On attempting such an operation, CockroachDB now throws the proper database error "failed to satisfy CHECK constraint ..." Release note (sql change): CHECK constraints are now checked when updating a conflicting row in INSERT ... ON CONFLICT DO UPDATE statements. closes #23699 Co-authored-by: Emmanuel <[email protected]>
This was referenced Jun 13, 2018
craig bot
pushed a commit
that referenced
this issue
Jun 13, 2018
26699: release-2.0: sql: Check CHECK constraints on upsert when updating a conflicting row r=emsal1863 a=emsal1863 Backport 1/1 commits from #26642. /cc @cockroachdb/release --- * Before: On a table with a CHECK constraint, such as: ``` CREATE TABLE ex(foo INT PRIMARY KEY, bar INT, CHECK (bar < 2) ``` an upsert on the table would not properly check the CHECK constraints, e.g. ``` INSERT INTO ex(foo, bar) VALUES(1, 2); INSERT INTO ex(foo, bar) VALUES(1, 2) ON CONFLICT (foo) DO UPDATE SET bar = 3 ``` would update the row, violating the check constraint. * After: On attempting such an operation, CockroachDB now throws the proper database error "failed to satisfy CHECK constraint ..." Release note (sql change): CHECK constraints are now checked when updating a conflicting row in INSERT ... ON CONFLICT DO UPDATE statements. closes #23699 Co-authored-by: Emmanuel <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-sql-mutations
Mutation statements: UPDATE/INSERT/UPSERT/DELETE.
C-bug
Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.
docs-done
docs-known-limitation
S-0-visible-logical-error
Database stores inconsistent data in some cases, or queries return invalid results silently.
Consider the following table:
A simple INSERT statement fails, as it should:
Now, the same with INSERT ... ON CONFLICT:
This succeeds!
And results in a row that fails constraint validation:
This may or may not need to be fixed for 2.0, but certainly needs a note in docs as known limitation.
The text was updated successfully, but these errors were encountered: