Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-29182

Assertion `fld->field_no < table->n_v_def' failed on cascade FK update of table with vcol index in parent

Details

    Description

      --source include/have_debug_sync.inc
      --source include/have_innodb.inc
      --connect (con2, localhost, root,,)
      --connection default
      set default_storage_engine= innodb;
       
       
      create table t1 (a int primary key, b int as (a), key(b));
      insert into t1(a) values (1),(2),(3);
      create table t2 (a int, foreign key (a) references t1 (a)
        on delete cascade on update cascade);
      insert into t2(a) values (1),(2),(3);
      set debug_sync= "find_table_for_vc_table_valid SIGNAL found WAIT_FOR go";
      UPDATE t1 set a = 11 where a = 1;
      --send
      UPDATE t1 set a = 22 where a = 2;
      --connection con2
      set debug_sync= "now WAIT_FOR found TIMEOUT 3";
      UPDATE t1 set a= 33 where a = 3;
      set debug_sync= "now SIGNAL go";
       
      --connection default
      --reap
       
      # Cleanup
      drop table t1, t2;
      set debug_sync= reset;
      --connection default
      

      Attachments

        Issue Links

          Activity

            Stack trace for the reference:

            10.3 66cd1c33

            mysqld: /data/src/10.3/storage/innobase/trx/trx0rec.cc:1075: ulint trx_undo_page_report_modify(buf_block_t*, trx_t*, dict_index_t*, const rec_t*, const rec_offs*, const upd_t*, ulint, const dtuple_t*, mtr_t*): Assertion `fld->field_no < table->n_v_def' failed.
            220925 15:26:39 [ERROR] mysqld got signal 6 ;
             
            #7  0x00007fa5c9c6a662 in __GI___assert_fail (assertion=0x563dc585a600 "fld->field_no < table->n_v_def", file=0x563dc5859500 "/data/src/10.3/storage/innobase/trx/trx0rec.cc", line=1075, function=0x563dc585a280 "ulint trx_undo_page_report_modify(buf_block_t*, trx_t*, dict_index_t*, const rec_t*, const rec_offs*, const upd_t*, ulint, const dtuple_t*, mtr_t*)") at assert.c:101
            #8  0x0000563dc47a1aff in trx_undo_page_report_modify (undo_block=0x7fa5bf9f0180, trx=0x7fa5c02c68b8, index=0x618000049d08, rec=0x7fa5bff4007e "", offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, row=0x0, mtr=0x7fa5b36825e0) at /data/src/10.3/storage/innobase/trx/trx0rec.cc:1075
            #9  0x0000563dc47a7fac in trx_undo_report_row_operation (thr=0x6240001d2188, index=0x618000049d08, clust_entry=0x0, update=0x61a00001c908, cmpl_info=0, rec=0x7fa5bff4007e "", offsets=0x7fa5b3683830, roll_ptr=0x7fa5b3682c70) at /data/src/10.3/storage/innobase/trx/trx0rec.cc:2024
            #10 0x0000563dc48624b6 in btr_cur_upd_lock_and_undo (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, mtr=0x7fa5b3683b10, roll_ptr=0x7fa5b3682c70) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:3807
            #11 0x0000563dc4864167 in btr_cur_update_in_place (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, trx_id=41, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:4119
            #12 0x0000563dc4865cc0 in btr_cur_optimistic_update (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683730, heap=0x7fa5b3683810, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, trx_id=41, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:4347
            #13 0x0000563dc46f05e0 in row_upd_clust_rec (flags=0, node=0x61600005c208, index=0x618000049d08, offsets=0x7fa5b3683830, offsets_heap=0x7fa5b3683810, thr=0x6240001d2188, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/row/row0upd.cc:2892
            #14 0x0000563dc46f243b in row_upd_clust_step (node=0x61600005c208, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3241
            #15 0x0000563dc46f2c53 in row_upd (node=0x61600005c208, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3304
            #16 0x0000563dc46f3bc5 in row_upd_step (thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3448
            #17 0x0000563dc4620d49 in row_update_cascade_for_mysql (thr=0x6240001d2188, node=0x61600005c208, table=0x6190000dad08) at /data/src/10.3/storage/innobase/row/row0mysql.cc:2253
            #18 0x0000563dc45c3c7c in row_ins_foreign_check_on_constraint (thr=0x6240001d2188, foreign=0x61600005a408, pcur=0x7fa5b3684940, entry=0x61600005bf28, mtr=0x7fa5b3684d50) at /data/src/10.3/storage/innobase/row/row0ins.cc:1338
            #19 0x0000563dc45c57fc in row_ins_check_foreign_constraint (check_ref=0, foreign=0x61600005a408, table=0x6190000d5808, entry=0x61600005bf28, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0ins.cc:1762
            #20 0x0000563dc46e241c in row_upd_check_references_constraints (node=0x620000011c18, pcur=0x611000081a00, table=0x6190000d5808, index=0x618000047d08, offsets=0x7fa5b3685500, thr=0x6240001d2188, mtr=0x7fa5b3685b90) at /data/src/10.3/storage/innobase/row/row0upd.cc:298
            #21 0x0000563dc46ef7e9 in row_upd_clust_rec_by_insert (node=0x620000011c18, index=0x618000047d08, thr=0x6240001d2188, referenced=true, foreign=false, mtr=0x7fa5b3685b90) at /data/src/10.3/storage/innobase/row/row0upd.cc:2791
            #22 0x0000563dc46f2361 in row_upd_clust_step (node=0x620000011c18, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3228
            #23 0x0000563dc46f2c53 in row_upd (node=0x620000011c18, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3304
            #24 0x0000563dc46f3bc5 in row_upd_step (thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3448
            #25 0x0000563dc461e3b7 in row_update_for_mysql (prebuilt=0x620000011108) at /data/src/10.3/storage/innobase/row/row0mysql.cc:1827
            #26 0x0000563dc42ed7b5 in ha_innobase::update_row (this=0x61c0000638a8, old_row=0x6190000d75c8 "\375\001", new_row=0x6190000d75b8 "\375\v") at /data/src/10.3/storage/innobase/handler/ha_innodb.cc:8970
            #27 0x0000563dc3da2ab7 in handler::ha_update_row (this=0x61c0000638a8, old_data=0x6190000d75c8 "\375\001", new_data=0x6190000d75b8 "\375\v") at /data/src/10.3/sql/handler.cc:6527
            #28 0x0000563dc38c309a in mysql_update (thd=0x62a0000ba208, table_list=0x62b000000340, fields=..., values=..., conds=0x62b000000da0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7fa5b3687160, updated_return=0x7fa5b3687180) at /data/src/10.3/sql/sql_update.cc:963
            #29 0x0000563dc36208b2 in mysql_execute_command (thd=0x62a0000ba208) at /data/src/10.3/sql/sql_parse.cc:4344
            #30 0x0000563dc36394dc in mysql_parse (thd=0x62a0000ba208, rawbuf=0x62b000000228 "UPDATE t1 set a = 11 where a = 1", length=32, parser_state=0x7fa5b3688a00, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7871
            #31 0x0000563dc3610a82 in dispatch_command (command=COM_QUERY, thd=0x62a0000ba208, packet=0x629000136209 "UPDATE t1 set a = 11 where a = 1", packet_length=32, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1852
            #32 0x0000563dc360d65e in do_command (thd=0x62a0000ba208) at /data/src/10.3/sql/sql_parse.cc:1398
            #33 0x0000563dc39cf068 in do_handle_one_connection (connect=0x6080000010a8) at /data/src/10.3/sql/sql_connect.cc:1403
            #34 0x0000563dc39ce964 in handle_one_connection (arg=0x6080000010a8) at /data/src/10.3/sql/sql_connect.cc:1308
            #35 0x0000563dc4f79a67 in pfs_spawn_thread (arg=0x615000006c08) at /data/src/10.3/storage/perfschema/pfs.cc:1869
            #36 0x00007fa5c9e03ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477
            #37 0x00007fa5c9d33def in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
            

            elenst Elena Stepanova added a comment - Stack trace for the reference: 10.3 66cd1c33 mysqld: /data/src/10.3/storage/innobase/trx/trx0rec.cc:1075: ulint trx_undo_page_report_modify(buf_block_t*, trx_t*, dict_index_t*, const rec_t*, const rec_offs*, const upd_t*, ulint, const dtuple_t*, mtr_t*): Assertion `fld->field_no < table->n_v_def' failed. 220925 15:26:39 [ERROR] mysqld got signal 6 ;   #7 0x00007fa5c9c6a662 in __GI___assert_fail (assertion=0x563dc585a600 "fld->field_no < table->n_v_def", file=0x563dc5859500 "/data/src/10.3/storage/innobase/trx/trx0rec.cc", line=1075, function=0x563dc585a280 "ulint trx_undo_page_report_modify(buf_block_t*, trx_t*, dict_index_t*, const rec_t*, const rec_offs*, const upd_t*, ulint, const dtuple_t*, mtr_t*)") at assert.c:101 #8 0x0000563dc47a1aff in trx_undo_page_report_modify (undo_block=0x7fa5bf9f0180, trx=0x7fa5c02c68b8, index=0x618000049d08, rec=0x7fa5bff4007e "", offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, row=0x0, mtr=0x7fa5b36825e0) at /data/src/10.3/storage/innobase/trx/trx0rec.cc:1075 #9 0x0000563dc47a7fac in trx_undo_report_row_operation (thr=0x6240001d2188, index=0x618000049d08, clust_entry=0x0, update=0x61a00001c908, cmpl_info=0, rec=0x7fa5bff4007e "", offsets=0x7fa5b3683830, roll_ptr=0x7fa5b3682c70) at /data/src/10.3/storage/innobase/trx/trx0rec.cc:2024 #10 0x0000563dc48624b6 in btr_cur_upd_lock_and_undo (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, mtr=0x7fa5b3683b10, roll_ptr=0x7fa5b3682c70) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:3807 #11 0x0000563dc4864167 in btr_cur_update_in_place (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683830, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, trx_id=41, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:4119 #12 0x0000563dc4865cc0 in btr_cur_optimistic_update (flags=2, cursor=0x611000081dc0, offsets=0x7fa5b3683730, heap=0x7fa5b3683810, update=0x61a00001c908, cmpl_info=0, thr=0x6240001d2188, trx_id=41, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/btr/btr0cur.cc:4347 #13 0x0000563dc46f05e0 in row_upd_clust_rec (flags=0, node=0x61600005c208, index=0x618000049d08, offsets=0x7fa5b3683830, offsets_heap=0x7fa5b3683810, thr=0x6240001d2188, mtr=0x7fa5b3683b10) at /data/src/10.3/storage/innobase/row/row0upd.cc:2892 #14 0x0000563dc46f243b in row_upd_clust_step (node=0x61600005c208, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3241 #15 0x0000563dc46f2c53 in row_upd (node=0x61600005c208, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3304 #16 0x0000563dc46f3bc5 in row_upd_step (thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3448 #17 0x0000563dc4620d49 in row_update_cascade_for_mysql (thr=0x6240001d2188, node=0x61600005c208, table=0x6190000dad08) at /data/src/10.3/storage/innobase/row/row0mysql.cc:2253 #18 0x0000563dc45c3c7c in row_ins_foreign_check_on_constraint (thr=0x6240001d2188, foreign=0x61600005a408, pcur=0x7fa5b3684940, entry=0x61600005bf28, mtr=0x7fa5b3684d50) at /data/src/10.3/storage/innobase/row/row0ins.cc:1338 #19 0x0000563dc45c57fc in row_ins_check_foreign_constraint (check_ref=0, foreign=0x61600005a408, table=0x6190000d5808, entry=0x61600005bf28, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0ins.cc:1762 #20 0x0000563dc46e241c in row_upd_check_references_constraints (node=0x620000011c18, pcur=0x611000081a00, table=0x6190000d5808, index=0x618000047d08, offsets=0x7fa5b3685500, thr=0x6240001d2188, mtr=0x7fa5b3685b90) at /data/src/10.3/storage/innobase/row/row0upd.cc:298 #21 0x0000563dc46ef7e9 in row_upd_clust_rec_by_insert (node=0x620000011c18, index=0x618000047d08, thr=0x6240001d2188, referenced=true, foreign=false, mtr=0x7fa5b3685b90) at /data/src/10.3/storage/innobase/row/row0upd.cc:2791 #22 0x0000563dc46f2361 in row_upd_clust_step (node=0x620000011c18, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3228 #23 0x0000563dc46f2c53 in row_upd (node=0x620000011c18, thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3304 #24 0x0000563dc46f3bc5 in row_upd_step (thr=0x6240001d2188) at /data/src/10.3/storage/innobase/row/row0upd.cc:3448 #25 0x0000563dc461e3b7 in row_update_for_mysql (prebuilt=0x620000011108) at /data/src/10.3/storage/innobase/row/row0mysql.cc:1827 #26 0x0000563dc42ed7b5 in ha_innobase::update_row (this=0x61c0000638a8, old_row=0x6190000d75c8 "\375\001", new_row=0x6190000d75b8 "\375\v") at /data/src/10.3/storage/innobase/handler/ha_innodb.cc:8970 #27 0x0000563dc3da2ab7 in handler::ha_update_row (this=0x61c0000638a8, old_data=0x6190000d75c8 "\375\001", new_data=0x6190000d75b8 "\375\v") at /data/src/10.3/sql/handler.cc:6527 #28 0x0000563dc38c309a in mysql_update (thd=0x62a0000ba208, table_list=0x62b000000340, fields=..., values=..., conds=0x62b000000da0, order_num=0, order=0x0, limit=18446744073709551615, ignore=false, found_return=0x7fa5b3687160, updated_return=0x7fa5b3687180) at /data/src/10.3/sql/sql_update.cc:963 #29 0x0000563dc36208b2 in mysql_execute_command (thd=0x62a0000ba208) at /data/src/10.3/sql/sql_parse.cc:4344 #30 0x0000563dc36394dc in mysql_parse (thd=0x62a0000ba208, rawbuf=0x62b000000228 "UPDATE t1 set a = 11 where a = 1", length=32, parser_state=0x7fa5b3688a00, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:7871 #31 0x0000563dc3610a82 in dispatch_command (command=COM_QUERY, thd=0x62a0000ba208, packet=0x629000136209 "UPDATE t1 set a = 11 where a = 1", packet_length=32, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1852 #32 0x0000563dc360d65e in do_command (thd=0x62a0000ba208) at /data/src/10.3/sql/sql_parse.cc:1398 #33 0x0000563dc39cf068 in do_handle_one_connection (connect=0x6080000010a8) at /data/src/10.3/sql/sql_connect.cc:1403 #34 0x0000563dc39ce964 in handle_one_connection (arg=0x6080000010a8) at /data/src/10.3/sql/sql_connect.cc:1308 #35 0x0000563dc4f79a67 in pfs_spawn_thread (arg=0x615000006c08) at /data/src/10.3/storage/perfschema/pfs.cc:1869 #36 0x00007fa5c9e03ea7 in start_thread (arg=<optimized out>) at pthread_create.c:477 #37 0x00007fa5c9d33def in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

            Here is a simpler test case:

            CREATE TABLE t1(a INT PRIMARY KEY, b VARCHAR(3), c INT AS (LENGTH(b)) VIRTUAL,
                            INDEX(c)) ENGINE=InnoDB;
            CREATE TABLE t2(a INT REFERENCES t1(a) ON UPDATE CASCADE,
                            b INT GENERATED ALWAYS AS(a) VIRTUAL, INDEX(b)) ENGINE=InnoDB;
            INSERT INTO t1 SET a=1,b='fu';
            INSERT INTO t2 SET a=1;
            UPDATE t1 SET a=2,b='bar';
            SELECT * FROM t1;
            SELECT * FROM t2;
            DROP TABLE t2,t1;
            

            Fix:

            diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc
            index ca43e9045e1..59a2ebd6830 100644
            --- a/storage/innobase/row/row0ins.cc
            +++ b/storage/innobase/row/row0ins.cc
            @@ -479,7 +479,9 @@ row_ins_cascade_calc_update_vec(
             			const upd_field_t*	parent_ufield
             				= &parent_update->fields[j];
             
            -			if (parent_ufield->field_no == parent_field_no) {
            +			if (parent_ufield->field_no == parent_field_no
            +			    && !(parent_ufield->new_val.type.prtype
            +				 & DATA_VIRTUAL)) {
             
             				ulint			min_size;
             				const dict_col_t*	col;
            

            This is MySQL Bug#33327093 FK: assertion failure in row_MySQL_pad_col.

            marko Marko Mäkelä added a comment - Here is a simpler test case: CREATE TABLE t1(a INT PRIMARY KEY , b VARCHAR (3), c INT AS (LENGTH(b)) VIRTUAL, INDEX (c)) ENGINE=InnoDB; CREATE TABLE t2(a INT REFERENCES t1(a) ON UPDATE CASCADE , b INT GENERATED ALWAYS AS (a) VIRTUAL, INDEX (b)) ENGINE=InnoDB; INSERT INTO t1 SET a=1,b= 'fu' ; INSERT INTO t2 SET a=1; UPDATE t1 SET a=2,b= 'bar' ; SELECT * FROM t1; SELECT * FROM t2; DROP TABLE t2,t1; Fix: diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index ca43e9045e1..59a2ebd6830 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -479,7 +479,9 @@ row_ins_cascade_calc_update_vec( const upd_field_t* parent_ufield = &parent_update->fields[j]; - if (parent_ufield->field_no == parent_field_no) { + if (parent_ufield->field_no == parent_field_no + && !(parent_ufield->new_val.type.prtype + & DATA_VIRTUAL)) { ulint min_size; const dict_col_t* col; This is MySQL Bug#33327093 FK: assertion failure in row_MySQL_pad_col .

            Looks fine at first look. Please go ahead. I will continue checking a few more details. If it is a regression, it would be goof to know when it got introduced.

            debarun Debarun Banerjee added a comment - Looks fine at first look. Please go ahead. I will continue checking a few more details. If it is a regression, it would be goof to know when it got introduced.

            I suspect that this bug was introduced together with indexed virtual columns in MySQL 5.7, also known as MDEV-5800 in MariaDB Server 10.2.

            marko Marko Mäkelä added a comment - I suspect that this bug was introduced together with indexed virtual columns in MySQL 5.7, also known as MDEV-5800 in MariaDB Server 10.2.

            As far as I can tell, this bug only causes a crash and no data corruption (unless there is a bug in crash recovery).

            I checked where exactly the above test case would trigger a crash for CMAKE_BUILD_TYPE=RelWithDebInfo. In a 10.6 branch, it’d hit SIGSEGV due to attempting to dereference a null pointer old_v_val:

            trx_undo_page_report_modify()

            				field = static_cast<byte*>(
            					fld->old_v_val->data);
            				flen = fld->old_v_val->len;
            

            InnoDB is crashing while it is about to write an undo log record for executing the ON UPDATE CASCADE operation. No data in the referencing table will be changed before an undo log record has been written.

            After the crash, depending on how many changes had been written from log_sys.buf to the ib_logfile0, during recovery a subsequently started mariadbd process may observe that the UPDATE had not started at all, or that the transaction is incomplete and has to be rolled back. This is just like how InnoDB should work when the mariadbd process is forcibly killed during workload, for whatever reason.

            marko Marko Mäkelä added a comment - As far as I can tell, this bug only causes a crash and no data corruption (unless there is a bug in crash recovery). I checked where exactly the above test case would trigger a crash for CMAKE_BUILD_TYPE=RelWithDebInfo . In a 10.6 branch, it’d hit SIGSEGV due to attempting to dereference a null pointer old_v_val : trx_undo_page_report_modify() field = static_cast <byte*>( fld->old_v_val->data); flen = fld->old_v_val->len; InnoDB is crashing while it is about to write an undo log record for executing the ON UPDATE CASCADE operation. No data in the referencing table will be changed before an undo log record has been written. After the crash, depending on how many changes had been written from log_sys.buf to the ib_logfile0 , during recovery a subsequently started mariadbd process may observe that the UPDATE had not started at all, or that the transaction is incomplete and has to be rolled back. This is just like how InnoDB should work when the mariadbd process is forcibly killed during workload, for whatever reason.

            People

              marko Marko Mäkelä
              nikitamalyavin Nikita Malyavin
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.