[MDEV-31796] Phantom Keys Created: 2023-07-29 Updated: 2023-07-29 Resolved: 2023-07-29 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Data Definition - Alter Table, Data Definition - Create Table |
| Affects Version/s: | 11.0.2 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Marcos Ramos | Assignee: | Unassigned |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | CONSTRAINT, UNIQUE, foreign-keys, primary_key | ||
| Environment: |
Arch-based Linux |
||
| Description |
|
There is a primary key that I cannot drop, and a unique key that I cannot see. Describe Table
Cannot drop Primary Key
A total mess
I can see what shouldn't be there and I cannot see what should be there. I also cannot interact with what shouldn't be there. I have tried recreating the primary key and dropping it, but it didn't work. |
| Comments |
| Comment by Elena Stepanova [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Please paste the output of SHOW CREATE TABLE Languages. | |||||||||||||||||||||||||||||||||
| Comment by Marcos Ramos [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
This made me realize, that the CHASTER and COLLATE values were different from the rest of my database. I have corrected that, but the bug persists. Actually, this is happening with every constraint I create be it UNIQUE, PRIMARY or FOREIGN. If I create them and delete them, they stay as phantom constraints in the description of a table. | |||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Right. So, from SHOW CREATE above it is hopefully obvious what is happening. When you query information_schema.table_constraints, you get information about this key. The way the attribute is set is described both in MariaDB KB and MySQL manual. The relevant part there is
But
If you drop all unique keys from the table and a column is still shown as PRI or UNI in the DESCRIBE output, it is surely a problem. Can you paste an unabridged client output of it happening? | |||||||||||||||||||||||||||||||||
| Comment by Marcos Ramos [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Right, that matches now. Thank you! And I have tried dropping it, and then the fields clear.
But the description of 'Pupils' still shows that a foreign key is there for 'Learning' that is not really listed as a constrain for this table.
| |||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Yes, as you can see from the same pages above, foreign keys don't play any role in defining the key attribute for a column. It is a different type of constraint altogether. | |||||||||||||||||||||||||||||||||
| Comment by Marcos Ramos [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Right, but in this case, they key attribute 'MUL' stays even though there is nothing that would justify its presence. Am I understanding the situation correctly? And it prevents me from creating a constraint that would justify its presence. And I have to manually drop the index. This is despite the fact that the trigger for creating the index is creating the foreign key. I think this was automatic in previous versions of MariaDB. I never saw myself having to do this before. | |||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
The problem is, that metadata flags are wrong. Flags contain PRI (mary) key, if a primary key was previously defined and replaced by a unique key (also happens with MySQL):
| |||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2023-07-29 ] | |||||||||||||||||||||||||||||||||
|
Once again, same quote from the same manual.
Your t1 doesn't have a primary key, has a unique key on a, and a is a non-null column, so it fits the description above, thus PRI. |