Skip to content

MDEV-39620: Incorrect error message when dropping a column with a combined unique index#5172

Open
pranavktiwari wants to merge 1 commit into
10.11from
10.11-MDEV-39620
Open

MDEV-39620: Incorrect error message when dropping a column with a combined unique index#5172
pranavktiwari wants to merge 1 commit into
10.11from
10.11-MDEV-39620

Conversation

@pranavktiwari

@pranavktiwari pranavktiwari commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

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 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

…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.
@pranavktiwari
pranavktiwari requested a review from Copilot July 21, 2026 09:08
@pranavktiwari pranavktiwari changed the title 10.11 mdev 39620 MDEV-39620: Incorrect error message when dropping a column with a combined unique index Jul 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 emit ER_CANT_DROP_FIELD_OR_KEY instead of ER_KEY_COLUMN_DOES_NOT_EXIST for 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.

Comment thread sql/sql_table.cc
@sanja-byelkin

Copy link
Copy Markdown
Member

why existing tests was changed?

Also test fails looks related to the changes of existing tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants