midenok / mariadb

MariaDB server is a community developed fork of MySQL server. Started by core members of the original MySQL team, MariaDB actively works with outside developers to deliver the most featureful, stable, and sanely licensed open SQL server in the industry.
GNU General Public License v2.0
0 stars 0 forks source link

MDEV-21138 Assertion col->ord_part' or f.col->ord_part' failed in row_build_index_entry_low #68

Closed midenok closed 3 years ago

midenok commented 4 years ago

MDEV-21138 Assertion col->ord_part' orf.col->ord_part' failed in row_build_index_entry_low

Reproduce

--source include/have_innodb.inc

create or replace table t1 (f1 int, f2 text, f3 int, fulltext (f2), key(f1), key(f3), foreign key r (f3) references t1 (f1) on delete set null) with system versioning engine=innodb;
insert into t1 values (1,repeat('a',8193),1),(1,repeat('b',8193),1);
delete from t1;

# cleanup
drop table t1;

Result

#0  row_build_index_entry_low (row=0x7f1fec0580f0, ext=0x0, index=0x7f1fec02b698, heap=0x7f1fec01e4e0, flag=3) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0row.cc:315
#1  0x0000000000f6abc9 in ins_node_create_entry_list (node=0x7f1fec058210) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:120
#2  0x0000000000f6aa29 in ins_node_set_new_row (node=0x7f1fec058210, row=0x7f1fec0580f0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:200
#3  0x0000000000fa8c9b in row_update_vers_insert (thr=0x7f1fec0560c8, node=0x7f1fec024f18) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2176
#4  0x0000000000fa884d in row_update_cascade_for_mysql (thr=0x7f1fec0560c8, node=0x7f1fec024f18, table=0x7f1fec01bf98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2247
#5  0x0000000000f6e736 in row_ins_foreign_check_on_constraint (thr=0x7f1fec0560c8, foreign=0x7f1fec02c318, pcur=0x7f2048058b00, entry=0x7f1fec01e158, mtr=0x7f2048058610) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1441
#6  0x0000000000f6be56 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x7f1fec02c318, table=0x7f1fec01bf98, entry=0x7f1fec01e158, thr=0x7f1fec0560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1864
#7  0x000000000102ab04 in row_upd_check_references_constraints (node=0x7f1fec048940, pcur=0x7f2048059128, table=0x7f1fec01bf98, index=0x7f1fec01e678, offsets=0x7f1fec055490, thr=0x7f1fec0560c8, mtr=0x7f2048059228) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:296
#8  0x000000000102cfe4 in row_upd_sec_index_entry (node=0x7f1fec048940, thr=0x7f1fec0560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2520
#9  0x000000000102849d in row_upd_sec_step (node=0x7f1fec048940, thr=0x7f1fec0560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2569
#10 0x0000000001023ff7 in row_upd (node=0x7f1fec048940, thr=0x7f1fec0560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3339
#11 0x00000000010238a5 in row_upd_step (thr=0x7f1fec0560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3454
#12 0x0000000000fa70e1 in row_update_for_mysql (prebuilt=0x7f1fec047d08) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#13 0x0000000000dd112e in ha_innobase::update_row (this=0x7f1fec047560, old_row=0x7f1fec01a370 "\370\001", new_row=0x7f1fec01a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8849
#14 0x0000000000b4029c in handler::ha_update_row (this=0x7f1fec047560, old_data=0x7f1fec01a370 "\370\001", new_data=0x7f1fec01a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#15 0x0000000000d3aa0f in TABLE::delete_row (this=0x7f1fec046988) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:249
#16 0x0000000000d36f82 in mysql_delete (thd=0x7f1fec000ce8, table_list=0x7f1fec013c98, conds=0x7f1fec0150c8, order_list=0x7f1fec0055a8, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:720
#17 0x00000000007c30a4 in mysql_execute_command (thd=0x7f1fec000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#18 0x00000000007ba4b0 in mysql_parse (thd=0x7f1fec000ce8, rawbuf=0x7f1fec013bd0 "DELETE FROM t1", length=14, parser_state=0x7f204805d5e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

Related tests

innodb.innodb-32k innodb.innodb-64k innodb.innodb-16k innodb.innodb-32k-crash innodb.innodb-64k-crash innodb.blob-crash innodb.innodb-table-online innodb.index_merge_threshold innodb.innodb-ucs2 innodb.innodb_prefix_index_restart_server innodb.instant_alter_crash innodb.innodb-wl5522-1 innodb.innodb_bug53592 innodb.purge innodb.temp_table_savepoint innodb.undo_log
midenok commented 4 years ago

Good: col->ord_part set

#0  0x00000000011b6944 in dict_index_add_to_cache (index=@0x7f05540259b0: 0x7f05540254f8, page_no=4294967295, add_v=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/dict/dict0dict.cc:2180
#1  0x00000000011a110b in dict_create_index_step (thr=0x7f0554042088) at /home/midenok/src/mariadb/10.3/src/storage/innobase/dict/dict0crea.cc:1359
#2  0x0000000000f3282b in que_thr_step (thr=0x7f0554042088) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1047
#3  0x0000000000f31764 in que_run_threads_low (thr=0x7f0554042088) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1099
#4  0x0000000000f31489 in que_run_threads (thr=0x7f0554042088) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1139
#5  0x0000000000e2c6c4 in create_index_dict (trx=0x7f05b79011b8, index=0x7f05540254f8, add_v=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/handler0alter.cc:4798
#6  0x0000000000e1c4d8 in prepare_inplace_alter_table_dict (ha_alter_info=0x7f05b40993c8, altered_table=0x7f05540404f8, old_table=0x7f0554039c98, table_name=0x7f055403c535 "bug53592", flags=1, flags2=80, fts_doc_id_col=18446744073709551615, add_fts_doc_id=false, add_fts_doc_id_idx=false) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/handler0alter.cc:5638
#7  0x0000000000e12fdd in ha_innobase::prepare_inplace_alter_table (this=0x7f055402b3a0, altered_table=0x7f05540404f8, ha_alter_info=0x7f05b40993c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/handler0alter.cc:6808
#8  0x0000000000b39cf1 in handler::ha_prepare_inplace_alter_table (this=0x7f055402b3a0, altered_table=0x7f05540404f8, ha_alter_info=0x7f05b40993c8) at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:4556
#9  0x00000000008cc94d in mysql_inplace_alter_table (thd=0x7f0554000ce8, table_list=0x7f0554013d00, table=0x7f0554039c98, altered_table=0x7f05540404f8, ha_alter_info=0x7f05b40993c8, inplace_supported=HA_ALTER_INPLACE_NOCOPY_NO_LOCK, target_mdl_request=0x7f05b4099b18, alter_ctx=0x7f05b4099cc8) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:7594
#10 0x00000000008c6090 in mysql_alter_table (thd=0x7f0554000ce8, new_db=0x7f0554013d18, new_name=0x7f0554013d28, create_info=0x7f05b409c338, table_list=0x7f0554013d00, alter_info=0x7f05b409c280, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:9918
#11 0x00000000007c0e0f in mysql_execute_command (thd=0x7f0554000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4098
#12 0x00000000007ba4b0 in mysql_parse (thd=0x7f0554000ce8, rawbuf=0x7f0554013bd0 "create unique index bug53592_c on bug53592(c(1))", length=48, parser_state=0x7f05b409d5e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
2169            n_ord = new_index->n_uniq;
2170            /* Flag the ordering columns and also set column max_prefix */
2171
2172            for (i = 0; i < n_ord; i++) {
2173                    const dict_field_t*     field
2174                            = dict_index_get_nth_field(new_index, i);
2175
2176                    /* Check the column being added in the index for
2177                    the first time and flag the ordering column. */
2178                    if (field->col->ord_part == 0 ) {
2179                            field->col->max_prefix = field->prefix_len;
2180                            field->col->ord_part = 1;

Bad: f2 added to cache

#0  dict_index_add_to_cache (index=@0x7f1fec01e180: 0x7f1fec01dcc8, page_no=4294967295, add_v=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/dict/dict0dict.cc:2127
#1  0x00000000011a10cb in dict_create_index_step (thr=0x7f1fec02c3f8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/dict/dict0crea.cc:1359
#2  0x0000000000f3282b in que_thr_step (thr=0x7f1fec02c3f8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1047
#3  0x0000000000f31764 in que_run_threads_low (thr=0x7f1fec02c3f8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1099
#4  0x0000000000f31489 in que_run_threads (thr=0x7f1fec02c3f8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/que/que0que.cc:1139
#5  0x0000000000fa9fb7 in row_create_index_for_mysql (index=0x7f1fec01dcc8, trx=0x7f205a4641b8, field_lengths=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2567
#6  0x0000000000df9382 in create_index (trx=0x7f205a4641b8, form=0x7f20480571c0, table=0x7f1fec01bf98, key_num=2) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:11195
#7  0x0000000000dda360 in create_table_info_t::create_table (this=0x7f2048056490, create_fk=true) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:12421
#8  0x0000000000dfaa2c in ha_innobase::create (this=0x7f1fec01af10, name=0x7f2048059fc0 "./test/t1", form=0x7f20480571c0, create_info=0x7f204805a5c8, file_per_table=true, trx=0x7f205a4641b8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:12890
#9  0x0000000000ddb84f in ha_innobase::create (this=0x7f1fec01af10, name=0x7f2048059fc0 "./test/t1", form=0x7f20480571c0, create_info=0x7f204805a5c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:12943
#10 0x0000000000b3a361 in handler::ha_create (this=0x7f1fec01af10, name=0x7f2048059fc0 "./test/t1", form=0x7f20480571c0, info_arg=0x7f204805a5c8) at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:4714
#11 0x0000000000b3bf27 in ha_create_table (thd=0x7f1fec000ce8, path=0x7f2048059fc0 "./test/t1", db=0x7f1fec014440 "test", table_name=0x7f1fec013d98 "t1", create_info=0x7f204805a5c8, frm=0x7f2048059fb0) at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:5177
#12 0x00000000009340eb in rea_create_table (thd=0x7f1fec000ce8, frm=0x7f2048059fb0, path=0x7f2048059fc0 "./test/t1", db=0x7f1fec014440 "test", table_name=0x7f1fec013d98 "t1", create_info=0x7f204805a5c8, file=0x7f1fec015760, no_ha_create_table=false) at /home/midenok/src/mariadb/10.3/src/sql/unireg.cc:514
#13 0x00000000008bcf53 in create_table_impl (thd=0x7f1fec000ce8, orig_db=0x7f1fec013e00, orig_table_name=0x7f1fec013e10, db=0x7f1fec013e00, table_name=0x7f1fec013e10, path=0x7f2048059fc0 "./test/t1", options=..., create_info=0x7f204805a5c8, alter_info=0x7f204805a510, create_table_mode=0, is_trans=0x7f204805a307, key_info=0x7f204805a1d0, key_count=0x7f204805a1cc, frm=0x7f2048059fb0) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:4999
#14 0x00000000008bc0e8 in mysql_create_table_no_lock (thd=0x7f1fec000ce8, db=0x7f1fec013e00, table_name=0x7f1fec013e10, create_info=0x7f204805a5c8, alter_info=0x7f204805a510, is_trans=0x7f204805a307, create_table_mode=0, table_list=0x7f1fec013de8) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:5118
#15 0x00000000008bd770 in mysql_create_table (thd=0x7f1fec000ce8, create_table=0x7f1fec013de8, create_info=0x7f204805a5c8, alter_info=0x7f204805a510) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:5210
#16 0x00000000008d20bd in Sql_cmd_create_table_like::execute (this=0x7f1fec013dc8, thd=0x7f1fec000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_table.cc:11250
#17 0x00000000007c85cd in mysql_execute_command (thd=0x7f1fec000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:6031
#18 0x00000000007ba4b0 in mysql_parse (thd=0x7f1fec000ce8, rawbuf=0x7f1fec013bd0 "CREATE TABLE t1 (f1 INT, f2 TEXT, f3 INT, FULLTEXT (f2), KEY(f1), KEY(f3), FOREIGN KEY r (f3) REFERENCES t1 (f1) ON DELETE SET NULL) WITH SYSTEM VERSIONING ENGINE=InnoDB", length=169, parser_state=0x7f204805d5e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818
(rr) p index->n_uniq
$87 = 0

Info

    unsigned    n_uniq:10;/*!< number of fields from the beginning
                which are enough to determine an index
                entry uniquely */

n_uniq is set in dict_index_build_internal_non_clust() but it's not called for FTS index.

FTS indexes are treated differently:

3645                    if (node->index->type != DICT_FTS) {
3646                            dberr_t err = row_ins_index_entry_step(node, thr);
3647
3648                            if (err != DB_SUCCESS) {
3649                                    DBUG_RETURN(err);
3650                            }
3651                    }
midenok commented 4 years ago

Bad

1. FTS field is set to UNIV_SQL_NULL

#0  0x0000000000fe22f6 in dfield_set_len (field=0x7f12c8058150, len=4294967295) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:59
#1  0x0000000000fe72ee in dtuple_create_from_mem (buf=0x7f12c80580f0, buf_size=288, n_fields=9, n_v_fields=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:332
#2  0x0000000000fe138f in dtuple_create_with_vcol (heap=0x7f12c8058010, n_fields=9, n_v_fields=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:407
#3  0x0000000000fe2ce9 in row_build_low (type=1, index=0x7f12c8020958, rec=0x7f132b0e40cd "", offsets=0x7f132804c7e0, col_table=0x7f12c801bf98, defaults=0x0, add_v=0x0, col_map=0x0, ext=0x0, heap=0x7f12c8058010) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0row.cc:492
#4  0x0000000000fe238a in row_build (type=1, index=0x7f12c8020958, rec=0x7f132b0e40cd "", offsets=0x0, col_table=0x7f12c801bf98, defaults=0x0, col_map=0x0, ext=0x0, heap=0x7f12c8058010) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0row.cc:630
#5  0x0000000000f6e641 in row_ins_foreign_check_on_constraint (thr=0x7f12c80560c8, foreign=0x7f12c802c318, pcur=0x7f132804db00, entry=0x7f12c801e158, mtr=0x7f132804d610) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1411
#6  0x0000000000f6be56 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x7f12c802c318, table=0x7f12c801bf98, entry=0x7f12c801e158, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1864
#7  0x000000000102ab94 in row_upd_check_references_constraints (node=0x7f12c8048940, pcur=0x7f132804e128, table=0x7f12c801bf98, index=0x7f12c801e678, offsets=0x7f12c8055490, thr=0x7f12c80560c8, mtr=0x7f132804e228) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:296
#8  0x000000000102d074 in row_upd_sec_index_entry (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2520
#9  0x000000000102852d in row_upd_sec_step (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2569
#10 0x0000000001024087 in row_upd (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3339
#11 0x0000000001023935 in row_upd_step (thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3454
#12 0x0000000000fa70e1 in row_update_for_mysql (prebuilt=0x7f12c8047d08) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#13 0x0000000000dd112e in ha_innobase::update_row (this=0x7f12c8047560, old_row=0x7f12c801a370 "\370\001", new_row=0x7f12c801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8849
#14 0x0000000000b4029c in handler::ha_update_row (this=0x7f12c8047560, old_data=0x7f12c801a370 "\370\001", new_data=0x7f12c801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#15 0x0000000000d3aa0f in TABLE::delete_row (this=0x7f12c8046988) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:249
#16 0x0000000000d36f82 in mysql_delete (thd=0x7f12c8000ce8, table_list=0x7f12c8013c98, conds=0x7f12c80150c8, order_list=0x7f12c80055a8, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:720
#17 0x00000000007c30a4 in mysql_execute_command (thd=0x7f12c8000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#18 0x00000000007ba4b0 in mysql_parse (thd=0x7f12c8000ce8, rawbuf=0x7f12c8013bd0 "DELETE FROM t1", length=14, parser_state=0x7f13280525e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

2. FTS field is set to 20

#0  dfield_set_data (field=0x7f12c8058150, data=0x7f12c80580b7, len=20) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:106
#1  0x0000000000fe2f81 in row_build_low (type=1, index=0x7f12c8020958, rec=0x7f132b0e40cd "", offsets=0x7f132804c7e0, col_table=0x7f12c801bf98, defaults=0x0, add_v=0x0, col_map=0x0, ext=0x0, heap=0x7f12c8058010) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0row.cc:540
#2  0x0000000000fe238a in row_build (type=1, index=0x7f12c8020958, rec=0x7f132b0e40cd "", offsets=0x0, col_table=0x7f12c801bf98, defaults=0x0, col_map=0x0, ext=0x0, heap=0x7f12c8058010) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0row.cc:630
#3  0x0000000000f6e641 in row_ins_foreign_check_on_constraint (thr=0x7f12c80560c8, foreign=0x7f12c802c318, pcur=0x7f132804db00, entry=0x7f12c801e158, mtr=0x7f132804d610) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1411
#4  0x0000000000f6be56 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x7f12c802c318, table=0x7f12c801bf98, entry=0x7f12c801e158, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1864
#5  0x000000000102ab94 in row_upd_check_references_constraints (node=0x7f12c8048940, pcur=0x7f132804e128, table=0x7f12c801bf98, index=0x7f12c801e678, offsets=0x7f12c8055490, thr=0x7f12c80560c8, mtr=0x7f132804e228) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:296
#6  0x000000000102d074 in row_upd_sec_index_entry (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2520
#7  0x000000000102852d in row_upd_sec_step (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2569
#8  0x0000000001024087 in row_upd (node=0x7f12c8048940, thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3339
#9  0x0000000001023935 in row_upd_step (thr=0x7f12c80560c8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3454
#10 0x0000000000fa70e1 in row_update_for_mysql (prebuilt=0x7f12c8047d08) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#11 0x0000000000dd112e in ha_innobase::update_row (this=0x7f12c8047560, old_row=0x7f12c801a370 "\370\001", new_row=0x7f12c801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8849
#12 0x0000000000b4029c in handler::ha_update_row (this=0x7f12c8047560, old_data=0x7f12c801a370 "\370\001", new_data=0x7f12c801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6478
#13 0x0000000000d3aa0f in TABLE::delete_row (this=0x7f12c8046988) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:249
#14 0x0000000000d36f82 in mysql_delete (thd=0x7f12c8000ce8, table_list=0x7f12c8013c98, conds=0x7f12c80150c8, order_list=0x7f12c80055a8, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:720
#15 0x00000000007c30a4 in mysql_execute_command (thd=0x7f12c8000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#16 0x00000000007ba4b0 in mysql_parse (thd=0x7f12c8000ce8, rawbuf=0x7f12c8013bd0 "DELETE FROM t1", length=14, parser_state=0x7f13280525e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

Good

Test: innodb_fts.basic

FTS field length is set to UNIV_SQL_NULL

#0  0x0000000000fb2ab6 in dfield_set_len (field=0x7fde580454e0, len=4294967295) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:59
#1  0x0000000000fb298e in dtuple_create_from_mem (buf=0x7fde58045480, buf_size=240, n_fields=7, n_v_fields=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:332
#2  0x0000000000fb282f in dtuple_create_with_vcol (heap=0x7fde58044c80, n_fields=7, n_v_fields=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/data0data.ic:407
#3  0x0000000000fa457d in row_get_prebuilt_insert_row (prebuilt=0x7fde58044d08) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1133
#4  0x0000000000fa4d72 in row_insert_for_mysql (mysql_rec=0x7fde5801a350 "\374\001", prebuilt=0x7fde58044d08, ins_mode=ROW_INS_NORMAL) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1414
#5  0x0000000000dd053d in ha_innobase::write_row (this=0x7fde5801b260, record=0x7fde5801a350 "\374\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8056
#6  0x0000000000b3fe11 in handler::ha_write_row (this=0x7fde5801b260, buf=0x7fde5801a350 "\374\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6446
#7  0x0000000000774be5 in write_record (thd=0x7fde58000ce8, table=0x7fde580440c8, info=0x7fdeb4050720) at /home/midenok/src/mariadb/10.3/src/sql/sql_insert.cc:2034
#8  0x0000000000770d51 in mysql_insert (thd=0x7fde58000ce8, table_list=0x7fde58013fa0, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_insert.cc:1072
#9  0x00000000007c2185 in mysql_execute_command (thd=0x7fde58000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4455
#10 0x00000000007ba4b0 in mysql_parse (thd=0x7fde58000ce8, rawbuf=0x7fde58013bd0 "INSERT INTO articles (title,body) VALUES\n('MySQL Tutorial','DBMS stands for DataBase ...')  ,\n('How To Use MySQL Well','After you went through a ...'),\n('Optimizing MySQL','In this tutorial we will show ...'),\n('1001 MySQL Tricks','1. Never run mysqld as root. 2. ...'),\n('MySQL vs. YourSQL','In the following database comparison ...'),\n('MySQL Security','When configured properly, MySQL ...')", length=393, parser_state=0x7fdeb40535e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

Cause

History row tuple for foreign constraint is built from cluster index in row_ins_foreign_check_on_constraint():

    if (table->versioned() && cascade->is_delete != PLAIN_DELETE
        && cascade->update->affects_versioned()) {
        ut_ad(!cascade->historical_heap);
        cascade->historical_heap = mem_heap_create(srv_page_size);
        cascade->historical_row = row_build(
            ROW_COPY_DATA, clust_index, clust_rec, NULL, table,
            NULL, NULL, NULL, cascade->historical_heap);
    }

this tuple is then used to build insert node for history row, row_update_vers_insert():

    dtuple_t* row = node->historical_row;
    ut_ad(row);
    node->historical_row = NULL;

    ins_node_t* insert_node =
        ins_node_create(INS_DIRECT, table, node->historical_heap);

    if (!insert_node) {
        trx->error_state = DB_OUT_OF_MEMORY;
        goto exit;
    }

    insert_node->common.parent = thr;
    ins_node_set_new_row(insert_node, row);

ins_node_set_new_row() loops across all indexes and builds entries for them. The good example how it's used is in row_get_prebuilt_insert_row():

1133            row = dtuple_create_with_vcol(
1134                            prebuilt->heap, dict_table_get_n_cols(table),
1135                            dict_table_get_n_v_cols(table));
1136
1137            dict_table_copy_types(row, table);
1138
1139            ins_node_set_new_row(node, row);

ins_node_set_new_row() operates on empty row. OTOH row_build_index_entry_low() will not accept non-NULL tuple for FTS index, this assertion must be added to it:

diff --git a/storage/innobase/row/row0row.cc b/storage/innobase/row/row0row.cc
index cdcb568a508..ff722c30f8c 100644
--- a/storage/innobase/row/row0row.cc
+++ b/storage/innobase/row/row0row.cc
@@ -294,6 +294,8 @@ row_build_index_entry_low(
                        continue;
                }

+               ut_ad(index->type != DICT_FTS);
+
                if ((!ind_field || ind_field->prefix_len == 0)
                    && (!dfield_is_ext(dfield)
                        || dict_index_is_clust(index))) {

Fix

Use ins_node_set_new_row() for empty row first like in example from row_get_prebuilt_insert_row() then copy history row values to it. In this case cascade->historical_row can be built as ROW_COPY_POINTERS instead of ROW_COPY_DATA, I guess.

midenok commented 4 years ago
--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -2160,9 +2160,13 @@ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node)
        dict_table_t* table = node->table;
        ut_ad(table->versioned());

-       dtuple_t* row = node->historical_row;
-       ut_ad(row);
-       node->historical_row = NULL;
+       dtuple_t*       row;
+
+       row = dtuple_create_with_vcol(
+                       node->historical_heap, dict_table_get_n_cols(table),
+                       dict_table_get_n_v_cols(table));
+
+       dict_table_copy_types(row, table);

        ins_node_t* insert_node =
                ins_node_create(INS_DIRECT, table, node->historical_heap);
@@ -2175,6 +2179,24 @@ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node)
        insert_node->common.parent = thr;
        ins_node_set_new_row(insert_node, row);

+       {
+       ulint           n_fields        = dtuple_get_n_fields(node->historical_row);
+       ulint           n_v_fields      = dtuple_get_n_v_fields(node->historical_row);
+       ulint           i;
+
+       for (i = 0; i < n_fields; i++) {
+               dfield_copy(dtuple_get_nth_field(row, i),
+                       dtuple_get_nth_field(node->historical_row, i));
+       }
+
+       for (i = 0; i < n_v_fields; i++) {
+               dfield_copy(dtuple_get_nth_v_field(row, i),
+                       dtuple_get_nth_v_field(node->historical_row, i));
+       }
+       }
+
+       node->historical_row = NULL;
+
        row_end = dtuple_get_nth_field(row, table->vers_end);
        if (dict_table_get_nth_col(table, table->vers_end)

Assertion fails (versioning.foreign)

#4  0x0000000000f71a86 in row_ins_clust_index_entry_by_modify (pcur=0x7f22b404c858, flags=0, mode=2, offsets=0x7f22b404c0e8, offsets_heap=0x7f22b404c348, heap=0x7f22580a1e70, entry=0x7f225803c6e8, thr=0x7f2258093380, mtr=0x7f22b404c358) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:340
#5  0x0000000000f70708 in row_ins_clust_index_entry_low (flags=0, mode=2, index=0x7f2258035bb8, n_uniq=0, entry=0x7f225803c6e8, n_ext=0, thr=0x7f2258093380) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:2760
#6  0x0000000000f753bf in row_ins_clust_index_entry (index=0x7f2258035bb8, entry=0x7f225803c6e8, thr=0x7f2258093380, n_ext=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3235
#7  0x0000000000f7e5d1 in row_ins_index_entry (index=0x7f2258035bb8, entry=0x7f225803c6e8, thr=0x7f2258093380) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3360
#8  0x0000000000f7dad5 in row_ins_index_entry_step (node=0x7f225809e048, thr=0x7f2258093380) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3510
#9  0x0000000000f76720 in row_ins (node=0x7f225809e048, thr=0x7f2258093380) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3646
#10 0x0000000000f76323 in row_ins_step (thr=0x7f2258093380) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3789
#11 0x0000000000fa8e1b in row_update_vers_insert (thr=0x7f2258093380, node=0x7f2258056298) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2213

frame 11

(rr)  x/7s table->col_names
0x7fcea408d640: "parent_id"
0x7fcea408d64a: "sys_start"
0x7fcea408d654: "sys_end"
0x7fcea408d65c: "DB_ROW_ID"
0x7fcea408d666: "DB_TRX_ID"
0x7fcea408d670: "DB_ROLL_PTR"
0x7fcea408d67c: ""

Field sizes: 4, 7, 7, 6, 6, 6

Cause

Non-null values for DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR

Fix

Instead of n_fields copy n_fields - 3, leaving DB_ fields empty.

Bad

(rr) x/7bx entry->fields[2].data
0x7f225809de7a: 0xa5    0x00    0x00    0x01    0x53    0x01    0x10
(rr) x/4bx entry->fields[3].data
0x7f225809de81: 0x80    0x00    0x00    0x01
(rr) x/7bx entry->fields[4].data
0x7f225809de85: 0x5e    0x11    0x34    0xe7    0x09    0xf5    0x37
(rr) x/7bx entry->fields[5].data
0x7f22b404ccb8: 0x5e    0x11    0x34    0xe7    0x0a    0xa4    0x84

Good

(rr) x/7bx entry->fields[2].data
0x7f059409e7ec: 0x80    0x00    0x00    0x00    0x00    0x00    0x00
(rr) x/4bx entry->fields[3].data
0x7f059409e651: 0x80    0x00    0x00    0x01
(rr) x/7bx entry->fields[4].data
0x7f059409e655: 0x5e    0x11    0x35    0x42    0x0a    0x70    0xea
(rr) x/7bx entry->fields[5].data
0x7f05d805cbd8: 0x5e    0x11    0x35    0x42    0x0b    0x0f    0x64

Case that utilizes row_ins_clust_index_entry_by_modify()

--source include/have_innodb.inc

create table t1(a int primary key) engine=innodb;
insert into t1 (a) values (1);
begin;
delete from t1;
insert into t1 values (1);
rollback;

drop table t1;
midenok commented 4 years ago

MDEV-20494 ER_NOT_FORM_FILE or Assertion `!is_set() || (m_status == DA_OK_BULK && is_bulk_op())' failed upon adding partition to a versioned table

Reproduce

--source include/have_partition.inc

CREATE TABLE t1 (f DATE, t DATE, PERIOD FOR app(f,t)) WITH SYSTEM VERSIONING PARTITION BY SYSTEM_TIME ( PARTITION p1 HISTORY, PARTITION pn CURRENT );
LOCK TABLE t1 WRITE;
ALTER TABLE t1 ADD PARTITION (PARTITION p2 HISTORY);

# Cleanup
DROP TABLE t1;

Result

#3  0x00007f11d679afb2 in __GI___assert_fail (assertion=0x171e43f "!is_set() || (m_status == DA_OK_BULK && is_bulk_op())", file=0x171e2b5 "/home/midenok/src/mariadb/10.5/src/sql/sql_error.cc", line=335, function=0x171e475 "void Diagnostics_area::set_ok_status(ulonglong, ulonglong, const char *)") at assert.c:101
#4  0x000000000081f125 in Diagnostics_area::set_ok_status (this=0x7f11b8006910, affected_rows=0, last_insert_id=0, message=0x7f11d02a91e0 "Records: 0  Duplicates: 0  Warnings: 0") at /home/midenok/src/mariadb/10.5/src/sql/sql_error.cc:335
#5  0x00000000007b094f in my_ok (thd=0x7f11b8000cf8, affected_rows_arg=0, id=0, message=0x7f11d02a91e0 "Records: 0  Duplicates: 0  Warnings: 0") at /home/midenok/src/mariadb/10.5/src/sql/sql_class.h:5282
#6  0x0000000000e8f16c in fast_end_partition (thd=0x7f11b8000cf8, copied=0, deleted=0, table_list=0x7f11b8019560) at /home/midenok/src/mariadb/10.5/src/sql/sql_partition.cc:4520
#7  0x0000000000e8d67c in fast_alter_partition_table (thd=0x7f11b8000cf8, table=0x7f11b80172e8, alter_info=0x7f11d02acd60, create_info=0x7f11d02ace68, table_list=0x7f11b8019560, db=0x7f11d02ab908, table_name=0x7f11d02ab918) at /home/midenok/src/mariadb/10.5/src/sql/sql_partition.cc:7391
#8  0x0000000000999d87 in mysql_alter_table (thd=0x7f11b8000cf8, new_db=0x7f11b8005520, new_name=0x7f11b80059b0, create_info=0x7f11d02ace68, table_list=0x7f11b8019560, alter_info=0x7f11d02acd60, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/10.5/src/sql/sql_table.cc:10201
#9  0x0000000000a72368 in Sql_cmd_alter_table::execute (this=0x7f11b801f4f0, thd=0x7f11b8000cf8) at /home/midenok/src/mariadb/10.5/src/sql/sql_alter.cc:517
#10 0x000000000088d823 in mysql_execute_command (thd=0x7f11b8000cf8) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:5959
#11 0x000000000087e296 in mysql_parse (thd=0x7f11b8000cf8, rawbuf=0x7f11b8013d70 "ALTER TABLE t1 ADD PARTITION (PARTITION p2 HISTORY)", length=51, parser_state=0x7f11d02af5c0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.5/src/sql/sql_parse.cc:7988

Error thrown

#0  TABLE_SHARE::init_period_from_extra2 (this=0x7f5f40034440, period=0x7f5f40034978, data=0x7f5f4003ae4b "\001", end=0x7f5f4003ae4d "\004\004\002") at /home/midenok/src/mariadb/10.4/src/sql/table.cc:1450
#1  0x000000000099d4bc in TABLE_SHARE::init_from_binary_frm_image (this=0x7f5f40034440, thd=0x7f5f40000ce8, write=false, frm_image=0x7f5f4003ade8 "\376\001\v\024\061", frm_length=733) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:2134
#2  0x000000000099aa2a in open_table_def (thd=0x7f5f40000ce8, share=0x7f5f40034440, flags=11) at /home/midenok/src/mariadb/10.4/src/sql/table.cc:696
#3  0x0000000000aebc1e in tdc_acquire_share (thd=0x7f5f40000ce8, tl=0x7f5f400384d0, flags=3, out_table=0x7f5f571ab688) at /home/midenok/src/mariadb/10.4/src/sql/table_cache.cc:840
#4  0x000000000078c5b5 in open_table (thd=0x7f5f40000ce8, table_list=0x7f5f400384d0, ot_ctx=0x7f5f571ab758) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:1944
#5  0x0000000000788784 in Locked_tables_list::reopen_tables (this=0x7f5f40004a48, thd=0x7f5f40000ce8, need_reopen=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_base.cc:2686
#6  0x0000000000e16a1c in alter_partition_lock_handling (lpt=0x7f5f571abe00) at /home/midenok/src/mariadb/10.4/src/sql/sql_partition.cc:6858
#7  0x0000000000e15b97 in fast_alter_partition_table (thd=0x7f5f40000ce8, table=0x7f5f40022778, alter_info=0x7f5f571af3c0, create_info=0x7f5f571af478, table_list=0x7f5f40014158, db=0x7f5f571ae108, table_name=0x7f5f571ae118) at /home/midenok/src/mariadb/10.4/src/sql/sql_partition.cc:7470
#8  0x000000000095a84d in mysql_alter_table (thd=0x7f5f40000ce8, new_db=0x7f5f40005498, new_name=0x7f5f400058a0, create_info=0x7f5f571af478, table_list=0x7f5f40014158, alter_info=0x7f5f571af3c0, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:9864
#9  0x0000000000a10ac6 in Sql_cmd_alter_table::execute (this=0x7f5f40014b90, thd=0x7f5f40000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_alter.cc:502
#10 0x00000000008556cb in mysql_execute_command (thd=0x7f5f40000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6102
#11 0x0000000000845c10 in mysql_parse (thd=0x7f5f40000ce8, rawbuf=0x7f5f40014040 "alter table t1 add partition (partition p2 history)", length=51, parser_state=0x7f5f571b25e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7901
1446    bool TABLE_SHARE::init_period_from_extra2(period_info_t *period,
1447                                              const uchar *data, const uchar *end)
1448    {
1449      if (data + 2*frm_fieldno_size > end)
1450        return 1;
1451      period->start_fieldno= read_frm_fieldno(data);
1452      period->end_fieldno= read_frm_fieldno(data + frm_fieldno_size);
1453      return period->start_fieldno >= fields || period->end_fieldno >= fields;
1454    }
(rr) p data + 2*frm_fieldno_size > end
$8 = true
(rr) p data + 2*frm_fieldno_size - end
$9 = 2
(rr) p extra2.application_period.length
$10 = 9

Cause

Error message masked, but status not cleared:

static void alter_partition_lock_handling(ALTER_PARTITION_PARAM_TYPE *lpt)
{
  THD *thd= lpt->thd;
  if (lpt->table)
  {
    /*
      Remove all instances of the table and its locks and other resources.
    */
    close_all_tables_for_name(thd, lpt->table->s, HA_EXTRA_NOT_USED, NULL);
  }
  lpt->table= 0;
  lpt->table_list->table= 0;
  if (thd->locked_tables_mode)
  {
    Diagnostics_area *stmt_da= NULL;
    Diagnostics_area tmp_stmt_da(true);
    if (unlikely(thd->is_error()))
    {
      /* reopen might fail if we have a previous error, use a temporary da. */
      stmt_da= thd->get_stmt_da();
      thd->set_stmt_da(&tmp_stmt_da);
    }
    if (unlikely(thd->locked_tables_list.reopen_tables(thd, false)))
      sql_print_warning("We failed to reacquire LOCKs in ALTER TABLE");
    if (stmt_da)
      thd->set_stmt_da(stmt_da);
  }
}

Related to Bug #32943.

midenok commented 4 years ago

FRM is built

#0  build_frm_image (thd=0x7efc0c000ce8, table=..., create_info=0x7efc23865478, create_fields=..., keys=0, key_info=0x7efc0c015878, db_file=0x7efc0c02d870) at /home/midenok/src/mariadb/10.4/src/sql/unireg.cc:187
#1  0x0000000000945c57 in mysql_write_frm (lpt=0x7efc23861e00, flags=1) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:1848
#2  0x0000000000e14f85 in fast_alter_partition_table (thd=0x7efc0c000ce8, table=0x7efc0c022778, alter_info=0x7efc238653c0, create_info=0x7efc23865478, table_list=0x7efc0c014158, db=0x7efc23864108, table_name=0x7efc23864118) at /home/midenok/src/mariadb/10.4/src/sql/sql_partition.cc:7430
#3  0x000000000095a84d in mysql_alter_table (thd=0x7efc0c000ce8, new_db=0x7efc0c005498, new_name=0x7efc0c0058a0, create_info=0x7efc23865478, table_list=0x7efc0c014158, alter_info=0x7efc238653c0, order_num=0, order=0x0, ignore=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:9864
#4  0x0000000000a10ac6 in Sql_cmd_alter_table::execute (this=0x7efc0c014b90, thd=0x7efc0c000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_alter.cc:502
#5  0x00000000008556cb in mysql_execute_command (thd=0x7efc0c000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6102
#6  0x0000000000845c10 in mysql_parse (thd=0x7efc0c000ce8, rawbuf=0x7efc0c014040 "alter table t1 add partition (partition p2 history)", length=51, parser_state=0x7efc238685e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7901
(rr) p create_info->period_info.constr->name
$16 = {
  <Lex_cstring> = {
    <st_mysql_const_lex_string> = {
      str = 0x0,
      length = 0
    }, <No data fields>}, <No data fields>}
(rr) p period_info_len
$17 = 9

Cause

Lost period_info.constr->name

Good

(rr) p *create_info->period_info.constr
$21 = {
  <Sql_alloc> = {<No data fields>},
  <Type_handler_hybrid_field_type> = {
    m_type_handler = 0x1e107e8 <type_handler_null>
  },
  members of Virtual_column_info:
  vcol_type = VCOL_TYPE_NONE,
  in_partitioning_expr = false,
  stored_in_db = false,
  utf8 = true,
  automatic_name = true,
  expr = 0x7efc0c014da0,
  name = {
    <Lex_cstring> = {
      <st_mysql_const_lex_string> = {
        str = 0x7efc0c015e90 "app",
        length = 3
      }, <No data fields>}, <No data fields>},
  flags = 0
}
(rr) pitem create_info->period_info.constr->expr
$24 = 0x2016e90 <dbug_item_print_buf> "f < t"

Bad

(rr) p *create_info->period_info.constr
$22 = {
  <Sql_alloc> = {<No data fields>},
  <Type_handler_hybrid_field_type> = {
    m_type_handler = 0x1e107e8 <type_handler_null>
  },
  members of Virtual_column_info:
  vcol_type = VCOL_TYPE_NONE,
  in_partitioning_expr = false,
  stored_in_db = false,
  utf8 = true,
  automatic_name = false,
  expr = 0x7efc0c015600,
  name = {
    <Lex_cstring> = {
      <st_mysql_const_lex_string> = {
        str = 0x0,
        length = 0
      }, <No data fields>}, <No data fields>},
  flags = 0
}
(rr) pitem create_info->period_info.constr->expr
$26 = 0x2016e90 <dbug_item_print_buf> "t1.f < t1.t"
midenok commented 4 years ago

Consraint name assigned

#0  0x0000000000969ca9 in make_unique_constraint_name (thd=0x7efc0c000ce8, name=0x7efc0c014b68, own_name_base=0x7efc0c014b38 "app", vcol=0x7efc238653c0, nr=0x7efc23863e84) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5407
#1  0x000000000095f059 in fix_constraints_names (thd=0x7efc0c000ce8, check_constraint_list=0x7efc238653c0, create_info=0x7efc23865418) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:6566
#2  0x0000000000950ff1 in create_table_impl (thd=0x7efc0c000ce8, orig_db=..., orig_table_name=..., db=..., table_name=..., path=0x7efc23864e00 "./test/t1", options=..., create_info=0x7efc23865418, alter_info=0x7efc23865360, create_table_mode=0, is_trans=0x7efc23865147, key_info=0x7efc23865010, key_count=0x7efc2386500c, frm=0x7efc23864df0) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:4872
#3  0x0000000000950cb8 in mysql_create_table_no_lock (thd=0x7efc0c000ce8, db=0x7efc0c014248, table_name=0x7efc0c014258, create_info=0x7efc23865418, alter_info=0x7efc23865360, is_trans=0x7efc23865147, create_table_mode=0, table_list=0x7efc0c014230) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5149
#4  0x00000000009520d0 in mysql_create_table (thd=0x7efc0c000ce8, create_table=0x7efc0c014230, create_info=0x7efc23865418, alter_info=0x7efc23865360) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:5241
#5  0x00000000009675df in Sql_cmd_create_table_like::execute (this=0x7efc0c0141d0, thd=0x7efc0c000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_table.cc:11458
#6  0x00000000008556cb in mysql_execute_command (thd=0x7efc0c000ce8) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:6102
#7  0x0000000000845c10 in mysql_parse (thd=0x7efc0c000ce8, rawbuf=0x7efc0c014040 "create table t1 (f date, t date, period for app(f,t)) with system versioning partition by system_time ( partition p1 history, partition pn current )", length=148, parser_state=0x7efc238685e0, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.4/src/sql/sql_parse.cc:7901

Bad: constraint name not copied:

      if (share->period.constr_name.streq(check->name.str))
      {
        if (!drop_period && !keep)
        {
          my_error(ER_PERIOD_CONSTRAINT_DROP, MYF(0), check->name.str,
                   share->period.name.str);
          goto err;
        }
        keep= keep && !drop_period;

        DBUG_ASSERT(create_info->period_info.constr == NULL || drop_period);

        if (keep)
        {
          Item *expr_copy= check->expr->get_copy(thd);
          check= new Virtual_column_info();
          check->expr= expr_copy;
          create_info->period_info.constr= check;
        }
      }

Fix

Clone properly Virtual_column_info.

midenok commented 4 years ago

MDEV-21138 Assertion col->ord_part' orf.col->ord_part' failed in row_build_index_entry_low

Branch: MDEV-21138/row_update_vers_insert

2020-02-03 21:11:23 8 [ERROR] InnoDB: Duplicate FTS_DOC_ID value on table `test`.`t1`

Error thrown

#0  row_ins_sec_index_entry (index=0x7fc238028998, entry=0x7fc23801f898, thr=0x7fc2380536e8, check_foreign=true) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3336
#1  0x0000000000f808bf in row_ins_index_entry (index=0x7fc238028998, entry=0x7fc23801f898, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3362
#2  0x0000000000f7fda5 in row_ins_index_entry_step (node=0x7fc23805a270, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3510
#3  0x0000000000f789a0 in row_ins (node=0x7fc23805a270, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3646
#4  0x0000000000f785a3 in row_ins_step (thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3789
#5  0x0000000000fab0f3 in row_update_vers_insert (thr=0x7fc2380536e8, node=0x7fc238024f18) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2212
#6  0x0000000000faaaad in row_update_cascade_for_mysql (thr=0x7fc2380536e8, node=0x7fc238024f18, table=0x7fc23801bf98) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2268
#7  0x0000000000f709b6 in row_ins_foreign_check_on_constraint (thr=0x7fc2380536e8, foreign=0x7fc238035b68, pcur=0x7fc294059b40, entry=0x7fc23801e158, mtr=0x7fc294059680) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1441
#8  0x0000000000f6e0d6 in row_ins_check_foreign_constraint (check_ref=0, foreign=0x7fc238035b68, table=0x7fc23801bf98, entry=0x7fc23801e158, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:1864
#9  0x000000000102d05d in row_upd_check_references_constraints (node=0x7fc238048740, pcur=0x7fc29405a158, table=0x7fc23801bf98, index=0x7fc23801e678, offsets=0x7fc23804df00, thr=0x7fc2380536e8, mtr=0x7fc29405a258) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:295
#10 0x000000000102f6c4 in row_upd_sec_index_entry (node=0x7fc238048740, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2517
#11 0x000000000102a9fd in row_upd_sec_step (node=0x7fc238048740, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:2566
#12 0x0000000001026557 in row_upd (node=0x7fc238048740, thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3336
#13 0x0000000001025e05 in row_upd_step (thr=0x7fc2380536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0upd.cc:3451
#14 0x0000000000fa9341 in row_update_for_mysql (prebuilt=0x7fc238047b08) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:1888
#15 0x0000000000dd131e in ha_innobase::update_row (this=0x7fc238047360, old_row=0x7fc23801a370 "\370\001", new_row=0x7fc23801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/storage/innobase/handler/ha_innodb.cc:8838
#16 0x0000000000b4028c in handler::ha_update_row (this=0x7fc238047360, old_data=0x7fc23801a370 "\370\001", new_data=0x7fc23801a348 "\370\001") at /home/midenok/src/mariadb/10.3/src/sql/handler.cc:6479
#17 0x0000000000d3a84f in TABLE::delete_row (this=0x7fc238046788) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:249
#18 0x0000000000d36dc2 in mysql_delete (thd=0x7fc238000ce8, table_list=0x7fc238013c98, conds=0x7fc2380150c8, order_list=0x7fc2380055a0, limit=18446744073709551615, options=0, result=0x0) at /home/midenok/src/mariadb/10.3/src/sql/sql_delete.cc:720
#19 0x00000000007c2e24 in mysql_execute_command (thd=0x7fc238000ce8) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:4658
#20 0x00000000007ba230 in mysql_parse (thd=0x7fc238000ce8, rawbuf=0x7fc238013bd0 "delete from t1", length=14, parser_state=0x7fc29405e5e8, is_com_multi=false, is_next_command=false) at /home/midenok/src/mariadb/10.3/src/sql/sql_parse.cc:7818

frame 3

3645                    if (node->index->type != DICT_FTS) {
3646                            dberr_t err = row_ins_index_entry_step(node, thr);
3647
3648                            if (err != DB_SUCCESS) {
3649                                    DBUG_RETURN(err);
3650                            }
3651                    }
(rr)  p node->index->type
$11 = 2
(rr)  p node->index->name
$12 = {
  m_name = 0x7fc23802bbe8 "FTS_DOC_ID_INDEX"
}
(rr) p DICT_FTS
$13 = 32
(rr) p DICT_UNIQUE
$14 = 2

Note

FTS_DOC_ID_INDEX is UNIQUE index, that's expected.

Fail 2

--- a/storage/innobase/row/row0mysql.cc
+++ b/storage/innobase/row/row0mysql.cc
@@ -2185,8 +2185,10 @@ static dberr_t row_update_vers_insert(que_thr_t* thr, upd_node_t* node)
        ut_ad(n_fields > 3);
        // Exclude DB_ROW_ID, DB_TRX_ID, DB_ROLL_PTR
        for (i = 0; i < n_fields - 3; i++) {
-               dfield_copy(dtuple_get_nth_field(row, i),
-                       dtuple_get_nth_field(node->historical_row, i));
+               dfield_t* f = dtuple_get_nth_field(row, i);
+               if (f->type.prtype & DATA_FTS_DOC_ID)
+                       continue;
+               dfield_copy(f, dtuple_get_nth_field(node->historical_row, i));
        }

        for (i = 0; i < n_v_fields; i++) {
#3  0x00007fe257d5d012 in __GI___assert_fail (assertion=0x176407d "!(col->prtype & 256U)", file=0x1762b50 "/home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc", line=1122, function=0x1763ece "ulint rec_get_converted_size_comp_prefix_low(const dict_index_t *, const dfield_t *, ulint, ulint *, rec_comp_status_t, bool)") at assert.c:101
#4  0x0000000000f441ea in rec_get_converted_size_comp_prefix_low (index=0x7fe1e4020958, fields=0x7fe1e401f7c0, n_fields=9, extra=0x0, status=REC_STATUS_ORDINARY, temp=false) at /home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc:1122
#5  0x0000000000f44f0f in rec_get_converted_size_comp (index=0x7fe1e4020958, status=REC_STATUS_ORDINARY, fields=0x7fe1e401f7c0, n_fields=9, extra=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc:1227
#6  0x0000000001104aba in rec_get_converted_size (index=0x7fe1e4020958, dtuple=0x7fe1e401f778, n_ext=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/rem0rec.ic:1402
#7  0x000000000110329e in btr_cur_optimistic_insert (flags=0, cursor=0x7fe25004a708, offsets=0x7fe250049fc8, heap=0x7fe25004a228, entry=0x7fe1e401f778, rec=0x7fe250049f60, big_rec=0x7fe25004a6f0, n_ext=0, thr=0x7fe1e40536e8, mtr=0x7fe25004a238) at /home/midenok/src/mariadb/10.3/src/storage/innobase/btr/btr0cur.cc:3307
#8  0x0000000000f72b72 in row_ins_clust_index_entry_low (flags=0, mode=2, index=0x7fe1e4020958, n_uniq=0, entry=0x7fe1e401f778, n_ext=0, thr=0x7fe1e40536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:2779
#9  0x0000000000f7763f in row_ins_clust_index_entry (index=0x7fe1e4020958, entry=0x7fe1e401f778, thr=0x7fe1e40536e8, n_ext=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3235
#10 0x0000000000f808a1 in row_ins_index_entry (index=0x7fe1e4020958, entry=0x7fe1e401f778, thr=0x7fe1e40536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3360
#11 0x0000000000f7fda5 in row_ins_index_entry_step (node=0x7fe1e405a270, thr=0x7fe1e40536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3510
#12 0x0000000000f789a0 in row_ins (node=0x7fe1e405a270, thr=0x7fe1e40536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3646
#13 0x0000000000f785a3 in row_ins_step (thr=0x7fe1e40536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3789
#14 0x0000000000fab120 in row_update_vers_insert (thr=0x7fe1e40536e8, node=0x7fe1e4024f18) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2214

Divergence is on #10 0x0000000000f808a1 in row_ins_index_entry (row0ins.cc:3360)

    if (index->is_primary()) {
        return row_ins_clust_index_entry(index, entry, thr, 0);
    } else {
        return row_ins_sec_index_entry(index, entry, thr);
    }

Cause

DATA_FTS_DOC_ID is not unique bit mask, any type like MYSQL_TYPE_TIMESTAMP includes it.

Fix

Check also column name for FTS_DOC_ID_COL_NAME.

Current status

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0x00007efc94215535 in __GI_abort () at abort.c:79
#2  0x00007efc9421540f in __assert_fail_base (fmt=0x7efc943a3588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x176407d "!(col->prtype & 256U)", file=0x1762b50 "/home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc", line=1122, function=<optimized out>) at assert.c:92
#3  0x00007efc94225012 in __GI___assert_fail (assertion=0x176407d "!(col->prtype & 256U)", file=0x1762b50 "/home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc", line=1122, function=0x1763ece "ulint rec_get_converted_size_comp_prefix_low(const dict_index_t *, const dfield_t *, ulint, ulint *, rec_comp_status_t, bool)") at assert.c:101
#4  0x0000000000f441ea in rec_get_converted_size_comp_prefix_low (index=0x7efc28020958, fields=0x7efc2801f7c0, n_fields=9, extra=0x0, status=REC_STATUS_ORDINARY, temp=false) at /home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc:1122
#5  0x0000000000f44f0f in rec_get_converted_size_comp (index=0x7efc28020958, status=REC_STATUS_ORDINARY, fields=0x7efc2801f7c0, n_fields=9, extra=0x0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/rem/rem0rec.cc:1227
#6  0x0000000001104afa in rec_get_converted_size (index=0x7efc28020958, dtuple=0x7efc2801f778, n_ext=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/include/rem0rec.ic:1402
#7  0x00000000011032de in btr_cur_optimistic_insert (flags=0, cursor=0x7efc840f26f8, offsets=0x7efc840f1fb8, heap=0x7efc840f2218, entry=0x7efc2801f778, rec=0x7efc840f1f50, big_rec=0x7efc840f26e0, n_ext=0, thr=0x7efc280536e8, mtr=0x7efc840f2228) at /home/midenok/src/mariadb/10.3/src/storage/innobase/btr/btr0cur.cc:3307
#8  0x0000000000f72b72 in row_ins_clust_index_entry_low (flags=0, mode=2, index=0x7efc28020958, n_uniq=0, entry=0x7efc2801f778, n_ext=0, thr=0x7efc280536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:2779
#9  0x0000000000f7763f in row_ins_clust_index_entry (index=0x7efc28020958, entry=0x7efc2801f778, thr=0x7efc280536e8, n_ext=0) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3235
#10 0x0000000000f808a1 in row_ins_index_entry (index=0x7efc28020958, entry=0x7efc2801f778, thr=0x7efc280536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3360
#11 0x0000000000f7fda5 in row_ins_index_entry_step (node=0x7efc2805a270, thr=0x7efc280536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3510
#12 0x0000000000f789a0 in row_ins (node=0x7efc2805a270, thr=0x7efc280536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3646
#13 0x0000000000f785a3 in row_ins_step (thr=0x7efc280536e8) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0ins.cc:3789
#14 0x0000000000fab16c in row_update_vers_insert (thr=0x7efc280536e8, node=0x7efc28024f18) at /home/midenok/src/mariadb/10.3/src/storage/innobase/row/row0mysql.cc:2218

What next:

On duplicate FTS_DOC_ID skip silently if this is history record.

midenok commented 4 years ago

Fix

Skip adding to FTS_DOC_ID_INDEX for history record.

--- a/storage/innobase/row/row0ins.cc
+++ b/storage/innobase/row/row0ins.cc
@@ -3642,7 +3642,12 @@ row_ins(
        ut_ad(node->state == INS_NODE_INSERT_ENTRIES);

        while (node->index != NULL) {
-               if (node->index->type != DICT_FTS) {
+               dict_index_t *index = node->index;
+               if (index->type != DICT_FTS && (
+                       !node->vers_history_row()
+                       || !dict_index_is_unique(index)
+                       || dict_index_get_n_unique(index) > 1
+                       || strcmp(index->name, FTS_DOC_ID_INDEX_NAME))) {
                        dberr_t err = row_ins_index_entry_step(node, thr);

                        if (err != DB_SUCCESS) {

This solves FTS problem.