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

Server crash in in handler::ha_external_lock or Assertion `inited==RND' failed in handler::ha_rnd_end upon SELECT from partitioned table

Details

    Description

      The test case is sporadic, run with --repeat=N (with high enough N). Can also try ASAN, it doesn't add anything to the result, but changes the dynamics._

      # Run with --repeat=N
       
      --source include/have_innodb.inc
      --source include/have_partition.inc
       
      SET @stats.save= @@innodb_stats_persistent;
      SET GLOBAL innodb_stats_persistent= ON;
       
      CREATE TABLE t1 (a INT) ENGINE=InnoDB;
      CREATE TABLE t2 (
        pk INT AUTO_INCREMENT,
        i INT,
        t1 TIME,
        t2 TIME,
        d1 DATETIME,
        d2 DATETIME,
        v1 VARCHAR(1),
        v2 VARCHAR(1),
        PRIMARY KEY (pk),
        KEY (i)
      ) ENGINE=InnoDB;
       
      BEGIN;
      SELECT * FROM t1;
       
      --connect (con1,localhost,root,,test)
       
      ALTER TABLE t2 PARTITION BY KEY() PARTITIONS 5;
       
      INSERT INTO t2 (i,t1,t2,d1,d2,v1,v2) VALUES
        (7, '01:39:40', '01:39:40', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'w', 'w'),
        (2, '18:14:11', '18:14:11', '1980-03-03 15:06:11', '1980-03-03 15:06:11', 'e', 'e'),
        (2, '03:28:55', '03:28:55', '2025-06-03 03:14:33', '2025-06-03 03:14:33', 'a', 'a'),
        (4, '15:00:03', '15:00:03', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'r', 'r'),
        (6, '17:10:27', '17:10:27', '2014-04-18 18:00:26', '2014-04-18 18:00:26', 'k', 'k'),
        (6, '09:50:22', '09:50:22', '2026-10-20 00:00:00', '2026-10-20 00:00:00', 'c', 'c'),
        (8, '00:00:00', '00:00:00', '2010-07-24 13:01:33', '2010-07-24 13:01:33', 'k', 'k'),
        (4, '09:51:13', '09:51:13', '2006-04-14 03:38:00', '2006-04-14 03:38:00', 'x', 'x'),
        (2, '11:25:28', '11:25:28', '2012-12-12 12:12:12', '2012-12-12 12:12:12', 'j', 'j'),
        (8, '11:11:11', '11:11:11', '1973-07-16 03:25:43', '1973-07-16 03:25:43', 't', 't'),
        (1, '11:14:24', '11:14:24', '1981-12-12 08:27:15', '1981-12-12 08:27:15', 'n', 'n'),
        (6, '04:00:47', '04:00:47', '2022-11-25 18:24:30', '2022-11-25 18:24:30', 'z', 'z'),
        (3, '21:22:12', '21:22:12', '1991-07-28 18:41:31', '1991-07-28 18:41:31', 'u', 'u'),
        (2, '14:29:11', '14:29:11', '2034-09-25 22:51:04', '2034-09-25 22:51:04', 'a', 'a'),
        (3, '16:23:38', '16:23:38', '1900-01-01 00:00:00', '1900-01-01 00:00:00', 'g', 'g'),
        (4, '20:06:35', '20:06:35', '2011-01-11 07:21:24', '2011-01-11 07:21:24', 'f', 'f'),
        (6, '19:33:10', '19:33:10', '1979-09-15 17:25:04', '1979-09-15 17:25:04', 'p', 'p'),
        (0, '08:51:41', '08:51:41', '2008-01-07 21:23:06', '2008-01-07 21:23:06', 'm', 'm'),
        (8, '22:40:20', '22:40:20', '1974-11-12 05:56:02', '1974-11-12 05:56:02', 't', 't'),
        (5, '13:00:50', '13:00:50', '2000-08-27 08:22:13', '2000-08-27 08:22:13', 'i', 'i'),
        (4, '22:22:22', '12:12:12', '2015-02-27 00:00:00', '2015-02-27 00:00:00', 'h', 'h'),
        (2, '12:54:06', '12:54:06', '1996-09-27 12:06:03', '1996-09-27 12:06:03', 'd', 'd'),
        (3, '22:47:40', '22:47:40', '2029-07-13 16:52:43', '2029-07-13 16:52:43', 'b', 'b'),
        (7, '03:01:56', '03:01:56', '1973-10-13 00:00:00', '1973-10-13 00:00:00', 'o', 'o'),
        (1, '12:35:21', '12:35:21', '2025-12-02 00:57:31', '2025-12-02 00:57:31', 'j', 'j'),
        (1, '00:00:00', '00:00:00', '1978-03-12 09:48:05', '1978-03-12 09:48:05', 's', 's');
       
      --connection default
      --error 0,ER_TABLE_DEF_CHANGED
      SELECT * FROM t2 WHERE pk != 0 AND i = 0;
       
      DROP TABLE t1, t2;
      SET GLOBAL innodb_stats_persistent= @stats.save;
      

      10.0 6aff5fa27a

      mysqld: /data/src/10.0/sql/handler.h:2672: int handler::ha_rnd_end(): Assertion `inited==RND' failed.
      180330 23:55:41 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f91585c0ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
      #8  0x00000000005e47a7 in handler::ha_rnd_end (this=0x7f9144883888) at /data/src/10.0/sql/handler.h:2672
      #9  0x000000000094be7f in QUICK_ROR_INTERSECT_SELECT::~QUICK_ROR_INTERSECT_SELECT (this=0x7f9144859d80, __in_chrg=<optimized out>) at /data/src/10.0/sql/opt_range.cc:2288
      #10 0x000000000094bedc in QUICK_ROR_INTERSECT_SELECT::~QUICK_ROR_INTERSECT_SELECT (this=0x7f9144859d80, __in_chrg=<optimized out>) at /data/src/10.0/sql/opt_range.cc:2290
      #11 0x000000000094a8c7 in SQL_SELECT::cleanup (this=0x7f914491eb88) at /data/src/10.0/sql/opt_range.cc:1800
      #12 0x000000000094a94e in SQL_SELECT::~SQL_SELECT (this=0x7f914491eb88, __in_chrg=<optimized out>) at /data/src/10.0/sql/opt_range.cc:1814
      #13 0x000000000069e810 in st_join_table::cleanup (this=0x7f914491e260) at /data/src/10.0/sql/sql_select.cc:11449
      #14 0x000000000069f842 in JOIN::cleanup (this=0x7f91449a50d0, full=true) at /data/src/10.0/sql/sql_select.cc:11878
      #15 0x000000000069f456 in JOIN::join_free (this=0x7f91449a50d0) at /data/src/10.0/sql/sql_select.cc:11765
      #16 0x00000000006ad209 in do_select (join=0x7f91449a50d0, fields=0x7f914d341210, table=0x0, procedure=0x0) at /data/src/10.0/sql/sql_select.cc:17668
      #17 0x0000000000689e15 in JOIN::exec_inner (this=0x7f91449a50d0) at /data/src/10.0/sql/sql_select.cc:3108
      #18 0x00000000006872d2 in JOIN::exec (this=0x7f91449a50d0) at /data/src/10.0/sql/sql_select.cc:2394
      #19 0x000000000068a674 in mysql_select (thd=0x7f914d33d070, rref_pointer_array=0x7f914d3413a0, tables=0x7f91449a42a0, wild_num=1, fields=..., conds=0x7f91449a4ed8, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2148797184, result=0x7f91449a50b0, unit=0x7f914d340a08, select_lex=0x7f914d3410f8) at /data/src/10.0/sql/sql_select.cc:3333
      #20 0x00000000006808d2 in handle_select (thd=0x7f914d33d070, lex=0x7f914d340940, result=0x7f91449a50b0, setup_tables_done_option=0) at /data/src/10.0/sql/sql_select.cc:377
      #21 0x000000000065505f in execute_sqlcom_select (thd=0x7f914d33d070, all_tables=0x7f91449a42a0) at /data/src/10.0/sql/sql_parse.cc:5293
      #22 0x000000000064d5f8 in mysql_execute_command (thd=0x7f914d33d070) at /data/src/10.0/sql/sql_parse.cc:2553
      #23 0x0000000000657ce0 in mysql_parse (thd=0x7f914d33d070, rawbuf=0x7f91449a4088 "SELECT * FROM t2 WHERE pk != 0 AND i = 0", length=40, parser_state=0x7f915a686640) at /data/src/10.0/sql/sql_parse.cc:6569
      #24 0x000000000064a81f in dispatch_command (command=COM_QUERY, thd=0x7f914d33d070, packet=0x7f914d382071 "", packet_length=40) at /data/src/10.0/sql/sql_parse.cc:1296
      #25 0x0000000000649b1f in do_command (thd=0x7f914d33d070) at /data/src/10.0/sql/sql_parse.cc:999
      #26 0x0000000000769cf2 in do_handle_one_connection (thd_arg=0x7f914d33d070) at /data/src/10.0/sql/sql_connect.cc:1377
      #27 0x0000000000769a64 in handle_one_connection (arg=0x7f914d33d070) at /data/src/10.0/sql/sql_connect.cc:1292
      #28 0x0000000000aca5dc in pfs_spawn_thread (arg=0x7f914d282270) at /data/src/10.0/storage/perfschema/pfs.cc:1861
      #29 0x00007f915a2c4494 in start_thread (arg=0x7f915a687700) at pthread_create.c:333
      #30 0x00007f915867d93f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      If the same test is repeated long enough on a non-debug version, it eventually causes a crash in bitmap_get_first_set:

      10.2 RelWithDebInfo 861038f2e8

      #2  <signal handler called>
      #3  bitmap_get_first_set (map=0x7fd3040e8a18) at /data/src/10.2/mysys/my_bitmap.c:634
      #4  0x000055bfc7c3a26f in ha_partition::external_lock (this=0x7fd3040e8430, thd=0x7fd3080009a8, lock_type=2) at /data/src/10.2/sql/ha_partition.cc:3780
      #5  0x000055bfc778245c in handler::ha_external_lock (this=0x7fd3040e8430, thd=thd@entry=0x7fd3080009a8, lock_type=lock_type@entry=2) at /data/src/10.2/sql/handler.cc:5887
      #6  0x000055bfc784bdd8 in unlock_external (thd=0x7fd3080009a8, table=0x7fd308010008, count=<optimized out>) at /data/src/10.2/sql/lock.cc:703
      #7  0x000055bfc784c590 in mysql_unlock_read_tables (thd=<optimized out>, sql_lock=0x7fd30800fff0) at /data/src/10.2/sql/lock.cc:480
      #8  0x000055bfc7621187 in JOIN::join_free (this=this@entry=0x7fd308010030) at /data/src/10.2/sql/sql_select.cc:12213
      #9  0x000055bfc763a33c in do_select (procedure=<optimized out>, join=0x7fd308010030) at /data/src/10.2/sql/sql_select.cc:18352
      #10 JOIN::exec_inner (this=this@entry=0x7fd308010030) at /data/src/10.2/sql/sql_select.cc:3621
      #11 0x000055bfc763a619 in JOIN::exec (this=this@entry=0x7fd308010030) at /data/src/10.2/sql/sql_select.cc:3416
      #12 0x000055bfc763a75b in mysql_select (thd=thd@entry=0x7fd3080009a8, tables=0x7fd30800f208, wild_num=1, fields=..., conds=0x7fd30800fe28, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2148797184, result=0x7fd308010010, unit=0x7fd3080043c8, select_lex=0x7fd308004b00) at /data/src/10.2/sql/sql_select.cc:3816
      #13 0x000055bfc763b166 in handle_select (thd=thd@entry=0x7fd3080009a8, lex=lex@entry=0x7fd308004300, result=result@entry=0x7fd308010010, setup_tables_done_option=setup_tables_done_option@entry=0) at /data/src/10.2/sql/sql_select.cc:376
      #14 0x000055bfc75293ef in execute_sqlcom_select (thd=0x7fd3080009a8, all_tables=0x7fd30800f208) at /data/src/10.2/sql/sql_parse.cc:6479
      #15 0x000055bfc75e566e in mysql_execute_command (thd=0x7fd3080009a8) at /data/src/10.2/sql/sql_parse.cc:3485
      #16 0x000055bfc75eb3da in mysql_parse (thd=0x7fd3080009a8, rawbuf=<optimized out>, length=<optimized out>, parser_state=<optimized out>, is_com_multi=<optimized out>, is_next_command=<optimized out>) at /data/src/10.2/sql/sql_parse.cc:8013
      #17 0x000055bfc75eef54 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7fd3080009a8, packet=packet@entry=0x7fd308006ce9 "", packet_length=packet_length@entry=40, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.2/sql/sql_parse.cc:1824
      #18 0x000055bfc75ef989 in do_command (thd=0x7fd3080009a8) at /data/src/10.2/sql/sql_parse.cc:1378
      #19 0x000055bfc76b8834 in do_handle_one_connection (connect=connect@entry=0x55bfca85ad78) at /data/src/10.2/sql/sql_connect.cc:1335
      #20 0x000055bfc76b89d4 in handle_one_connection (arg=arg@entry=0x55bfca85ad78) at /data/src/10.2/sql/sql_connect.cc:1241
      #21 0x000055bfc797c914 in pfs_spawn_thread (arg=0x55bfca81d3d8) at /data/src/10.2/storage/perfschema/pfs.cc:1862
      #22 0x00007fd35c491494 in start_thread (arg=0x7fd34c5f3700) at pthread_create.c:333
      #23 0x00007fd35aa9293f in clone () from /lib/x86_64-linux-gnu/libc.so.6
      

      Attachments

        Issue Links

          Activity

            Also I think the above patch is trying to solve the assert during the execution , the better solution would be to not pick ROR intersect in such a case.

            I think psergey patch in 10.3 with commit f2c418079def should be backported to earlier versions

            varun Varun Gupta (Inactive) added a comment - Also I think the above patch is trying to solve the assert during the execution , the better solution would be to not pick ROR intersect in such a case. I think psergey patch in 10.3 with commit f2c418079def should be backported to earlier versions
            varun Varun Gupta (Inactive) added a comment - - edited

            Here is the test case without partitioned tables

            --source include/have_innodb.inc
            set @optimizer_switch_save= @@optimizer_switch;
            set optimizer_switch='index_merge_sort_intersection=off';
            create table t0 (a int)engine=innodb;
            insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
            create table t1 (
              a int, b int, c int,
              key(a),key(b),key(c)
            )engine=innodb;
            insert into t1
            select A.a+10*B.a, A.a+10*B.a, A.a+10*B.a+100*C.a
            from t0 A, t0 B, t0 C, t0 D where D.a<5;
            set @@global.debug_dbug="+d,ha_index_init_fail";
            select * from t1 where a=10 and b=10;
            DROP TABLE t0,t1;
            

            varun Varun Gupta (Inactive) added a comment - - edited Here is the test case without partitioned tables --source include/have_innodb.inc set @optimizer_switch_save= @@optimizer_switch; set optimizer_switch= 'index_merge_sort_intersection=off' ; create table t0 (a int )engine=innodb; insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1 ( a int , b int , c int , key (a), key (b), key (c) )engine=innodb; insert into t1 select A.a+10*B.a, A.a+10*B.a, A.a+10*B.a+100*C.a from t0 A, t0 B, t0 C, t0 D where D.a<5; set @@ global .debug_dbug= "+d,ha_index_init_fail" ; select * from t1 where a=10 and b=10; DROP TABLE t0,t1;
            • The testcase in the patch doesn't fire for me. varun, is it possible to use the testcase from the previous comment?
            • As far as I understand, the problem in this bug is orthogonal to whatever the commit f2c418079def is solving.
            psergei Sergei Petrunia added a comment - The testcase in the patch doesn't fire for me. varun , is it possible to use the testcase from the previous comment? As far as I understand, the problem in this bug is orthogonal to whatever the commit f2c418079def is solving.

            varun, it is ok to push the fix for this bug with the above "testcase without partitioned tables".

            psergei Sergei Petrunia added a comment - varun , it is ok to push the fix for this bug with the above "testcase without partitioned tables".

            I think it is also ok to backport f2c418079def to the earlier versions.

            psergei Sergei Petrunia added a comment - I think it is also ok to backport f2c418079def to the earlier versions.

            People

              varun Varun Gupta (Inactive)
              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.