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

Potential corruption on Foreign key update on a table with vcol index




      I have added an assertion to ensure that the correct table is chosen in innodb_find_table_for_vc:

      --- a/storage/innobase/handler/ha_innodb.cc
      +++ b/storage/innobase/handler/ha_innodb.cc
      @@ -20007,6 +20007,9 @@
       	} else {
       		if (table->vc_templ->mysql_table_query_id
       		    == thd_get_query_id(thd)) {
      +			DEBUG_SYNC(thd, "find_table_for_vc_table_valid");
      +                        DBUG_ASSERT(table->vc_templ->mysql_table_query_id
      +                                    == thd_get_query_id(thd));
       			return table->vc_templ->mysql_table;

      This is important, since the table is thread-local data.

      The above assertion fails with the following test:

      --source include/have_debug_sync.inc
      --source include/have_innodb.inc
      --source include/have_sequence.inc
      --connect (con2, localhost, root,,)
      --connection default
      set default_storage_engine= innodb;
      create table t1 (a int primary key);
      insert into t1(a) select * from seq_1_to_65536;
      create table t2 (a int,  b int as (a), key(b), foreign key (a) references t1 (a)
        on delete cascade on update cascade);
      insert into t2(a) select * from seq_1_to_65536;
      set debug_sync= "find_table_for_vc_table_valid SIGNAL found WAIT_FOR go";
      UPDATE t1 set a = a + 1000000 where a <= 2;
      --connection con2
      set debug_sync= "now WAIT_FOR found TIMEOUT 3";
      UPDATE t1 set a= 330000 where a = 33333;
      set debug_sync= "now SIGNAL go";
      --connection default
      # Cleanup
      drop table t2, t1;
      set debug_sync= reset;
      --connection default

      I believe we need enough rows to have more that one leaf page in the tree, to avoid a row lock timeout.

      The best way to fix it is to put mysql_table to a threadlocal data as well. A good place can be row_prebuilt_t (and table is already there): to access child prebuilt, parent prebuilt should contain references to it, we can fill it on open under certain conditions, or on demand


        Issue Links



              nikitamalyavin Nikita Malyavin
              nikitamalyavin Nikita Malyavin
              1 Vote for this issue
              8 Start watching this issue



                Git Integration

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