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

Crash in join optimizer with constant outer join nest

    XMLWordPrintable

    Details

      Description

      Note: Could be related to MDEV-21781.

      Initial issue title: Server crashes in JOIN::fix_all_splittings_in_plan or Assertion `join->best_read < double(1.79769313486231570815e+308L)' failed with not_null_range_scan=on

      CREATE TABLE t1 (a INT) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1),(2);
       
      CREATE TABLE t2 (b INT) ENGINE=MyISAM;
      INSERT INTO t2 VALUES (3),(4);
       
      CREATE TABLE t3 (c INT, KEY(c)) ENGINE=MyISAM;
       
      CREATE TABLE t4 (d INT, KEY(d)) ENGINE=MyISAM;
      INSERT INTO t4 VALUES (5),(6);
       
      CREATE TABLE t5 (e INT) ENGINE=MyISAM;
      INSERT INTO t5 VALUES (7),(8);
       
      CREATE TABLE t6 (f INT) ENGINE=MyISAM;
      INSERT INTO t6 VALUES (9),(10);
       
      SET SESSION optimizer_switch= 'not_null_range_scan=on';
       
      SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN ( t3 JOIN t4 ON t3.c = t4.d ) ON t2.b >= t4.d ON t1.a <= t2.b LEFT JOIN t5 ON t2.b = t5.e LEFT JOIN t6 ON t3.c = t6.f;
      

      10.5 non-debug 17a7bafe

      #3  <signal handler called>
      #4  JOIN::fix_all_splittings_in_plan (this=this@entry=0x7efef8055308) at /data/src/10.5/sql/opt_split.cc:1155
      #5  0x00005647767e7e1a in JOIN::optimize_inner (this=this@entry=0x7efef8055308) at /data/src/10.5/sql/sql_select.cc:2253
      #6  0x00005647767e8513 in JOIN::optimize (this=this@entry=0x7efef8055308) at /data/src/10.5/sql/sql_select.cc:1612
      #7  0x00005647767e8611 in mysql_select (thd=thd@entry=0x7efef80009b8, tables=0x7efef8010aa8, fields=..., conds=0x0, og_num=<optimized out>, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7efef80552e0, unit=0x7efef8004810, select_lex=0x7efef80104b0) at /data/src/10.5/sql/sql_select.cc:4635
      #8  0x00005647767e9014 in handle_select (thd=thd@entry=0x7efef80009b8, lex=lex@entry=0x7efef8004748, result=result@entry=0x7efef80552e0, setup_tables_done_option=setup_tables_done_option@entry=0) at /data/src/10.5/sql/sql_select.cc:429
      #9  0x000056477666e189 in execute_sqlcom_select (thd=thd@entry=0x7efef80009b8, all_tables=0x7efef8010aa8) at /data/src/10.5/sql/sql_parse.cc:6208
      #10 0x000056477678a648 in mysql_execute_command (thd=thd@entry=0x7efef80009b8) at /data/src/10.5/sql/sql_parse.cc:3939
      #11 0x00005647767913fc in mysql_parse (thd=thd@entry=0x7efef80009b8, rawbuf=<optimized out>, length=157, parser_state=parser_state@entry=0x7eff088a3500, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.5/sql/sql_parse.cc:7992
      #12 0x0000564776787238 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7efef80009b8, packet=packet@entry=0x7efef8007c79 "SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN ( t3 JOIN t4 ON t3.c = t4.d ) ON t2.b >= t4.d ON t1.a <= t2.b LEFT JOIN t5 ON t2.b = t5.e LEFT JOIN t6 ON t3.c = t6.f", packet_length=packet_length@entry=157, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/src/10.5/sql/sql_parse.cc:1875
      #13 0x00005647767855ee in do_command (thd=0x7efef80009b8) at /data/src/10.5/sql/sql_parse.cc:1356
      #14 0x000056477687c390 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x56477934d988, put_in_cache=put_in_cache@entry=true) at /data/src/10.5/sql/sql_connect.cc:1411
      #15 0x000056477687c9f4 in handle_one_connection (arg=arg@entry=0x56477934d988) at /data/src/10.5/sql/sql_connect.cc:1313
      #16 0x0000564776be7d11 in pfs_spawn_thread (arg=0x5647793263f8) at /data/src/10.5/storage/perfschema/pfs.cc:2201
      #17 0x00007eff0ef5d4a4 in start_thread (arg=0x7eff088a4700) at pthread_create.c:456
      #18 0x00007eff0dfdbd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      10.5 17a7bafe debug

      mariadbd: /data/src/10.5/sql/sql_select.cc:8733: bool greedy_search(JOIN*, table_map, uint, uint, uint): Assertion `join->best_read < double(1.79769313486231570815e+308L)' failed.
      200610 20:49:22 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007f40c9f4ef12 in __GI___assert_fail (assertion=0x55d79ad15740 "join->best_read < double(1.79769313486231570815e+308L)", file=0x55d79ad14358 "/data/src/10.5/sql/sql_select.cc", line=8733, function=0x55d79ad19280 <greedy_search(JOIN*, unsigned long long, unsigned int, unsigned int, unsigned int)::__PRETTY_FUNCTION__> "bool greedy_search(JOIN*, table_map, uint, uint, uint)") at assert.c:101
      #8  0x000055d799fbd8f4 in greedy_search (join=0x7f40b4225568, remaining_tables=51, search_depth=62, prune_level=1, use_cond_selectivity=4) at /data/src/10.5/sql/sql_select.cc:8733
      #9  0x000055d799fbca98 in choose_plan (join=0x7f40b4225568, join_tables=51) at /data/src/10.5/sql/sql_select.cc:8290
      #10 0x000055d799fb442f in make_join_statistics (join=0x7f40b4225568, tables_list=..., keyuse_array=0x7f40b4225858) at /data/src/10.5/sql/sql_select.cc:5535
      #11 0x000055d799fa8234 in JOIN::optimize_inner (this=0x7f40b4225568) at /data/src/10.5/sql/sql_select.cc:2236
      #12 0x000055d799fa5d4c in JOIN::optimize (this=0x7f40b4225568) at /data/src/10.5/sql/sql_select.cc:1612
      #13 0x000055d799fb1009 in mysql_select (thd=0x7f40b4000b18, tables=0x7f40b40140e8, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f40b4225540, unit=0x7f40b4004b30, select_lex=0x7f40b4013af0) at /data/src/10.5/sql/sql_select.cc:4635
      #14 0x000055d799fa0d86 in handle_select (thd=0x7f40b4000b18, lex=0x7f40b4004a68, result=0x7f40b4225540, setup_tables_done_option=0) at /data/src/10.5/sql/sql_select.cc:429
      #15 0x000055d799f663db in execute_sqlcom_select (thd=0x7f40b4000b18, all_tables=0x7f40b40140e8) at /data/src/10.5/sql/sql_parse.cc:6208
      #16 0x000055d799f5d70f in mysql_execute_command (thd=0x7f40b4000b18) at /data/src/10.5/sql/sql_parse.cc:3939
      #17 0x000055d799f6b227 in mysql_parse (thd=0x7f40b4000b18, rawbuf=0x7f40b4013950 "SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN ( t3 JOIN t4 ON t3.c = t4.d ) ON t2.b >= t4.d ON t1.a <= t2.b LEFT JOIN t5 ON t2.b = t5.e LEFT JOIN t6 ON t3.c = t6.f", length=157, parser_state=0x7f40c4aec520, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:7992
      #18 0x000055d799f575ad in dispatch_command (command=COM_QUERY, thd=0x7f40b4000b18, packet=0x7f40b41b0679 "SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN ( t3 JOIN t4 ON t3.c = t4.d ) ON t2.b >= t4.d ON t1.a <= t2.b LEFT JOIN t5 ON t2.b = t5.e LEFT JOIN t6 ON t3.c = t6.f", packet_length=157, is_com_multi=false, is_next_command=false) at /data/src/10.5/sql/sql_parse.cc:1875
      #19 0x000055d799f55ce5 in do_command (thd=0x7f40b4000b18) at /data/src/10.5/sql/sql_parse.cc:1356
      #20 0x000055d79a0fa6cf in do_handle_one_connection (connect=0x55d79dbeda98, put_in_cache=true) at /data/src/10.5/sql/sql_connect.cc:1411
      #21 0x000055d79a0fa437 in handle_one_connection (arg=0x55d79dbe0ae8) at /data/src/10.5/sql/sql_connect.cc:1313
      #22 0x000055d79a63360e in pfs_spawn_thread (arg=0x55d79dac9468) at /data/src/10.5/storage/perfschema/pfs.cc:2201
      #23 0x00007f40cbed74a4 in start_thread (arg=0x7f40c4aed700) at pthread_create.c:456
      #24 0x00007f40ca00bd0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      EXPLAIN also crashes.
      Without not_null_range_scan the query returns the same result as MySQL 5.6-8.0, different ordering aside:

      SELECT * FROM t1 LEFT JOIN t2 LEFT JOIN ( t3 JOIN t4 ON t3.c = t4.d ) ON t2.b >= t4.d ON t1.a <= t2.b LEFT JOIN t5 ON t2.b = t5.e LEFT JOIN t6 ON t3.c = t6.f;
      a	b	c	d	e	f
      1	3	NULL	NULL	NULL	NULL
      1	4	NULL	NULL	NULL	NULL
      2	3	NULL	NULL	NULL	NULL
      2	4	NULL	NULL	NULL	NULL
      

        Attachments

          Activity

            People

            Assignee:
            psergey Sergei Petrunia
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: