[MDEV-30606] Foreign key cannot be used in the check constraint Created: 2023-02-07 Updated: 2023-11-06 Resolved: 2023-02-17 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Create Table |
| Affects Version/s: | 10.6.12, 10.10.3 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Nikola | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 2 |
| Labels: | bug, error, innodb | ||
| Environment: |
Using your docker image |
||
| Issue Links: |
|
||||||||||||||||||||||||||||||||
| Description |
|
Hi I have following code snippet, where I use a foreign key in a check constraint. This code was working with version 10.10.2, but does not anymore with 10.10.3. I checked and it still works with the latest 10.3.38.
I get the error code 1901:
Now my question is, if you have introduced a bug in your latest release or if that code snippet is something that should not be working, but was working so far unintentionally. I did not find an exact documentation if a foreign key should not be used in a check constraint. |
| Comments |
| Comment by Pieter Nys [ 2023-02-17 ] | ||||||||||||||||||||||||||||||
|
We are experiencing the same bug in our test-pipeline. When using version 10.6.11, we are able to load in our test-database. Using 10.6.12, this is no longer possible. The specific section of our database-load-script:
Our error-message:
| ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-02-17 ] | ||||||||||||||||||||||||||||||
|
This was an intentional change. If a field is a part of a foreign key with a ON UPDATE CASCADE action, it can be updated internally by InnoDB without informing the server and without validating the CHECK constraint. In other words, such cascading updates can invalidate the constraint and that's why they are not supported. It is possible to implement CHECK constrain validation on cascading updates, but this would've been too intrusive and risky change in a 10.6 GA branch | ||||||||||||||||||||||||||||||
| Comment by Valerii Kravchuk [ 2023-02-17 ] | ||||||||||||||||||||||||||||||
|
I wonder what MDEV introduced this change and why it is not mentioned in the release notes in any visible way? | ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-02-17 ] | ||||||||||||||||||||||||||||||
|
it's linked as "is caused by", but here it is again: Not listed in release notes because they only list major changes and this one was considered a minor one. Perhaps incorrectly. I can add it if you think it's worth it | ||||||||||||||||||||||||||||||
| Comment by Valerii Kravchuk [ 2023-02-17 ] | ||||||||||||||||||||||||||||||
|
But I'd appreciate more detailed information for the release notes, now that we have several users complaining. | ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-05-22 ] | ||||||||||||||||||||||||||||||
|
This change in behavior was caused by the commit https://github.com/MariaDB/server/commit/a5eff044cb85 (in 10.6.12, indeed) When working on something else I've noticed that | ||||||||||||||||||||||||||||||
| Comment by Tim Koop [ 2023-07-25 ] | ||||||||||||||||||||||||||||||
|
We were bitten by this change too. We would have appreciated reading about it in the release notes. | ||||||||||||||||||||||||||||||
| Comment by Sergei Golubchik [ 2023-11-06 ] | ||||||||||||||||||||||||||||||
|
This limitation will be removed in MDEV-22880 |