Details
-
Bug
-
Status: Confirmed (View Workflow)
-
Minor
-
Resolution: Unresolved
-
10.11, 11.4, 11.8, 12.3, 13.1, 12.3.3
-
Linux x86_64
Description
When an INPLACE ALTER TABLE ... DROP COLUMN is rejected because the column is referenced by a foreign key, error 1829 reports an internal database/table identifier instead of the SQL-visible constraint name. The statement-local foreign_key_checks=0 override is required to reach this diagnostic path and does not change the global setting.
Steps to reproduce
1. Save the following as setup.sql:
CREATE DATABASE diag; |
USE diag; |
CREATE TABLE parent ( |
id INT PRIMARY KEY, ref INT UNIQUE |
) ENGINE=InnoDB;
|
CREATE TABLE child ( |
id INT PRIMARY KEY, ref INT, |
CONSTRAINT fk_ref FOREIGN KEY (ref) |
REFERENCES parent(ref) |
) ENGINE=InnoDB;
|
2. Save the COPY operation as copy.sql:
USE diag; |
SET STATEMENT foreign_key_checks=0 FOR |
ALTER TABLE parent DROP COLUMN ref, ALGORITHM=COPY; |
3. Save the equivalent INPLACE operation as inplace.sql:
USE diag; |
SET STATEMENT foreign_key_checks=0 FOR |
ALTER TABLE parent DROP COLUMN ref, ALGORITHM=INPLACE; |
4. Save the metadata check as metadata.sql:
SELECT TABLE_NAME, COLUMN_NAME FROM information_schema.COLUMNS |
WHERE TABLE_SCHEMA='diag' |
ORDER BY TABLE_NAME, ORDINAL_POSITION; |
SELECT TABLE_NAME, CONSTRAINT_NAME FROM information_schema.REFERENTIAL_CONSTRAINTS |
WHERE CONSTRAINT_SCHEMA='diag'; |
5. Run the files in this order, allowing the two expected ALTER errors before continuing to the metadata query:
mariadb --batch --raw < setup.sql
|
mariadb --batch --raw < copy.sql
|
mariadb --batch --raw < inplace.sql
|
mariadb --batch --raw < metadata.sql
|
Actual result
The COPY operation returns error 1829 and correctly names the declared constraint:
ERROR 1829 (HY000): Cannot drop column 'ref': needed in a foreign key constraint 'fk_ref' of table `diag`.`child`
|
The subsequent INPLACE operation returns the same error, but identifies the constraint as the internal diag/child value:
ERROR 1829 (HY000): Cannot drop column 'ref': needed in a foreign key constraint 'diag/child' of table `diag`.`child`
|
The failed operations leave all four columns and the foreign-key metadata intact:
TABLE_NAME COLUMN_NAME
|
child id
|
child ref
|
parent id
|
parent ref
|
TABLE_NAME CONSTRAINT_NAME
|
child fk_ref
|
Expected result
Both algorithms should reject the operation with error 1829 naming the SQL-visible constraint fk_ref. The observed problem is limited to the INPLACE diagnostic identity; the evidence does not show a loss of data or foreign-key enforcement.
This occurs when an INPLACE column drop reaches the foreign-key dependency diagnostic under a statement-local foreign-key-checks override.