Uploaded image for project: 'Percona Server'
  1. Percona Server
  2. PS-5580

Renaming a TokuDB/RocksDB table with FK while foreign_key_checks is set 0 results in a crash

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Affects Version/s: Not 5.7, 8.0.15-5
    • Fix Version/s: None
    • Component/s: MyRocks, TokuDB
    • Labels:

      Description

      # mysqld options required for replay: --plugin-load-add=RocksDB=ha_rocksdb.so
      CREATE DATABASE test;
      USE test;
      set foreign_key_checks=0;
      CREATE TABLE t1(a int)engine=RocksDB;
      CREATE TABLE t2(id INT KEY,t1_id INT,INDEX par_ind (t1_id,id),FOREIGN KEY(t1_id) REFERENCES t1(id) ON DELETE CASCADE);
      rename table t1 to t5,t2 to t1;
      

      gdb:

      Program terminated with signal 6, Aborted.
      #0  0x00007f02ac8729d1 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
      59        val = INTERNAL_SYSCALL (tgkill, err, 3, THREAD_GETMEM (THREAD_SELF, pid),
      (gdb) bt
      +bt
      #0  0x00007f02ac8729d1 in __pthread_kill (threadid=<optimized out>, signo=6) at ../nptl/sysdeps/unix/sysv/linux/pthread_kill.c:59
      #1  0x000000000448aac5 in my_write_core (sig=6) at /sdc/ps-8.0.15-1204_dbg/mysys/stacktrace.cc:278
      #2  0x000000000343373d in handle_fatal_signal (sig=6) at /sdc/ps-8.0.15-1204_dbg/sql/signal_handler.cc:252
      #3  <signal handler called>
      #4  0x00007f02aa975207 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:55
      #5  0x00007f02aa9768f8 in __GI_abort () at abort.c:90
      #6  0x00000000049bebb7 in ut_dbg_assertion_failed (expr=0x5d707a5 "table2 == NULL", file=0x5d70320 "/sdc/ps-8.0.15-1204_dbg/storage/innobase/dict/dict0dict.cc", line=1234) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/ut/ut0dbg.cc:92
      #7  0x0000000004ac4c72 in dict_table_add_to_cache (table=0x7f0245e19cb8, can_be_evicted=1, heap=0x7f0245c58318) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/dict/dict0dict.cc:1234
      #8  0x0000000004aff6be in dd_open_table_one<dd::Table> (client=0x7f0245c40180, table=0x7f02a9211f20, norm_name=0x7f0245cd0840 "test/t2", dd_table=0x7f0245c163a0, thd=0x7f0245c1a000, fk_list=std::deque with 1 elements = {...}) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/dict/dict0dd.cc:4125
      #9  0x0000000004aecd5f in dd_open_table_one_on_name (name=0x7f0245cd0840 "test/t2", dict_locked=true, fk_list=std::deque with 1 elements = {...}, thd=0x7f0245c1a000) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/dict/dict0dd.cc:4237
      #10 0x0000000004aecf81 in dd_open_fk_tables (fk_list=std::deque with 1 elements = {...}, dict_locked=true, thd=0x7f0245c1a000) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/dict/dict0dd.cc:4273
      #11 0x00000000048a650c in row_rename_table_for_mysql (old_name=0x7f02a9213cc0 "test/t2", new_name=0x7f02a9213ec0 "test/t1", dd_table=0x7f0245c181a0, trx=0x7f0292000a80, replay=false) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/row/row0mysql.cc:4848
      #12 0x00000000046dbbcc in innobase_basic_ddl::rename_impl<dd::Table> (thd=0x7f0245c1a000, from=0x7f02a9214bb0 "./test/t2", to=0x7f02a92149a0 "./test/t1", from_table=0x7f0245c163a0, to_table=0x7f0245c181a0) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/handler/ha_innodb.cc:14024
      #13 0x00000000046bf330 in ha_innobase::rename_table (this=0x7f0245dfc5d0, from=0x7f02a9214bb0 "./test/t2", to=0x7f02a92149a0 "./test/t1", from_table_def=0x7f0245c163a0, to_table_def=0x7f0245c181a0) at /sdc/ps-8.0.15-1204_dbg/storage/innobase/handler/ha_innodb.cc:16004
      #14 0x0000000002ef43e8 in handler::ha_rename_table (this=0x7f0245dfc5d0, from=0x7f02a9214bb0 "./test/t2", to=0x7f02a92149a0 "./test/t1", from_table_def=0x7f0245c163a0, to_table_def=0x7f0245c181a0) at /sdc/ps-8.0.15-1204_dbg/sql/handler.cc:5071
      #15 0x0000000003321801 in mysql_rename_table (thd=0x7f0245c1a000, base=0x7f029bff2920, old_db=0x7f0245e6abf0 "test", old_name=0x7f0245e6a5d0 "t2", old_fk_db=0x7f0245e6abf0 "test", old_fk_name=0x7f0245e6a5d0 "t2", new_schema=..., new_db=0x7f0245ddc5c8 "test", new_name=0x7f0245e6a610 "t1", flags=8) at /sdc/ps-8.0.15-1204_dbg/sql/sql_table.cc:9632
      #16 0x00000000032c05bd in do_rename (thd=0x7f0245c1a000, ren_table=0x7f0245e6a650, new_db=0x7f0245ddc5c8 "test", new_table_name=0x7f0245e6a610 "t1", new_table_alias=0x7f0245e6abf8 "t1", int_commit_done=0x7f02a9215327, post_ddl_htons=0x7f02a92152f0, fk_invalidator=0x7f02a92152c0) at /sdc/ps-8.0.15-1204_dbg/sql/sql_rename.cc:717
      #17 0x00000000032c0c4c in rename_tables (thd=0x7f0245c1a000, table_list=0x7f0245e69a70, int_commit_done=0x7f02a9215327, post_ddl_htons=0x7f02a92152f0, fk_invalidator=0x7f02a92152c0) at /sdc/ps-8.0.15-1204_dbg/sql/sql_rename.cc:866
      #18 0x00000000032bf292 in mysql_rename_tables (thd=0x7f0245c1a000, table_list=0x7f0245e69a70) at /sdc/ps-8.0.15-1204_dbg/sql/sql_rename.cc:326
      #19 0x0000000003271c14 in mysql_execute_command (thd=0x7f0245c1a000, first_level=true) at /sdc/ps-8.0.15-1204_dbg/sql/sql_parse.cc:3442
      #20 0x0000000003277ae1 in mysql_parse (thd=0x7f0245c1a000, parser_state=0x7f02a9216a30, update_userstat=false, force_primary_storage_engine=false) at /sdc/ps-8.0.15-1204_dbg/sql/sql_parse.cc:5333
      #21 0x000000000326d1b5 in dispatch_command (thd=0x7f0245c1a000, com_data=0x7f02a9217b80, command=COM_QUERY) at /sdc/ps-8.0.15-1204_dbg/sql/sql_parse.cc:1760
      #22 0x000000000326b6a2 in do_command (thd=0x7f0245c1a000) at /sdc/ps-8.0.15-1204_dbg/sql/sql_parse.cc:1292
      #23 0x000000000341eefe in handle_connection (arg=0x7f02581f3c80) at /sdc/ps-8.0.15-1204_dbg/sql/conn_handler/connection_handler_per_thread.cc:311
      #24 0x000000000457465c in pfs_spawn_thread (arg=0x7f02583d1520) at /sdc/ps-8.0.15-1204_dbg/storage/perfschema/pfs.cc:2836
      #25 0x00007f02ac86ddd5 in start_thread (arg=0x7f02a9218700) at pthread_create.c:307
      #26 0x00007f02aaa3cead in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
      

      I'm able to reproduce it with both debug and release build in 8.0.15-5.

      Welcome to the MySQL monitor.  Commands end with ; or \g.
      Your MySQL connection id is 31
      Server version: 8.0.15-5 Percona Server (GPL), Release '5', Revision 'f8a9e99'
      
      Copyright (c) 2009-2019 Percona LLC and/or its affiliates
      Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
      
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
      
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      mysql> CREATE DATABASE test;
      Query OK, 1 row affected (0.02 sec)
      
      mysql> USE test;
      Database changed
      mysql> set foreign_key_checks=0;
      Query OK, 0 rows affected (0.01 sec)
      
      mysql> CREATE TABLE t1(a int)engine=RocksDB;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> CREATE TABLE t2(id INT KEY,t1_id INT,INDEX par_ind (t1_id,id),FOREIGN KEY(t1_id) REFERENCES t1(id) ON DELETE CASCADE);
      Query OK, 0 rows affected (0.03 sec)
      
      mysql> rename table t1 to t5,t2 to t1;
      ERROR 2013 (HY000): Lost connection to MySQL server during query
      

      Same thing happens with TokuDB as well:

      mysql> CREATE DATABASE test;
      Query OK, 1 row affected (0.01 sec)
      
      mysql> USE test;
      Database changed
      mysql> set foreign_key_checks=0;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> CREATE TABLE t1(a int)engine=TokuDB;
      Query OK, 0 rows affected (0.02 sec)
      
      mysql> CREATE TABLE t2(id INT KEY,t1_id INT,INDEX par_ind (t1_id,id),FOREIGN KEY(t1_id) REFERENCES t1(id) ON DELETE CASCADE);
      Query OK, 0 rows affected (0.03 sec)
      
      mysql> rename table t1 to t5,t2 to t1;
      ERROR 2013 (HY000): Lost connection to MySQL server during query
      

      Using InnoDB results with the error:

      mysql> USE test;
      Database changed
      mysql> set foreign_key_checks=0;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> CREATE TABLE t1(a int)engine=InnoDB;
      Query OK, 0 rows affected (0.03 sec)
      
      mysql> CREATE TABLE t2(id INT KEY,t1_id INT,INDEX par_ind (t1_id,id),FOREIGN KEY(t1_id) REFERENCES t1(id) ON DELETE CASCADE);
      ERROR 3734 (HY000): Failed to add the foreign key constraint. Missing column 'id' for constraint 't2_ibfk_1' in the referenced table 't1'
      

      5.7.25-28 works ok:

      Server version: 5.7.25-28-log Percona Server (GPL), Release '28', Revision 'c335905'
      
      Copyright (c) 2009-2019 Percona LLC and/or its affiliates
      Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
      
      Oracle is a registered trademark of Oracle Corporation and/or its
      affiliates. Other names may be trademarks of their respective
      owners.
      
      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
      
      mysql> USE test;
      Database changed
      mysql> set foreign_key_checks=0;
      Query OK, 0 rows affected (0.00 sec)
      
      mysql> CREATE TABLE t1(a int)engine=RocksDB;
      Query OK, 0 rows affected (0.01 sec)
      
      mysql> CREATE TABLE t2(id INT KEY,t1_id INT,INDEX par_ind (t1_id,id),FOREIGN KEY(t1_id) REFERENCES t1(id) ON DELETE CASCADE);
      Query OK, 0 rows affected (0.02 sec)
      
      mysql> rename table t1 to t5,t2 to t1;
      Query OK, 0 rows affected (0.02 sec)
      

        Smart Checklist

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                hrvoje.matijakovic Hrvoje Matijakovic
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - Not Specified
                  Not Specified
                  Logged:
                  Time Spent - 2 hours, 40 minutes
                  2h 40m