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

Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_tables

Details

    • 10.2.12, 10.2.14

    Description

      10.2 ca3c8d9b58fdc267b

      mysqld: /data/src/10.2/sql/sql_base.cc:2153: void Locked_tables_list::unlock_locked_tables(THD*): Assertion `thd->transaction.stmt.is_empty()' failed.
      170926 17:12:24 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f4a73b09ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
      #8  0x000055baadf8c00a in Locked_tables_list::unlock_locked_tables (this=0x7f4a10004510, thd=0x7f4a10000b00) at /data/src/10.2/sql/sql_base.cc:2153
      #9  0x000055baadf8c08f in Locked_tables_list::unlock_locked_table (this=0x7f4a10004510, thd=0x7f4a10000b00, mdl_ticket=0x0) at /data/src/10.2/sql/sql_base.cc:2196
      #10 0x000055baae0c61f4 in mysql_create_table (thd=0x7f4a10000b00, create_table=0x7f4a10012588, create_info=0x7f4a64762920, alter_info=0x7f4a64762870) at /data/src/10.2/sql/sql_table.cc:5121
      #11 0x000055baadffeabd in mysql_execute_command (thd=0x7f4a10000b00) at /data/src/10.2/sql/sql_parse.cc:3966
      #12 0x000055baae00b24a in mysql_parse (thd=0x7f4a10000b00, rawbuf=0x7f4a10012438 "CREATE OR REPLACE TEMPORARY TABLE t1 (d INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED", length=80, parser_state=0x7f4a64763200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7875
      #13 0x000055baadff8efb in dispatch_command (command=COM_QUERY, thd=0x7f4a10000b00, packet=0x7f4a1013ea71 "CREATE OR REPLACE TEMPORARY TABLE t1 (d INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED", packet_length=80, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1812
      #14 0x000055baadff7875 in do_command (thd=0x7f4a10000b00) at /data/src/10.2/sql/sql_parse.cc:1360
      #15 0x000055baae144ae1 in do_handle_one_connection (connect=0x55bab2530340) at /data/src/10.2/sql/sql_connect.cc:1354
      #16 0x000055baae14486e in handle_one_connection (arg=0x55bab2530340) at /data/src/10.2/sql/sql_connect.cc:1260
      #17 0x000055baae561616 in pfs_spawn_thread (arg=0x55bab253a8b0) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #18 0x00007f4a75a4e494 in start_thread (arg=0x7f4a64764700) at pthread_create.c:333
      #19 0x00007f4a73bc693f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      --source include/have_innodb.inc
       
      CREATE TEMPORARY TABLE t1 (a INT) ENGINE=InnoDB;
      CREATE TEMPORARY TABLE t2 (b INT, c INT) ENGINE=InnoDB ROW_FORMAT=COMPACT;
      LOCK TABLE t2 WRITE;
      ALTER TABLE t2 DROP COLUMN c;
      CREATE OR REPLACE TEMPORARY TABLE t1 (d INT) ENGINE=InnoDB ROW_FORMAT=COMPRESSED;
      

      Reproducible on older 10.2 builds too.
      First noticed some time around MDEV-10813 development.
      No visible problems on non-debug builds.

      Attachments

        Issue Links

          Activity

            Fix for the first issue pushed to 10.2.12.

            Second issue: ALTER TABLE fails due to duplicate key error. Then we try to reopen table and do parse_vcol_defs(), which constructs string like "PARSE_VCOL_EXPR current_timestamp(0)" and then it errors our because field->default_value->expr is not set.

            svoj Sergey Vojtovich added a comment - Fix for the first issue pushed to 10.2.12. Second issue: ALTER TABLE fails due to duplicate key error. Then we try to reopen table and do parse_vcol_defs(), which constructs string like "PARSE_VCOL_EXPR current_timestamp(0)" and then it errors our because field->default_value->expr is not set.

            The second bug is triggered with the following test case:

            --source include/have_innodb.inc
             
            CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB;
            INSERT INTO t1 (i) VALUES (1),(1);
            LOCK TABLE t1 WRITE;
            --error 1062
            ALTER TABLE t1 ADD UNIQUE(i);
             
            # Cleanup
            UNLOCK TABLES;
            DROP TABLE t1;
            

            ALTER TABLE fails due to "duplicate keys" error. Since we're under LOCK TABLES, we need to reopen tables after failing ALTER TABLE. Then eventually we call Item_func::fix_fields() with thd->is_error() set (duplicate keys). The following code cannot handle this situation:

            Item_func::fix_fields()
            {
            ...
              fix_length_and_dec();
              if (thd->is_error()) // An error inside fix_length_and_dec occurred
                return TRUE;
            ...
            }
            

            It appears to be introduced by 691b7584.

            Stack trace to that code:

            #0  Item_func::fix_fields (this=0x7fffa402b9e0, thd=0x7fffa4000b00, ref=0x7fffa402bae8) at /home/svoj/devel/maria/mariadb/sql/item_func.cc:202
            #1  0x0000555555e67481 in Item_func_now::fix_fields (this=0x7fffa402b9e0, thd=0x7fffa4000b00, items=0x7fffa402bae8) at /home/svoj/devel/maria/mariadb/sql/item_timefunc.cc:1725
            #2  0x0000555555c0a34d in fix_vcol_expr (thd=0x7fffa4000b00, vcol=0x7fffa402bad8) at /home/svoj/devel/maria/mariadb/sql/table.cc:2745
            #3  0x0000555555c0a74a in fix_and_check_vcol_expr (thd=0x7fffa4000b00, table=0x7fffa403b6a0, vcol=0x7fffa402bad8) at /home/svoj/devel/maria/mariadb/sql/table.cc:2830
            #4  0x0000555555c0aba9 in unpack_vcol_info_from_frm (thd=0x7fffa4000b00, mem_root=0x7fffa403c158, table=0x7fffa403b6a0, expr_str=0x7ffff0093a70, vcol_ptr=0x7fffa402b850, error_reported=0x7ffff0093df9) at /home/svoj/devel/maria/mariadb/sql/table.cc:2949
            #5  0x0000555555c045e3 in parse_vcol_defs (thd=0x7fffa4000b00, mem_root=0x7fffa403c158, table=0x7fffa403b6a0, error_reported=0x7ffff0093df9) at /home/svoj/devel/maria/mariadb/sql/table.cc:1109
            #6  0x0000555555c0b85a in open_table_from_share (thd=0x7fffa4000b00, share=0x7fffa401e9c8, alias=0x7fffa402c448 "t1", db_stat=33, prgflag=8, ha_open_flags=16, outparam=0x7fffa403b6a0, is_create_table=false) at /home/svoj/devel/maria/mariadb/sql/table.cc:3183
            #7  0x0000555555a96ab6 in open_table (thd=0x7fffa4000b00, table_list=0x7fffa402be28, ot_ctx=0x7ffff0094240) at /home/svoj/devel/maria/mariadb/sql/sql_base.cc:1877
            #8  0x0000555555a978f1 in Locked_tables_list::reopen_tables (this=0x7fffa4004518, thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_base.cc:2362
            #9  0x0000555555bd8357 in mysql_inplace_alter_table (thd=0x7fffa4000b00, table_list=0x7fffa4012680, table=0x7fffa4027ed0, altered_table=0x7fffa402f560, ha_alter_info=0x7ffff0094490, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE,
                target_mdl_request=0x7ffff0094500, alter_ctx=0x7ffff00950c0) at /home/svoj/devel/maria/mariadb/sql/sql_table.cc:7458
            #10 0x0000555555bdd4a5 in mysql_alter_table (thd=0x7fffa4000b00, new_db=0x7fffa4012c90 "test", new_name=0x0, create_info=0x7ffff0095cd0, table_list=0x7fffa4012680, alter_info=0x7ffff0095c20, order_num=0, order=0x0, ignore=false)
                at /home/svoj/devel/maria/mariadb/sql/sql_table.cc:9351
            #11 0x0000555555c56f0b in Sql_cmd_alter_table::execute (this=0x7fffa4012d58, thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_alter.cc:324
            #12 0x0000555555b12543 in mysql_execute_command (thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:6208
            #13 0x0000555555b171c6 in mysql_parse (thd=0x7fffa4000b00, rawbuf=0x7fffa4012598 "ALTER TABLE t1 ADD UNIQUE(i)", length=28, parser_state=0x7ffff0097080, is_com_multi=false, is_next_command=false) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:7902
            #14 0x0000555555b04c09 in dispatch_command (command=COM_QUERY, thd=0x7fffa4000b00, packet=0x7fffa4008951 "ALTER TABLE t1 ADD UNIQUE(i)", packet_length=28, is_com_multi=false, is_next_command=false) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:1806
            #15 0x0000555555b034bd in do_command (thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:1360
            #16 0x0000555555c51c3e in do_handle_one_connection (connect=0x5555580934b0) at /home/svoj/devel/maria/mariadb/sql/sql_connect.cc:1335
            #17 0x0000555555c51991 in handle_one_connection (arg=0x5555580934b0) at /home/svoj/devel/maria/mariadb/sql/sql_connect.cc:1241
            #18 0x0000555555f9e1e0 in pfs_spawn_thread (arg=0x555557ff7110) at /home/svoj/devel/maria/mariadb/storage/perfschema/pfs.cc:1862
            #19 0x00007ffff68a96ba in start_thread (arg=0x7ffff0098700) at pthread_create.c:333
            #20 0x00007ffff5d3e41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109
            

            svoj Sergey Vojtovich added a comment - The second bug is triggered with the following test case: --source include/have_innodb.inc   CREATE TABLE t1 (d DATETIME DEFAULT CURRENT_TIMESTAMP, i INT) ENGINE=InnoDB; INSERT INTO t1 (i) VALUES (1),(1); LOCK TABLE t1 WRITE; --error 1062 ALTER TABLE t1 ADD UNIQUE(i);   # Cleanup UNLOCK TABLES; DROP TABLE t1; ALTER TABLE fails due to "duplicate keys" error. Since we're under LOCK TABLES, we need to reopen tables after failing ALTER TABLE. Then eventually we call Item_func::fix_fields() with thd->is_error() set (duplicate keys). The following code cannot handle this situation: Item_func::fix_fields() { ... fix_length_and_dec(); if (thd->is_error()) // An error inside fix_length_and_dec occurred return TRUE; ... } It appears to be introduced by 691b7584. Stack trace to that code: #0 Item_func::fix_fields (this=0x7fffa402b9e0, thd=0x7fffa4000b00, ref=0x7fffa402bae8) at /home/svoj/devel/maria/mariadb/sql/item_func.cc:202 #1 0x0000555555e67481 in Item_func_now::fix_fields (this=0x7fffa402b9e0, thd=0x7fffa4000b00, items=0x7fffa402bae8) at /home/svoj/devel/maria/mariadb/sql/item_timefunc.cc:1725 #2 0x0000555555c0a34d in fix_vcol_expr (thd=0x7fffa4000b00, vcol=0x7fffa402bad8) at /home/svoj/devel/maria/mariadb/sql/table.cc:2745 #3 0x0000555555c0a74a in fix_and_check_vcol_expr (thd=0x7fffa4000b00, table=0x7fffa403b6a0, vcol=0x7fffa402bad8) at /home/svoj/devel/maria/mariadb/sql/table.cc:2830 #4 0x0000555555c0aba9 in unpack_vcol_info_from_frm (thd=0x7fffa4000b00, mem_root=0x7fffa403c158, table=0x7fffa403b6a0, expr_str=0x7ffff0093a70, vcol_ptr=0x7fffa402b850, error_reported=0x7ffff0093df9) at /home/svoj/devel/maria/mariadb/sql/table.cc:2949 #5 0x0000555555c045e3 in parse_vcol_defs (thd=0x7fffa4000b00, mem_root=0x7fffa403c158, table=0x7fffa403b6a0, error_reported=0x7ffff0093df9) at /home/svoj/devel/maria/mariadb/sql/table.cc:1109 #6 0x0000555555c0b85a in open_table_from_share (thd=0x7fffa4000b00, share=0x7fffa401e9c8, alias=0x7fffa402c448 "t1", db_stat=33, prgflag=8, ha_open_flags=16, outparam=0x7fffa403b6a0, is_create_table=false) at /home/svoj/devel/maria/mariadb/sql/table.cc:3183 #7 0x0000555555a96ab6 in open_table (thd=0x7fffa4000b00, table_list=0x7fffa402be28, ot_ctx=0x7ffff0094240) at /home/svoj/devel/maria/mariadb/sql/sql_base.cc:1877 #8 0x0000555555a978f1 in Locked_tables_list::reopen_tables (this=0x7fffa4004518, thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_base.cc:2362 #9 0x0000555555bd8357 in mysql_inplace_alter_table (thd=0x7fffa4000b00, table_list=0x7fffa4012680, table=0x7fffa4027ed0, altered_table=0x7fffa402f560, ha_alter_info=0x7ffff0094490, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, target_mdl_request=0x7ffff0094500, alter_ctx=0x7ffff00950c0) at /home/svoj/devel/maria/mariadb/sql/sql_table.cc:7458 #10 0x0000555555bdd4a5 in mysql_alter_table (thd=0x7fffa4000b00, new_db=0x7fffa4012c90 "test", new_name=0x0, create_info=0x7ffff0095cd0, table_list=0x7fffa4012680, alter_info=0x7ffff0095c20, order_num=0, order=0x0, ignore=false) at /home/svoj/devel/maria/mariadb/sql/sql_table.cc:9351 #11 0x0000555555c56f0b in Sql_cmd_alter_table::execute (this=0x7fffa4012d58, thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_alter.cc:324 #12 0x0000555555b12543 in mysql_execute_command (thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:6208 #13 0x0000555555b171c6 in mysql_parse (thd=0x7fffa4000b00, rawbuf=0x7fffa4012598 "ALTER TABLE t1 ADD UNIQUE(i)", length=28, parser_state=0x7ffff0097080, is_com_multi=false, is_next_command=false) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:7902 #14 0x0000555555b04c09 in dispatch_command (command=COM_QUERY, thd=0x7fffa4000b00, packet=0x7fffa4008951 "ALTER TABLE t1 ADD UNIQUE(i)", packet_length=28, is_com_multi=false, is_next_command=false) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:1806 #15 0x0000555555b034bd in do_command (thd=0x7fffa4000b00) at /home/svoj/devel/maria/mariadb/sql/sql_parse.cc:1360 #16 0x0000555555c51c3e in do_handle_one_connection (connect=0x5555580934b0) at /home/svoj/devel/maria/mariadb/sql/sql_connect.cc:1335 #17 0x0000555555c51991 in handle_one_connection (arg=0x5555580934b0) at /home/svoj/devel/maria/mariadb/sql/sql_connect.cc:1241 #18 0x0000555555f9e1e0 in pfs_spawn_thread (arg=0x555557ff7110) at /home/svoj/devel/maria/mariadb/storage/perfschema/pfs.cc:1862 #19 0x00007ffff68a96ba in start_thread (arg=0x7ffff0098700) at pthread_create.c:333 #20 0x00007ffff5d3e41d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

            agg_arg_charsets_for_string_result never should be called from fix_length_and_dec because it return operation result
            I see 3 ways to fix it:

            1) add result to fix_length_and_dec
            2) make new virtual method like fix_collations call it before fix_length_and_dec and check return code.
            3) add fix_fieldds for items which now use agg_arg_charsets_for_string_result (the fix_fields will call old_fix_fields this function and fix_length_and_dec again...

            sanja Oleksandr Byelkin added a comment - agg_arg_charsets_for_string_result never should be called from fix_length_and_dec because it return operation result I see 3 ways to fix it: 1) add result to fix_length_and_dec 2) make new virtual method like fix_collations call it before fix_length_and_dec and check return code. 3) add fix_fieldds for items which now use agg_arg_charsets_for_string_result (the fix_fields will call old_fix_fields this function and fix_length_and_dec again...

            revision-id: 46e0c8a921978e7b95adf3f17f3c85b18d9f9ef6 (mariadb-10.2.14-78-g46e0c8a9219)
            parent(s): 9bcd0f5fea8ca26742b10d37b95a966c69909ff1
            author: Oleksandr Byelkin
            committer: Oleksandr Byelkin
            timestamp: 2018-05-08 15:26:26 +0200
            message:

            MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_table

            fix_length_and_dec now return result (error/OK)

            —

            sanja Oleksandr Byelkin added a comment - revision-id: 46e0c8a921978e7b95adf3f17f3c85b18d9f9ef6 (mariadb-10.2.14-78-g46e0c8a9219) parent(s): 9bcd0f5fea8ca26742b10d37b95a966c69909ff1 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-05-08 15:26:26 +0200 message: MDEV-11071 : Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_table fix_length_and_dec now return result (error/OK) —

            revision-id: 71c318372e919e21ccf73e54553fffecb1040f75 (mariadb-10.2.15-56-g71c318372e9)
            parent(s): a79b033b359b882f2fe88051781c6e850bd71780
            author: Oleksandr Byelkin
            committer: Oleksandr Byelkin
            timestamp: 2018-06-14 17:58:33 +0200
            message:

            MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_table

            fix_length_and_dec now return result (error/OK)

            sanja Oleksandr Byelkin added a comment - revision-id: 71c318372e919e21ccf73e54553fffecb1040f75 (mariadb-10.2.15-56-g71c318372e9) parent(s): a79b033b359b882f2fe88051781c6e850bd71780 author: Oleksandr Byelkin committer: Oleksandr Byelkin timestamp: 2018-06-14 17:58:33 +0200 message: MDEV-11071 : Assertion `thd->transaction.stmt.is_empty()' failed in Locked_tables_list::unlock_locked_table fix_length_and_dec now return result (error/OK)

            People

              sanja Oleksandr Byelkin
              elenst Elena Stepanova
              Votes:
              0 Vote for this issue
              Watchers:
              4 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.