[MDEV-27012] Server crash or assertion failure after adding a unique key on a blob Created: 2021-11-09  Updated: 2021-12-27  Resolved: 2021-12-27

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table
Affects Version/s: 10.4, 10.5, 10.6
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Elena Stepanova Assignee: Aleksey Midenkov
Resolution: Duplicate Votes: 0
Labels: affects-tests, regression

Issue Links:
Duplicate
duplicates MDEV-27244 Table corruption upon adding serial d... Closed

 Description   

I'm not sure why such an ugly way of adding a unique key is required (via a SERIAL column – while the column isn't added since it already exists, the unique key is); but adding just a unique key directly doesn't cause the same effect.

--source include/have_innodb.inc
 
CREATE TABLE t1 (pk INT PRIMARY KEY, a VARCHAR(150), b TEXT, KEY(a(64))) ENGINE=InnoDB;
ALTER TABLE t1 ADD IF NOT EXISTS b SERIAL, ORDER BY b;
ALTER TABLE t1 FORCE;
 
# Cleanup
DROP TABLE t1;

10.4 04ad98b5 debug

mysqld: /data/src/10.4/sql/table.cc:9234: void setup_keyinfo_hash(KEY*): Assertion `key_info->key_part->field->flags & (1<< 30)' failed.
211109 19:19:56 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f0c4368bf36 in __GI___assert_fail (assertion=0x55d04488e7e8 "key_info->key_part->field->flags & (1<< 30)", file=0x55d04488b060 "/data/src/10.4/sql/table.cc", line=9234, function=0x55d04488e784 "void setup_keyinfo_hash(KEY*)") at assert.c:101
#8  0x000055d043c9128b in setup_keyinfo_hash (key_info=0x7f0bec096028) at /data/src/10.4/sql/table.cc:9234
#9  0x000055d043c40559 in mysql_prepare_alter_table (thd=0x7f0bec000d90, table=0x7f0bec192c60, create_info=0x7f0c3c7052b0, alter_info=0x7f0c3c7051f0, alter_ctx=0x7f0c3c7046b0) at /data/src/10.4/sql/sql_table.cc:8531
#10 0x000055d043c44b4d in mysql_alter_table (thd=0x7f0bec000d90, new_db=0x7f0bec005568, new_name=0x7f0bec005990, create_info=0x7f0c3c7052b0, table_list=0x7f0bec014868, alter_info=0x7f0c3c7051f0, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:9970
#11 0x000055d043ce0752 in Sql_cmd_alter_table::execute (this=0x7f0bec014f38, thd=0x7f0bec000d90) at /data/src/10.4/sql/sql_alter.cc:520
#12 0x000055d043b544a9 in mysql_execute_command (thd=0x7f0bec000d90) at /data/src/10.4/sql/sql_parse.cc:6192
#13 0x000055d043b59897 in mysql_parse (thd=0x7f0bec000d90, rawbuf=0x7f0bec014798 "ALTER TABLE t1 FORCE", length=20, parser_state=0x7f0c3c7064d0, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7995
#14 0x000055d043b45b9f in dispatch_command (command=COM_QUERY, thd=0x7f0bec000d90, packet=0x7f0bec00abf1 "ALTER TABLE t1 FORCE", packet_length=20, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1857
#15 0x000055d043b44405 in do_command (thd=0x7f0bec000d90) at /data/src/10.4/sql/sql_parse.cc:1373
#16 0x000055d043cd6ee4 in do_handle_one_connection (connect=0x55d0468de070) at /data/src/10.4/sql/sql_connect.cc:1420
#17 0x000055d043cd6b7d in handle_one_connection (arg=0x55d0468de070) at /data/src/10.4/sql/sql_connect.cc:1316
#18 0x000055d04420abf4 in pfs_spawn_thread (arg=0x55d04682a790) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#19 0x00007f0c43ba4609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#20 0x00007f0c43777293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

10.4 04ad98b5 non-debug

#3  <signal handler called>
#4  0x00005589ea635482 in fields_in_hash_keyinfo (keyinfo=keyinfo@entry=0x7f59f812d410) at /data/src/10.4/sql/item.h:2694
#5  0x00005589ea6354a5 in setup_keyinfo_hash (key_info=key_info@entry=0x7f59f812d410) at /data/src/10.4/sql/table.cc:9235
#6  0x00005589ea60027f in mysql_prepare_alter_table (thd=<optimized out>, table=<optimized out>, create_info=<optimized out>, alter_info=<optimized out>, alter_ctx=<optimized out>) at /data/src/10.4/sql/sql_table.cc:8531
#7  0x00005589ea606a0c in mysql_alter_table (thd=thd@entry=0x7f59f8000c48, new_db=new_db@entry=0x7f59f8005260, new_name=new_name@entry=0x7f59f8005688, create_info=create_info@entry=0x7f5a463062a0, table_list=<optimized out>, table_list@entry=0x7f59f8010180, alter_info=alter_info@entry=0x7f5a463061e0, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:9970
#8  0x00005589ea661def in Sql_cmd_alter_table::execute (this=<optimized out>, thd=0x7f59f8000c48) at /data/src/10.4/sql/sql_alter.cc:520
#9  0x00005589ea55cc60 in mysql_execute_command (thd=0x7f59f8000c48) at /data/src/10.4/sql/sql_parse.cc:6192
#10 0x00005589ea563f43 in mysql_parse (thd=0x7f59f8000c48, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /data/src/10.4/sql/sql_parse.cc:7995
#11 0x00005589ea56661d in dispatch_command (command=COM_QUERY, thd=0x7f59f8000c48, packet=<optimized out>, packet_length=<optimized out>, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /data/src/10.4/sql/sql_class.h:1201
#12 0x00005589ea568cb0 in do_command (thd=0x7f59f8000c48) at /data/src/10.4/sql/sql_parse.cc:1373
#13 0x00005589ea65d87e in do_handle_one_connection (connect=connect@entry=0x5589ed9950d8) at /data/src/10.4/sql/sql_connect.cc:1420
#14 0x00005589ea65d9af in handle_one_connection (arg=arg@entry=0x5589ed9950d8) at /data/src/10.4/sql/sql_connect.cc:1316
#15 0x00005589ea9f2686 in pfs_spawn_thread (arg=0x5589ed6c4568) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#16 0x00007f5a517d9609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#17 0x00007f5a513c7293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The failures appeared in 10.4 after the merge from 10.3

commit 47ab793d71f2755b026672e4657174a1740b6ae2 (HEAD)
Merge: de2fa9eced7 524b4a89da3
Author: Marko Mäkelä
Date:   Tue Nov 9 08:40:14 2021 +0200
 
    Merge 10.3 into 10.4

but given that 10.3 doesn't have unique blobs, it doesn't fail there.



 Comments   
Comment by Elena Stepanova [ 2021-11-09 ]

Here are a couple of other ones, the stack traces are different, but the test cases are too similar to suspect that they can be a separate issue.

--source include/have_innodb.inc
 
CREATE TABLE t (a INT, b INT, f TEXT DEFAULT '', KEY (a), KEY (b)) ENGINE=InnoDB;
INSERT INTO t (f) VALUES ('foo');
ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT;
 
# Cleanup
DROP TABLE t;

10.4 04ad98b5

#3  <signal handler called>
#4  0x0000564a880f1f26 in key_copy (to_key=0x7f8b76352ea2 "", from_record=0x7f8b2005afc0 "\363", key_info=0x7f8b2005be50, key_length=6, with_zerofill=false) at /data/src/10.4/sql/key.cc:159
#5  0x0000564a87fd8407 in check_duplicate_long_entry_key (table=0x7f8b20063fc0, h=0x7f8b2005b418, new_rec=0x7f8b2005afc0 "\363", key_no=2) at /data/src/10.4/sql/handler.cc:6606
#6  0x0000564a87fd8ba3 in check_duplicate_long_entries (table=0x7f8b20063fc0, h=0x7f8b2005b418, new_rec=0x7f8b2005afc0 "\363") at /data/src/10.4/sql/handler.cc:6688
#7  0x0000564a87fd8ef2 in handler::ha_write_row (this=0x7f8b2005b418, buf=0x7f8b2005afc0 "\363") at /data/src/10.4/sql/handler.cc:6768
#8  0x0000564a87d80ec7 in copy_data_between_tables (thd=0x7f8b20000d90, from=0x7f8b20043f40, to=0x7f8b20063fc0, create=..., ignore=false, order_num=0, order=0x0, copied=0x7f8b76353c38, deleted=0x7f8b76353c40, keys_onoff=Alter_info::LEAVE_AS_IS, alter_ctx=0x7f8b763556b0) at /data/src/10.4/sql/sql_table.cc:10972
#9  0x0000564a87d7ed27 in mysql_alter_table (thd=0x7f8b20000d90, new_db=0x7f8b20005568, new_name=0x7f8b20005990, create_info=0x7f8b763562b0, table_list=0x7f8b200148c8, alter_info=0x7f8b763561f0, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:10392
#10 0x0000564a87e19752 in Sql_cmd_alter_table::execute (this=0x7f8b200152a0, thd=0x7f8b20000d90) at /data/src/10.4/sql/sql_alter.cc:520
#11 0x0000564a87c8d4a9 in mysql_execute_command (thd=0x7f8b20000d90) at /data/src/10.4/sql/sql_parse.cc:6192
#12 0x0000564a87c92897 in mysql_parse (thd=0x7f8b20000d90, rawbuf=0x7f8b20014798 "ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT", length=67, parser_state=0x7f8b763574d0, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7995
#13 0x0000564a87c7eb9f in dispatch_command (command=COM_QUERY, thd=0x7f8b20000d90, packet=0x7f8b2000abf1 "ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT", packet_length=67, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1857
#14 0x0000564a87c7d405 in do_command (thd=0x7f8b20000d90) at /data/src/10.4/sql/sql_parse.cc:1373
#15 0x0000564a87e0fee4 in do_handle_one_connection (connect=0x564a8b8e1150) at /data/src/10.4/sql/sql_connect.cc:1420
#16 0x0000564a87e0fb7d in handle_one_connection (arg=0x564a8b8e1150) at /data/src/10.4/sql/sql_connect.cc:1316
#17 0x0000564a88343bf4 in pfs_spawn_thread (arg=0x564a8b8d37b0) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#18 0x00007f8b81808609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#19 0x00007f8b813db293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

--source include/have_innodb.inc
 
CREATE TABLE t (a INT, b INT, f TEXT, KEY (a), KEY (b)) ENGINE=InnoDB;
INSERT INTO t (f) VALUES ('foo');
ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT;
 
# Cleanup
DROP TABLE t;

#3  <signal handler called>
#4  0x000055d612f43002 in Type_handler_hybrid_field_type::set_handler (this=0x120, other=0x55d614601d40 <type_handler_double>) at /data/src/10.4/sql/sql_type.h:6650
#5  0x000055d6134780e1 in Item_sum_sum::fix_length_and_dec_double (this=0x0) at /data/src/10.4/sql/item_sum.cc:1533
#6  0x000055d61326007a in Type_handler_string_result::Item_sum_sum_fix_length_and_dec (this=0x55d614601cf0 <type_handler_null>, item=0x0) at /data/src/10.4/sql/sql_type.cc:4478
#7  0x000055d61349ef32 in key_copy (to_key=0x7fc9ce961ea2 "", from_record=0x7fc984062c10 "\363", key_info=0x7fc9840632b0, key_length=6, with_zerofill=false) at /data/src/10.4/sql/key.cc:159
#8  0x000055d613385407 in check_duplicate_long_entry_key (table=0x7fc98405a3b0, h=0x7fc98405b218, new_rec=0x7fc984062c10 "\363", key_no=2) at /data/src/10.4/sql/handler.cc:6606
#9  0x000055d613385ba3 in check_duplicate_long_entries (table=0x7fc98405a3b0, h=0x7fc98405b218, new_rec=0x7fc984062c10 "\363") at /data/src/10.4/sql/handler.cc:6688
#10 0x000055d613385ef2 in handler::ha_write_row (this=0x7fc98405b218, buf=0x7fc984062c10 "\363") at /data/src/10.4/sql/handler.cc:6768
#11 0x000055d61312dec7 in copy_data_between_tables (thd=0x7fc984000d90, from=0x7fc984041e10, to=0x7fc98405a3b0, create=..., ignore=false, order_num=0, order=0x0, copied=0x7fc9ce962c38, deleted=0x7fc9ce962c40, keys_onoff=Alter_info::LEAVE_AS_IS, alter_ctx=0x7fc9ce9646b0) at /data/src/10.4/sql/sql_table.cc:10972
#12 0x000055d61312bd27 in mysql_alter_table (thd=0x7fc984000d90, new_db=0x7fc984005568, new_name=0x7fc984005990, create_info=0x7fc9ce9652b0, table_list=0x7fc9840148c8, alter_info=0x7fc9ce9651f0, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:10392
#13 0x000055d6131c6752 in Sql_cmd_alter_table::execute (this=0x7fc9840152a0, thd=0x7fc984000d90) at /data/src/10.4/sql/sql_alter.cc:520
#14 0x000055d61303a4a9 in mysql_execute_command (thd=0x7fc984000d90) at /data/src/10.4/sql/sql_parse.cc:6192
#15 0x000055d61303f897 in mysql_parse (thd=0x7fc984000d90, rawbuf=0x7fc984014798 "ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT", length=67, parser_state=0x7fc9ce9664d0, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7995
#16 0x000055d61302bb9f in dispatch_command (command=COM_QUERY, thd=0x7fc984000d90, packet=0x7fc98400abf1 "ALTER TABLE t ADD IF NOT EXISTS f SERIAL, CHANGE IF EXISTS x xx INT", packet_length=67, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1857
#17 0x000055d61302a405 in do_command (thd=0x7fc984000d90) at /data/src/10.4/sql/sql_parse.cc:1373
#18 0x000055d6131bcee4 in do_handle_one_connection (connect=0x55d61590ff60) at /data/src/10.4/sql/sql_connect.cc:1420
#19 0x000055d6131bcb7d in handle_one_connection (arg=0x55d61590ff60) at /data/src/10.4/sql/sql_connect.cc:1316
#20 0x000055d6136f0bf4 in pfs_spawn_thread (arg=0x55d6159025c0) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#21 0x00007fc9d9e1a609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#22 0x00007fc9d99ed293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Comment by Elena Stepanova [ 2021-12-10 ]

Here is another one, happens on intermediate test cases, but very easily changes to one of the above (usually to the crash in check_duplicate_long_entry_key). Since it's surely related, I won't create a clean test case, but will record it for the sake of JIRA search.

10.4 5e814881

2021-12-10 04:08:16 0x7fb0654cd700  InnoDB: Assertion failure in file /data/src/10.4/storage/innobase/row/row0sel.cc line 2629
InnoDB: Failing assertion: field->prefix_len > 0
 
#6  0x000055bd74bde055 in ut_dbg_assertion_failed (expr=0x55bd752276e7 "field->prefix_len > 0", file=0x55bd75226988 "/data/src/10.4/storage/innobase/row/row0sel.cc", line=2629) at /data/src/10.4/storage/innobase/ut/ut0dbg.cc:60
#7  0x000055bd74b4609c in row_sel_convert_mysql_key_to_innobase (tuple=0x7fb00c0b6ad0, buf=0x7fb00c0b68d8 "", buf_len=12, index=0x7fb00c08e8a0, key_ptr=0x7fb0654c7e9f "", key_len=3) at /data/src/10.4/storage/innobase/row/row0sel.cc:2629
#8  0x000055bd749526a0 in ha_innobase::index_read (this=0x7fb00c0a0d78, buf=0x7fb00c0a1568 "\033", key_ptr=0x7fb0654c7e9f "", key_len=3, find_flag=HA_READ_KEY_EXACT) at /data/src/10.4/storage/innobase/handler/ha_innodb.cc:9310
#9  0x000055bd745776b2 in handler::index_read_map (this=0x7fb00c0a0d78, buf=0x7fb00c0a1568 "\033", key=0x7fb0654c7e9f "", keypart_map=18446744073709551615, find_flag=HA_READ_KEY_EXACT) at /data/src/10.4/sql/handler.h:3662
#10 0x000055bd7456703d in handler::ha_index_read_map (this=0x7fb00c0a0d78, buf=0x7fb00c0a1568 "\033", key=0x7fb0654c7e9f "", keypart_map=18446744073709551615, find_flag=HA_READ_KEY_EXACT) at /data/src/10.4/sql/handler.cc:2937
#11 0x000055bd74571d1a in check_duplicate_long_entry_key (table=0x7fb00c0a9060, h=0x7fb00c0a0d78, new_rec=0x7fb00c0a1568 "\033", key_no=7) at /data/src/10.4/sql/handler.cc:6616
#12 0x000055bd745723e7 in check_duplicate_long_entries (table=0x7fb00c0a9060, h=0x7fb00c0a0d78, new_rec=0x7fb00c0a1568 "\033") at /data/src/10.4/sql/handler.cc:6688
#13 0x000055bd74572736 in handler::ha_write_row (this=0x7fb00c0a0d78, buf=0x7fb00c0a1568 "\033") at /data/src/10.4/sql/handler.cc:6768
#14 0x000055bd7431a476 in copy_data_between_tables (thd=0x7fb00c000d90, from=0x7fb00c0a4c50, to=0x7fb00c0a9060, create=..., ignore=false, order_num=2, order=0x7fb00c017540, copied=0x7fb0654c8c38, deleted=0x7fb0654c8c40, keys_onoff=Alter_info::LEAVE_AS_IS, alter_ctx=0x7fb0654ca6b0) at /data/src/10.4/sql/sql_table.cc:10973
#15 0x000055bd743182d6 in mysql_alter_table (thd=0x7fb00c000d90, new_db=0x7fb00c005568, new_name=0x7fb00c005990, create_info=0x7fb0654cb2b0, table_list=0x7fb00c016b70, alter_info=0x7fb0654cb1f0, order_num=2, order=0x7fb00c017540, ignore=false) at /data/src/10.4/sql/sql_table.cc:10393
#16 0x000055bd743b2d0c in Sql_cmd_alter_table::execute (this=0x7fb00c017708, thd=0x7fb00c000d90) at /data/src/10.4/sql/sql_alter.cc:520
#17 0x000055bd742267ee in mysql_execute_command (thd=0x7fb00c000d90) at /data/src/10.4/sql/sql_parse.cc:6192
#18 0x000055bd7422bbdb in mysql_parse (thd=0x7fb00c000d90, rawbuf=0x7fb00c0169d8 "ALTER TABLE t9_InnoDB /*!100301 */ MODIFY COLUMN IF EXISTS u BLOB DEFAULT 'z', LOCK=DEFAULT, ORDER BY l, col_int", length=112, parser_state=0x7fb0654cc4d0, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7995
#19 0x000055bd74217edf in dispatch_command (command=COM_QUERY, thd=0x7fb00c000d90, packet=0x7fb00c00abf1 "", packet_length=112, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1857
#20 0x000055bd74216745 in do_command (thd=0x7fb00c000d90) at /data/src/10.4/sql/sql_parse.cc:1373
#21 0x000055bd743a949e in do_handle_one_connection (connect=0x55bd76c785d0) at /data/src/10.4/sql/sql_connect.cc:1420
#22 0x000055bd743a9137 in handle_one_connection (arg=0x55bd76c785d0) at /data/src/10.4/sql/sql_connect.cc:1316
#23 0x000055bd748dd552 in pfs_spawn_thread (arg=0x55bd76c6aaa0) at /data/src/10.4/storage/perfschema/pfs.cc:1869
#24 0x00007fb06c96a609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#25 0x00007fb06c53d293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Generated at Thu Feb 08 09:49:39 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.