[MDEV-30115] Unspecified and inconsistent behavior of CHECK constraint requiring cast Created: 2022-11-28 Updated: 2023-11-28 |
|
| Status: | Confirmed |
| Project: | MariaDB Server |
| Component/s: | Data Manipulation - Insert |
| Affects Version/s: | 10.3, 10.4, 10.5, 10.6, 10.7, 10.8, 10.9, 10.10, 10.11 |
| Fix Version/s: | 10.4, 10.5, 10.6 |
| Type: | Bug | Priority: | Major |
| Reporter: | Elena Stepanova | Assignee: | Oleksandr Byelkin |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | None | ||
| Description |
|
Quite possibly it's just a documentation issue (it must be at least a documentation issue, as I can't find anything in the KB that would shed any light on it; it is not surprising as the INSERT IGNORE information in the KB is scarce even in regard to the legacy logic). However, I can't request a documentation change because I don't know what the expected behavior for CHECK constraints is. The test case is degenerate, but obviously there are more realistic paths which lead to the same problem.
"Normally" INSERT IGNORE does one of two things: either it converts the inserted values into closest valid ones (e.g. with data type mismatch), or it skips the rows which cannot be inserted (e.g. with unique constraints). But in the case above, it doesn't do either of that. Instead, it converts the literal in the check constraint to double, applies the check (with a warning) and inserts the value, which leaves the table contents invalid for further operations:
This behavior is not unique. The same would have occurred if check_constraint_checks=0 was used for INSERT instead of IGNORE, and that is documented. So, it's possible that in case of CHECK constraints INSERT IGNORE behaves this way by design. |
| Comments |
| Comment by Sergei Golubchik [ 2022-12-02 ] | |||||||||||||||||||||||||
|
I think that violating a constraint is shouldn't be done lightly, not on IGNORE. So it's a bug. The row should be ignored, with CHECK CONSTRAINT just as it is with UNIQUE CONSTRAINT | |||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2023-07-03 ] | |||||||||||||||||||||||||
|
Here is an even stranger representation of (hopefully) the same root cause.
The first INSERT fails with ER_TRUNCATED_WRONG_VALUE (ERROR 1292 (22007): Truncated incorrect DECIMAL value: '').
and the outcome is the same as in the description, an invalid table. |