MDEV-39620: Incorrect error message when dropping a column with a combined unique index#5172
MDEV-39620: Incorrect error message when dropping a column with a combined unique index#5172pranavktiwari wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the error handling when attempting to drop a column or key that is part of an index. In sql/sql_table.cc, the error code has been changed from ER_KEY_COLUMN_DOES_NOT_EXIST to ER_CANT_DROP_FIELD_OR_KEY, providing a more descriptive message. The corresponding test files and expected results in mysql-test/main/ have been updated to match this new behavior. There are no review comments to evaluate, and I have no additional feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
b5a0351 to
5934c54
Compare
…bined unique index Problem: Dropping a column that is part of a composite unique index returns the misleading error ER_KEY_COLUMN_DOES_NOT_EXIST, suggesting that the column is missing even though it exists in the table. Cause: During ALTER TABLE ... DROP COLUMN, the server validates the resulting index definitions after removing the column. If an index still references the dropped column, the validation reports ER_KEY_COLUMN_DOES_NOT_EXIST, which reflects the intermediate table definition rather than the actual reason for the failure. Fix: Replace ER_KEY_COLUMN_DOES_NOT_EXIST with ER_CANT_DROP_FIELD_OR_KEY and include a message indicating that the column cannot be dropped because it is part of an index, making the reported error more descriptive for users.
6265a65 to
f970dd1
Compare
There was a problem hiding this comment.
Pull request overview
This PR addresses MDEV-39620 by changing the server error surfaced during ALTER TABLE ... DROP COLUMN when the column is still referenced by a (composite) index, and updates MTR expectations accordingly.
Changes:
- Updates
mysql_prepare_alter_table()to emitER_CANT_DROP_FIELD_OR_KEYinstead ofER_KEY_COLUMN_DOES_NOT_EXISTfor a dropped column that is still referenced by a unique/primary index. - Adjusts multiple mysql-test suites to expect the new error code and message output.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sql/sql_table.cc | Changes the emitted error when an index still references a dropped column. |
| mysql-test/suite/versioning/t/alter.test | Updates expected error code for DROP COLUMN cases involving indexes. |
| mysql-test/suite/versioning/r/alter.result | Updates expected error output text for those cases. |
| mysql-test/suite/innodb/t/innodb-table-online.test | Updates expected error code for an online ALTER scenario. |
| mysql-test/suite/innodb/t/innodb-index.test | Updates expected error code in several DROP COLUMN/index scenarios. |
| mysql-test/suite/innodb/r/innodb-table-online.result | Updates expected error output text. |
| mysql-test/suite/innodb/r/innodb-index.result | Updates expected error output text in several scenarios. |
| mysql-test/main/long_unique_bugs.test | Updates expected error code for a long-unique/index DROP COLUMN case. |
| mysql-test/main/long_unique_bugs.result | Updates expected error output text. |
| mysql-test/main/alter_table.test | Updates expected error code for a DROP COLUMN + composite unique index case. |
| mysql-test/main/alter_table.result | Updates expected error output text. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
why existing tests was changed? Also test fails looks related to the changes of existing tests |
fixes MDEV-39620
Problem:
Dropping a column that is part of a composite unique index returns the
misleading error
ER_KEY_COLUMN_DOES_NOT_EXIST, suggesting that thecolumn is missing even though it exists in the table.
Cause:
During
ALTER TABLE ... DROP COLUMN, the server validates the resultingindex definitions after removing the column. If an index still references
the dropped column, the validation reports
ER_KEY_COLUMN_DOES_NOT_EXIST,which reflects the intermediate table definition rather than the actual
reason for the failure.
Fix:
Replace
ER_KEY_COLUMN_DOES_NOT_EXISTwithER_CANT_DROP_FIELD_OR_KEYand include a message indicating that thecolumn cannot be dropped because it is part of an index, making the
reported error more descriptive for users.