[MDEV-30788] ONLINE Add Foreign Key Created: 2023-03-04 Updated: 2023-03-06 Resolved: 2023-03-06 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Server |
| Fix Version/s: | N/A |
| Type: | Task | Priority: | Major |
| Reporter: | Nuno | Assignee: | Marko Mäkelä |
| Resolution: | Cannot Reproduce | Votes: | 0 |
| Labels: | None | ||
| Issue Links: |
|
||||||||
| Description |
|
MariaDB 10.8.7 I'm trying to add a new foreign key without any FK checks or tables locked. I tried this (with and without "GLOBAL"):
However, I get this error:
— Then I tried without "ONLINE":
However, the "main_table" gets immediately locked for many queries, with "Waiting for table metadata lock". — If I'm disabling FOREIGN_KEY_CHECKS, isn't the ALTER TABLE supposed to be performed ONLINE, without locking any tables and without checking for integrity? |
| Comments |
| Comment by Marko Mäkelä [ 2023-03-05 ] | ||||||||||||||||||||||||||||||||||||||||
|
Can you provide a complete example, starting with CREATE TABLE statements? | ||||||||||||||||||||||||||||||||||||||||
| Comment by Nuno [ 2023-03-05 ] | ||||||||||||||||||||||||||||||||||||||||
|
Hi marko - thanks much for your reply. Hopefully these are enough (unfortunately I can't provide the exact tables):
All the constraints above are already there. Now I'm trying to add a new constraint/FK on `initiator`. Thanks!! | ||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-03-06 ] | ||||||||||||||||||||||||||||||||||||||||
|
nunop, it would really help if you could provide a self-contained SQL test case. Adding a FOREIGN KEY without a table rebuild is being tested in our regression test suite, so it does work in some cases:
In your case, it does not work for some reason that is not obvious to me. The number of rows in the tables should not matter, or at most it matters that the tables contain at least 1 row. You can add explicit , ALGORITHM=INSTANT to have the operation rejected in case the table would need to be copied. | ||||||||||||||||||||||||||||||||||||||||
| Comment by Nuno [ 2023-03-06 ] | ||||||||||||||||||||||||||||||||||||||||
|
Ok marko Thanks very much for this. It appears that the problem must be with the UI I'm using, which is phpMyAdmin. I've just tried directly in the shell, and ALTER ONLINE worked without any problem, and instantly! I'll report this issue to phpMyAdmin instead Thank you very much!! Issue can be closed. | ||||||||||||||||||||||||||||||||||||||||
| Comment by Marko Mäkelä [ 2023-03-06 ] | ||||||||||||||||||||||||||||||||||||||||
|
Thank you for the clarification. |