[MDEV-29314] Assertion `n_fields > n_cols' failed in dict_index_t::init_change_cols Created: 2022-08-16  Updated: 2022-08-24  Resolved: 2022-08-24

Status: Closed
Project: MariaDB Server
Component/s: Full-text Search, Storage Engine - InnoDB
Affects Version/s: 10.6, 10.7, 10.8, 10.9, 10.10, 10.11
Fix Version/s: 10.6.10, 10.7.6, 10.8.5, 10.9.3, 10.10.2

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Thirunarayanan Balathandayuthapani
Resolution: Fixed Votes: 0
Labels: affects-tests, regression


 Description   

--source include/have_innodb.inc
 
CREATE TABLE t (a VARCHAR(16) COLLATE utf8_bin, FULLTEXT (a)) ENGINE=InnoDB COLLATE utf8_unicode_520_ci;
ALTER TABLE t MODIFY COLUMN a VARCHAR(512);
 
# Cleanup
DROP TABLE t;

10.6 39cafb66

mariadbd: /data/src/10.6/storage/innobase/include/dict0mem.h:1348: void dict_index_t::init_change_cols(unsigned int): Assertion `n_fields > n_cols' failed.
220816 17:22:34 [ERROR] mysqld got signal 6 ;
 
#7  0x00007fa9b97e3662 in __GI___assert_fail (assertion=0x562bd1de7852 "n_fields > n_cols", file=0x562bd1de73f8 "/data/src/10.10/storage/innobase/include/dict0mem.h", line=1339, function=0x562bd1de7868 "void dict_index_t::init_change_cols(unsigned int)") at assert.c:101
#8  0x0000562bd154f4e1 in dict_index_t::init_change_cols (this=0x7fa96c11fc08, n_cols=1) at /data/src/10.10/storage/innobase/include/dict0mem.h:1339
#9  0x0000562bd155a1b4 in ha_innobase_inplace_ctx::change_col_collation (this=0x7fa96c016b40, index=0x7fa96c11fc08, altered_table=...) at /data/src/10.10/storage/innobase/handler/handler0alter.cc:1430
#10 0x0000562bd153e7b5 in prepare_inplace_alter_table_dict (ha_alter_info=0x7fa9ac5550d0, altered_table=0x7fa9ac555190, old_table=0x7fa96c042ef8, table_name=0x7fa96c22624d "t", flags=33, flags2=84, fts_doc_id_col=1, add_fts_doc_id=false, add_fts_doc_id_idx=false) at /data/src/10.10/storage/innobase/handler/handler0alter.cc:7200
#11 0x0000562bd15447d6 in ha_innobase::prepare_inplace_alter_table (this=0x7fa96c11a970, altered_table=0x7fa9ac555190, ha_alter_info=0x7fa9ac5550d0) at /data/src/10.10/storage/innobase/handler/handler0alter.cc:8492
#12 0x0000562bd1117bfa in handler::ha_prepare_inplace_alter_table (this=0x7fa96c11a970, altered_table=0x7fa9ac555190, ha_alter_info=0x7fa9ac5550d0) at /data/src/10.10/sql/handler.cc:5215
#13 0x0000562bd0e64828 in mysql_inplace_alter_table (thd=0x7fa96c000db8, table_list=0x7fa96c015570, table=0x7fa96c042ef8, altered_table=0x7fa9ac555190, ha_alter_info=0x7fa9ac5550d0, target_mdl_request=0x7fa9ac555960, ddl_log_state=0x7fa9ac555070, trigger_param=0x7fa9ac555550, alter_ctx=0x7fa9ac5564d0, partial_alter=@0x7fa9ac554f76: false, start_alter_id=@0x7fa9ac554fb0: 0, if_exists=false) at /data/src/10.10/sql/sql_table.cc:7612
#14 0x0000562bd0e6e124 in mysql_alter_table (thd=0x7fa96c000db8, new_db=0x7fa96c005a90, new_name=0x7fa96c005ea0, create_info=0x7fa9ac5572e0, table_list=0x7fa96c015570, alter_info=0x7fa9ac5571f0, order_num=0, order=0x0, ignore=false, if_exists=false) at /data/src/10.10/sql/sql_table.cc:10704
#15 0x0000562bd0f24306 in Sql_cmd_alter_table::execute (this=0x7fa96c015d80, thd=0x7fa96c000db8) at /data/src/10.10/sql/sql_alter.cc:547
#16 0x0000562bd0d4f185 in mysql_execute_command (thd=0x7fa96c000db8, is_called_from_prepared_stmt=false) at /data/src/10.10/sql/sql_parse.cc:5997
#17 0x0000562bd0d55227 in mysql_parse (thd=0x7fa96c000db8, rawbuf=0x7fa96c015470 "ALTER TABLE t MODIFY COLUMN a VARCHAR(512)", length=42, parser_state=0x7fa9ac5583c0) at /data/src/10.10/sql/sql_parse.cc:8035
#18 0x0000562bd0d41807 in dispatch_command (command=COM_QUERY, thd=0x7fa96c000db8, packet=0x7fa96c00b9f9 "ALTER TABLE t MODIFY COLUMN a VARCHAR(512)", packet_length=42, blocking=true) at /data/src/10.10/sql/sql_parse.cc:1894
#19 0x0000562bd0d40202 in do_command (thd=0x7fa96c000db8, blocking=true) at /data/src/10.10/sql/sql_parse.cc:1407
#20 0x0000562bd0f1905a in do_handle_one_connection (connect=0x562bd4c98388, put_in_cache=true) at /data/src/10.10/sql/sql_connect.cc:1418
#21 0x0000562bd0f18cf9 in handle_one_connection (arg=0x562bd4cadc08) at /data/src/10.10/sql/sql_connect.cc:1312
#22 0x0000562bd1418972 in pfs_spawn_thread (arg=0x562bd4c97ef8) at /data/src/10.10/storage/perfschema/pfs.cc:2201
#23 0x00007fa9b9cadea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
#24 0x00007fa9b98acdef in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

The failure started happening on 10.6 after this commit:

commit f8240a2723f0cad948a02fc5381f050d02e45e95
Author: Marko Mäkelä
Date:   Mon Jul 4 11:15:15 2022 +0300
 
    MDEV-26294 Duplicate entries in unique index not detected when changing collation



 Comments   
Comment by Roel Van de Paar [ 2022-08-23 ]

Also ran into this:

CREATE TABLE t (t CHAR CHARACTER SET utf8 COLLATE utf8_unicode_ci,FULLTEXT (t)) ENGINE=InnoDB;
ALTER TABLE t CONVERT TO CHARACTER SET utf8,CHARACTER SET utf8;

Leads to:

10.11.0 bc563f1a4b0b38de3b41fd0f0d3d8b7f1aacbd8b (Debug)

mysqld: /test/10.11_dbg/storage/innobase/include/dict0mem.h:1339: void dict_index_t::init_change_cols(unsigned int): Assertion `n_fields > n_cols' failed.

10.11.0 bc563f1a4b0b38de3b41fd0f0d3d8b7f1aacbd8b (Debug)

Core was generated by `/test/MD190822-mariadb-10.11.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
[Current thread is 1 (Thread 0x150deb2e2700 (LWP 3148429))]
(gdb) bt
#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x0000150e2428d859 in __GI_abort () at abort.c:79
#2  0x0000150e2428d729 in __assert_fail_base (fmt=0x150e24423588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55682f5cc398 "n_fields > n_cols", file=0x55682f5b8928 "/test/10.11_dbg/storage/innobase/include/dict0mem.h", line=1339, function=<optimized out>) at assert.c:92
#3  0x0000150e2429efd6 in __GI___assert_fail (assertion=assertion@entry=0x55682f5cc398 "n_fields > n_cols", file=file@entry=0x55682f5b8928 "/test/10.11_dbg/storage/innobase/include/dict0mem.h", line=line@entry=1339, function=function@entry=0x55682f5cc400 "void dict_index_t::init_change_cols(unsigned int)") at assert.c:101
#4  0x000055682ee023aa in dict_index_t::init_change_cols (n_cols=1, this=0x150db0130350) at /test/10.11_dbg/storage/innobase/include/dict0mem.h:1339
#5  ha_innobase_inplace_ctx::change_col_collation (this=this@entry=0x150db0015200, index=index@entry=0x150db0130350, altered_table=@0x150deb2ddf90: {s = 0x150deb2def20, file = 0x150db0126310, next = 0x0, prev = 0x0, share_all_next = 0x0, share_all_prev = 0x0, global_free_next = 0x0, global_free_prev = 0x0, instance = 0, in_use = 0x150db0000db8, record = {0x150db0125e88 "\377   \245\245\245\245\310^\022\260\r\025", 0x150db0125e88 "\377   \245\245\245\245\310^\022\260\r\025", 0x150db0125e88 "\377   \245\245\245\245\310^\022\260\r\025"}, write_row_record = 0x0, insert_values = 0x0, covering_keys = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, intersect_keys = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, keys_in_use_for_query = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, keys_in_use_for_group_by = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, keys_in_use_for_order_by = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, constraint_dependent_keys = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, key_info = 0x150db0125fa8, field = 0x150db0125e90, vfield = 0x0, default_field = 0x0, next_number_field = 0x0, found_next_number_field = 0x0, check_constraints = 0x0, triggers = 0x0, pos_in_table_list = 0x0, pos_in_locked_tables = 0x0, internal_tables = 0x0, group = 0x0, alias = {<Charset> = {m_charset = 0x55682fca7d20 <my_charset_bin>}, <Binary_string> = {<Sql_alloc> = {<No data fields>}, Ptr = 0x150db0125e80 "t", str_length = 1, Alloced_length = 0, extra_alloc = 0, alloced = false, thread_specific = false}, <No data fields>}, null_flags = 0x150db0125e88 "\377   \245\245\245\245\310^\022\260\r\025", def_read_set = {bitmap = 0x150db0126088, last_word_ptr = 0x150db0126088, last_word_mask = 4294967294, n_bits = 1}, def_write_set = {bitmap = 0x150db012608c, last_word_ptr = 0x150db012608c, last_word_mask = 4294967294, n_bits = 1}, tmp_set = {bitmap = 0x150db0126094, last_word_ptr = 0x150db0126094, last_word_mask = 4294967294, n_bits = 1}, def_rpl_write_set = {bitmap = 0x150db01260a0, last_word_ptr = 0x150db01260a0, last_word_mask = 4294967294, n_bits = 1}, eq_join_set = {bitmap = 0x150db0126098, last_word_ptr = 0x150db0126098, last_word_mask = 4294967294, n_bits = 1}, cond_set = {bitmap = 0x150db012609c, last_word_ptr = 0x150db012609c, last_word_mask = 4294967294, n_bits = 1}, read_set = 0x150deb2df270, write_set = 0x150deb2df270, rpl_write_set = 0x0, has_value_set = {bitmap = 0x150db0126090, last_word_ptr = 0x150db0126090, last_word_mask = 4294967294, n_bits = 1}, query_id = 0, collected_stats = 0x0, used_stat_records = 0, opt_range_keys = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, opt_range = 0x150db0125ea0, const_key_parts = 0x150db0125ec0, opt_range_condition_rows = 0, cond_selectivity = 1, cond_selectivity_sampling_explain = 0x0, map = 0, lock_position = 0, lock_data_start = 0, lock_count = 0, tablenr = 0, used_fields = 0, temp_pool_slot = 0, status = 3, db_stat = 0, derived_select_number = 0, maybe_null = 0, current_lock = 2, copy_blobs = false, next_number_field_updated = false, null_row = false, no_rows_with_nulls = false, null_catch_flags = 0 '\000', force_index = false, force_index_order = false, force_index_group = false, distinct = false, const_table = false, no_rows = false, used_for_duplicate_elimination = false, keep_row_order = false, no_keyread = false, locked_by_logger = false, locked_by_name = false, fulltext_searched = false, no_cache = false, open_by_handler = false, auto_increment_field_not_null = false, insert_or_update = false, alias_name_used = false, get_fields_in_item_tree = false, vcol_refix_list = {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x55682fd7ec20 <end_of_list>, last = 0x150deb2de218, elements = 0}, <No data fields>}, m_needs_reopen = false, created = false, master_had_triggers = false, reginfo = {join_tab = 0x0, lock_type = TL_UNLOCK, skip_locked = false, not_exists_optimize = false, impossible_range = false}, mem_root = {free = 0x150db0125e68, used = 0x150db01262f8, pre_alloc = 0x0, min_malloc = 32, block_size = 1016, block_num = 6, first_block_usage = 0, flags = 0, error_handler = 0x55682e8e3e1a <sql_alloc_error_handler()>, psi_key = 0}, blob_storage = 0x0, grant = {grant_table_user = 0x0, grant_table_role = 0x0, version = 0, privilege = NO_ACL, want_privilege = NO_ACL, orig_want_privilege = NO_ACL, m_internal = {m_schema_lookup_done = false, m_schema_access = 0x0, m_table_lookup_done = false, m_table_access = 0x0}}, expr_arena = 0x0, part_info = 0x0, all_partitions_pruned_away = false, max_keys = 0, stats_is_read = false, histograms_are_read = false, mdl_ticket = 0x0, spl_opt_info = 0x0, keys_usable_for_splitting = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, notnull_cond = 0x0, with_impossible_ranges = {static BITS_PER_ELEMENT = 64, static ARRAY_ELEMENTS = 1, static ALL_BITS_SET = 18446744073709551615, buffer = {0}}, range_rowid_filter_cost_info_elems = 0, range_rowid_filter_cost_info = 0x0, range_rowid_filter_cost_info_ptr = 0x0, vers_write = false}) at /test/10.11_dbg/storage/innobase/handler/handler0alter.cc:1430
#6  0x000055682edec080 in prepare_inplace_alter_table_dict (ha_alter_info=ha_alter_info@entry=0x150deb2dded0, altered_table=altered_table@entry=0x150deb2ddf90, old_table=<optimized out>, table_name=<optimized out>, flags=<optimized out>, flags2=<optimized out>, fts_doc_id_col=<optimized out>, add_fts_doc_id=<optimized out>, add_fts_doc_id_idx=<optimized out>) at /test/10.11_dbg/storage/innobase/handler/handler0alter.cc:7200
#7  0x000055682edf1b85 in ha_innobase::prepare_inplace_alter_table (this=<optimized out>, altered_table=<optimized out>, ha_alter_info=<optimized out>) at /test/10.11_dbg/storage/innobase/handler/ha_innodb.h:700
#8  0x000055682eaa856d in handler::ha_prepare_inplace_alter_table (this=0x150db0121a10, altered_table=altered_table@entry=0x150deb2ddf90, ha_alter_info=ha_alter_info@entry=0x150deb2dded0) at /test/10.11_dbg/sql/handler.cc:5215
#9  0x000055682e886ef7 in mysql_inplace_alter_table (thd=thd@entry=0x150db0000db8, table_list=0x150db0013d60, table=table@entry=0x150db0121118, altered_table=altered_table@entry=0x150deb2ddf90, ha_alter_info=ha_alter_info@entry=0x150deb2dded0, target_mdl_request=target_mdl_request@entry=0x150deb2de760, ddl_log_state=0x150deb2dde60, trigger_param=0x150deb2de350, alter_ctx=0x150deb2df610, partial_alter=@0x150deb2dddcf: false, start_alter_id=@0x150deb2dddd8: 0, if_exists=false) at /test/10.11_dbg/sql/sql_table.cc:7612
#10 0x000055682e89a2a8 in mysql_alter_table (thd=thd@entry=0x150db0000db8, new_db=new_db@entry=0x150db0005890, new_name=new_name@entry=0x150db0005ca0, create_info=create_info@entry=0x150deb2e0400, table_list=<optimized out>, table_list@entry=0x150db0013d60, alter_info=alter_info@entry=0x150deb2e0310, order_num=<optimized out>, order=<optimized out>, ignore=<optimized out>, if_exists=<optimized out>) at /test/10.11_dbg/sql/sql_table.cc:10704
#11 0x000055682e91f518 in Sql_cmd_alter_table::execute (this=<optimized out>, thd=0x150db0000db8) at /test/10.11_dbg/sql/structs.h:569
#12 0x000055682e7be1fa in mysql_execute_command (thd=thd@entry=0x150db0000db8, is_called_from_prepared_stmt=is_called_from_prepared_stmt@entry=false) at /test/10.11_dbg/sql/sql_parse.cc:5997
#13 0x000055682e7a6882 in mysql_parse (thd=thd@entry=0x150db0000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x150deb2e1330) at /test/10.11_dbg/sql/sql_parse.cc:8035
#14 0x000055682e7b3e6a in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x150db0000db8, packet=packet@entry=0x150db000b6e9 "ALTER TABLE t CONVERT TO CHARACTER SET utf8,CHARACTER SET utf8", packet_length=packet_length@entry=62, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_class.h:1339
#15 0x000055682e7b6574 in do_command (thd=0x150db0000db8, blocking=blocking@entry=true) at /test/10.11_dbg/sql/sql_parse.cc:1407
#16 0x000055682e9181da in do_handle_one_connection (connect=<optimized out>, connect@entry=0x556830d7bd58, put_in_cache=put_in_cache@entry=true) at /test/10.11_dbg/sql/sql_connect.cc:1418
#17 0x000055682e9186e3 in handle_one_connection (arg=0x556830d7bd58) at /test/10.11_dbg/sql/sql_connect.cc:1312
#18 0x0000150e2479e609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#19 0x0000150e2438a133 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.6.10 (dbg), 10.7.6 (dbg), 10.8.5 (dbg), 10.9.2 (dbg), 10.10.2 (dbg), 10.11.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.3.37 (dbg), 10.3.37 (opt), 10.4.27 (dbg), 10.4.27 (opt), 10.5.18 (dbg), 10.5.18 (opt), 10.6.10 (opt), 10.7.6 (opt), 10.8.5 (opt), 10.9.2 (opt), 10.10.2 (opt), 10.11.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.38 (dbg), 5.7.38 (opt), 8.0.29 (dbg), 8.0.29 (opt)

Comment by Thirunarayanan Balathandayuthapani [ 2022-08-23 ]

Patch is in bb-10.6-MDEV-29314

Comment by Marko Mäkelä [ 2022-08-23 ]

Thank you. This looks like an unnecessarily strict debug assertion, with no impact on release builds. The fix looks OK to me.

Generated at Thu Feb 08 10:07:34 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.