[MDEV-25437] Cannot reference composite foreign key in CHECK clause Created: 2021-04-17 Updated: 2023-08-17 Resolved: 2021-04-19 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Create Table |
| Affects Version/s: | 10.5.9, 10.5 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Ludovico Pavesi | Assignee: | Sergei Golubchik |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Linux 5.11.11 |
||
| Description |
|
Trying to reference a composite foreign key in a CHECK clause fails: ERROR 1901 (HY000): Function or expression 'SomeColumn' cannot be used in the CHECK clause of `CONSTRAINT_1` For example, running MariaDB 10.5 in a container (docker run -p 127.0.0.1:3305:3306 --name test -e MYSQL_ROOT_PASSWORD=root -d mariadb:10.5) and executing this:
The CREATE TABLE `Bar` query fails with the error: ERROR 1901 (HY000): Function or expression 'SomeColumn' cannot be used in the CHECK clause of `CONSTRAINT_1` However, this worked on MariaDB 10.4. Starting another container with mariadb:10.4 and executing the same queries succeeds, both tables are created and all the constraints work as expected:
|
| Comments |
| Comment by Alice Sherepa [ 2021-04-19 ] | |||||||||||
|
Thanks for the report! I repeated as described.
| |||||||||||
| Comment by Sergei Golubchik [ 2021-04-19 ] | |||||||||||
|
This is intentional. The way MariaDB works right now (and always did) cascading updates to child tables happen on a very low level where there is no possibility of checking a CHECK constraint. That is, if you have cascading updates, they can break CHECK constraints. This is something we plan to fix — but it's a huge project. We're already working on it for a year, and it might take a few more. So for now we're not allowing CHECK constraints (and related features) when cascading updates are used. This was done in | |||||||||||
| Comment by Adrien Crivelli [ 2023-08-17 ] | |||||||||||
@Sergei Golubchik, is there an issue for that work , so that we can follow its progress ? | |||||||||||
| Comment by Sergei Golubchik [ 2023-08-17 ] | |||||||||||
|
Yes, there are two approaches to fix it. By "huge project" I meant MDEV-22361. But don't hold your breath, it'll take years. |