Skip to content
/ server Public

MDEV-33814 Wrong error message "Can't create table" on "ALTER TABLE"#4712

Open
a18792721831 wants to merge 1 commit intoMariaDB:10.6from
a18792721831:mdev-33814-alter-table-error-message
Open

MDEV-33814 Wrong error message "Can't create table" on "ALTER TABLE"#4712
a18792721831 wants to merge 1 commit intoMariaDB:10.6from
a18792721831:mdev-33814-alter-table-error-message

Conversation

@a18792721831
Copy link

When ALTER TABLE fails (e.g., due to foreign key constraint errors),
the error message incorrectly says "Can't create table" instead of
"Can't alter table". This is because ha_create_table() is shared by
both CREATE TABLE and ALTER TABLE (copy method).

Fix: Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish ALTER TABLE from CREATE TABLE, and use my_printf_error()
to report "Can't alter table" with the same error code (1005) for
backward compatibility.

All modified test cases pass:

  • innodb.alter_table_error_message (new regression test)
  • innodb.foreign_key
  • innodb.fk_col_alter
  • innodb.innodb-fk
  • innodb.innodb-fk-warnings

@CLAassistant
Copy link

CLAassistant commented Feb 28, 2026

CLA assistant check
All committers have signed the CLA.

@a18792721831 a18792721831 force-pushed the mdev-33814-alter-table-error-message branch 2 times, most recently from 952a605 to 6de3de8 Compare February 28, 2026 09:10
@grooverdan
Copy link
Member

few more tests still to re-record/update.

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 2, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! This is a preliminary review.

The commit message is somewhat misleading: HA_CREATE_TMP_ALTER is not how you distinguish between ANY ALTER TABLE and CREATE TABLE: It's how you distinguish between ALTER TABLE that creates a table before it does something more with the new table and generic CREATE TABLE.

I'd rephrase a bit. Instead of:

Fix: Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish ALTER TABLE from CREATE TABLE

I'd say:

Fix Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish between top level CREATE TABLE and CREATE TABLE executed internally by ALTER TABLE.

@@ -41,12 +41,12 @@ ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=IN
ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1'
Copy link
Member

Choose a reason for hiding this comment

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

there's more tests to re-record. Please check the buldbot: it must be clean

@a18792721831 a18792721831 force-pushed the mdev-33814-alter-table-error-message branch from 6de3de8 to b3e87bf Compare March 3, 2026 11:58
@a18792721831
Copy link
Author

Thank you for your contribution! This is a preliminary review.

The commit message is somewhat misleading: HA_CREATE_TMP_ALTER is not how you distinguish between ANY ALTER TABLE and CREATE TABLE: It's how you distinguish between ALTER TABLE that creates a table before it does something more with the new table and generic CREATE TABLE.

I'd rephrase a bit. Instead of:

Fix: Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish ALTER TABLE from CREATE TABLE

I'd say:

Fix Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish between top level CREATE TABLE and CREATE TABLE executed internally by ALTER TABLE.

Thank you for the review and the correction on the commit message!

I've updated the commit message as you suggested, and also re-recorded all the affected test result files that were failing in the buildbot. The updated commit now includes changes to 22 files in total.

Please let me know if there's anything else that needs to be addressed.

When ALTER TABLE fails (e.g., due to foreign key constraint errors),
the error message incorrectly says "Can't create table" instead of
"Can't alter table". This is because ha_create_table() is shared by
both top level CREATE TABLE and CREATE TABLE executed internally by
ALTER TABLE.

Fix: Check HA_CREATE_TMP_ALTER flag in create_info->options to
distinguish between top level CREATE TABLE and CREATE TABLE executed
internally by ALTER TABLE, and use my_printf_error() to report
"Can't alter table" with the same error code (1005) for backward
compatibility.
@a18792721831 a18792721831 force-pushed the mdev-33814-alter-table-error-message branch from b3e87bf to 6217f0d Compare March 4, 2026 03:13
my_error(ER_CANT_CREATE_TABLE, MYF(0), db, table_name, error);
{
if (create_info->options & HA_CREATE_TMP_ALTER)
my_printf_error(ER_CANT_CREATE_TABLE,
Copy link
Member

Choose a reason for hiding this comment

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

Just a thought, should we add ER_CANT_ALTER_TABLE HY000 in sql/share/errmsg-utf8.txt with the same error number HY000 as ER_CANT_CREATE_TABLE so translations can be added? Then this becomes a similar looking to the else clause.

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

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

4 participants