[MDEV-16301] IB: use real table name for error messages on ALTER Created: 2018-05-26  Updated: 2019-03-04  Resolved: 2019-03-04

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - InnoDB, Versioned Tables
Fix Version/s: 10.2.22, 10.3.13

Type: Task Priority: Minor
Reporter: Aleksey Midenkov Assignee: Sergei Golubchik
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MDEV-16102 Wrong ER_DUP_ENTRY upon ADD UNIQUE KE... Closed

 Description   

Reproduce

create or replace table parent(
    id int unique key
) engine innodb;
create or replace table child(
    parent_id int,
    sys_start bigint unsigned as row start invisible,
    sys_end bigint unsigned as row end invisible,
    period for system_time(sys_start, sys_end)
) engine innodb with system versioning;
insert into child values (1);
alter table child add foreign key (parent_id) references parent (id);

Result

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-675f_8`, CONSTRAINT `#sql-675f_8_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))

Expected

Instead of temporary table name (and constraint name) it should use real one:

ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`))

Notes

SQL layer utilizes TABLE_SHARE::error_table_name() for similar purpose.

Info

1. trx->detailed_error set

++
#0  trx_set_detailed_error_from_file (trx=0x7fffef912728, file=0x29c11c0) at /home/midenok/src/mariadb/review/src/storage/innobase/trx/trx0trx.cc:109
#1  0x0000000000f09b5f in row_ins_set_detailed (trx=0x7fffef912728, foreign=0x7fff8404fe78) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:746
#2  0x0000000000f0c31e in row_ins_foreign_report_add_err (trx=0x7fffef912728, foreign=0x7fff8404fe78, rec=0x7fffe8044070 "supremum", entry=0x7fff840232f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:869
#3  0x0000000000f095c9 in row_ins_check_foreign_constraint (check_ref=1, foreign=0x7fff8404fe78, table=0x7fff8408dfd8, entry=0x7fff840232f0, thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:1876
#4  0x0000000000f129e8 in row_ins_check_foreign_constraints (table=0x7fff8408dfd8, index=0x7fff840912b8, entry=0x7fff840232f0, thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:1980
#5  0x0000000000f12c65 in row_ins_sec_index_entry (index=0x7fff840912b8, entry=0x7fff840232f0, thr=0x7fff8409a7f0, dup_chk_only=false) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:3300
#6  0x0000000000f1b291 in row_ins_index_entry (index=0x7fff840912b8, entry=0x7fff840232f0, thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:3377
#7  0x0000000000f1accf in row_ins_index_entry_step (node=0x7fff8409a558, thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:3525
#8  0x0000000000f14712 in row_ins (node=0x7fff8409a558, thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:3667
#9  0x0000000000f14305 in row_ins_step (thr=0x7fff8409a7f0) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0ins.cc:3921
#10 0x0000000000f3eceb in row_insert_for_mysql (mysql_rec=0x7fff84097be8 "\375\001", prebuilt=0x7fff84099fd8, ins_mode=ROW_INS_NORMAL) at /home/midenok/src/mariadb/review/src/storage/innobase/row/row0mysql.cc:1452
#11 0x0000000000d9bc3c in ha_innobase::write_row (this=0x7fff84094c38, record=0x7fff84097be8 "\375\001") at /home/midenok/src/mariadb/review/src/storage/innobase/handler/ha_innodb.cc:8090
#12 0x0000000000b1b274 in handler::ha_write_row (this=0x7fff84094c38, buf=0x7fff84097be8 "\375\001") at /home/midenok/src/mariadb/review/src/sql/handler.cc:6195
#13 0x00000000008c0662 in copy_data_between_tables (thd=0x7fff84000d50, from=0x7fff84081b90, to=0x7fff84096fa0, create=..., ignore=false, order_num=0, order=0x0, copied=0x7fffe52a9d20, deleted=0x7fffe52a9d18, keys_onoff=Alter_info::LEAVE_AS_IS, alter_ctx=0x7fffe52aa0b8) at /home/midenok/src/mariadb/review/src/sql/sql_table.cc:10341
#14 0x00000000008b7ddf in mysql_alter_table (thd=0x7fff84000d50, new_db=0x7fff840053d0, new_name=0x7fff84005788, create_info=0x7fffe52ab3b0, table_list=0x7fff84013af0, alter_info=0x7fffe52ab2f8, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/review/src/sql/sql_table.cc:9774
#15 0x000000000095ed98 in Sql_cmd_alter_table::execute (this=0x7fff84014350, thd=0x7fff84000d50) at /home/midenok/src/mariadb/review/src/sql/sql_alter.cc:490
#16 0x00000000007c080e in mysql_execute_command (thd=0x7fff84000d50) at /home/midenok/src/mariadb/review/src/sql/sql_parse.cc:6283
#17 0x00000000007b232f in mysql_parse (thd=0x7fff84000d50, rawbuf=0x7fff840139b8 "alter table child add foreign key (parent_id) references parent (id)", length=68, parser_state=0x7fffe52ae650, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/review/src/sql/sql_parse.cc:8020

2. trx->detailed_error accessed

++
#0  ha_innobase::get_error_message (this=0x7fff84094c38, error=151, buf=0x7fffe52a6f20) at /home/midenok/src/mariadb/review/src/storage/innobase/handler/ha_innodb.cc:16736
#1  0x0000000000b13719 in handler::print_error (this=0x7fff84094c38, error=151, errflag=0) at /home/midenok/src/mariadb/review/src/sql/handler.cc:3742
#2  0x00000000008c06e1 in copy_data_between_tables (thd=0x7fff84000d50, from=0x7fff84081b90, to=0x7fff84096fa0, create=..., ignore=false, order_num=0, order=0x0, copied=0x7fffe52a9d20, deleted=0x7fffe52a9d18, keys_onoff=Alter_info::LEAVE_AS_IS, alter_ctx=0x7fffe52aa0b8) at /home/midenok/src/mariadb/review/src/sql/sql_table.cc:10348
#3  0x00000000008b7ddf in mysql_alter_table (thd=0x7fff84000d50, new_db=0x7fff840053d0, new_name=0x7fff84005788, create_info=0x7fffe52ab3b0, table_list=0x7fff84013af0, alter_info=0x7fffe52ab2f8, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/review/src/sql/sql_table.cc:9774
#4  0x000000000095ed98 in Sql_cmd_alter_table::execute (this=0x7fff84014350, thd=0x7fff84000d50) at /home/midenok/src/mariadb/review/src/sql/sql_alter.cc:490
#5  0x00000000007c080e in mysql_execute_command (thd=0x7fff84000d50) at /home/midenok/src/mariadb/review/src/sql/sql_parse.cc:6283
#6  0x00000000007b232f in mysql_parse (thd=0x7fff84000d50, rawbuf=0x7fff840139b8 "alter table child add foreign key (parent_id) references parent (id)", length=68, parser_state=0x7fffe52ae650, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/review/src/sql/sql_parse.cc:8020


Generated at Thu Feb 08 08:27:53 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.