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

Assertion `used_tables_cache == 0' failed in Item_func::fix_fields with condition_pushdown_from_having

    XMLWordPrintable

    Details

      Description

      SET optimizer_switch='condition_pushdown_from_having=on';
       
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (1),(2);
       
      CREATE TABLE t2 (b INT);
      INSERT INTO t2 VALUES (2),(3);
       
      SELECT a FROM t1 GROUP BY a HAVING a = 8 OR a = ( SELECT MIN(b) FROM t2 );
       
      # Cleanup
      DROP TABLE t1, t2;
      

      10.4 a3b63b8d

      mysqld: /data/src/10.4/sql/item_func.cc:328: virtual bool Item_func::fix_fields(THD*, Item**): Assertion `used_tables_cache == 0' failed.
      191201  0:29:59 [ERROR] mysqld got signal 6 ;
       
      #7  0x00007ff69f024f12 in __GI___assert_fail (assertion=0x5624c9042ff8 "used_tables_cache == 0", file=0x5624c9042fd8 "/data/src/10.4/sql/item_func.cc", line=328, function=0x5624c9043f60 <Item_func::fix_fields(THD*, Item**)::__PRETTY_FUNCTION__> "virtual bool Item_func::fix_fields(THD*, Item**)") at assert.c:101
      #8  0x00005624c8592648 in Item_func::fix_fields (this=0x7ff650073530, thd=0x7ff650000af0, ref=0x7ff6500754b8) at /data/src/10.4/sql/item_func.cc:328
      #9  0x00005624c80963eb in Item::fix_fields_if_needed (this=0x7ff650073530, thd=0x7ff650000af0, ref=0x7ff6500754b8) at /data/src/10.4/sql/item.h:956
      #10 0x00005624c8096419 in Item::fix_fields_if_needed_for_scalar (this=0x7ff650073530, thd=0x7ff650000af0, ref=0x7ff6500754b8) at /data/src/10.4/sql/item.h:960
      #11 0x00005624c811aa67 in Item::fix_fields_if_needed_for_bool (this=0x7ff650073530, thd=0x7ff650000af0, ref=0x7ff6500754b8) at /data/src/10.4/sql/item.h:964
      #12 0x00005624c85609c4 in Item_cond::fix_fields (this=0x7ff6500753c0, thd=0x7ff650000af0, ref=0x0) at /data/src/10.4/sql/item_cmpfunc.cc:4845
      #13 0x00005624c823123e in make_cond_for_table_from_pred (thd=0x7ff650000af0, root_cond=0x7ff650015f18, cond=0x7ff650015f18, tables=4611686018427387905, used_table=0, join_tab_idx_arg=0, exclude_expensive_cond=false, retain_ref_cond=false, is_top_and_level=true) at /data/src/10.4/sql/sql_select.cc:22180
      #14 0x00005624c8230d65 in make_cond_for_table (thd=0x7ff650000af0, cond=0x7ff650015f18, tables=4611686018427387905, used_table=0, join_tab_idx_arg=0, exclude_expensive_cond=false, retain_ref_cond=false) at /data/src/10.4/sql/sql_select.cc:22075
      #15 0x00005624c81fab63 in JOIN::add_having_as_table_cond (this=0x7ff650016928, tab=0x7ff6500747c0) at /data/src/10.4/sql/sql_select.cc:3035
      #16 0x00005624c81fd094 in JOIN::make_aggr_tables_info (this=0x7ff650016928) at /data/src/10.4/sql/sql_select.cc:3582
      #17 0x00005624c81fa79f in JOIN::optimize_stage2 (this=0x7ff650016928) at /data/src/10.4/sql/sql_select.cc:2958
      #18 0x00005624c81f7fee in JOIN::optimize_inner (this=0x7ff650016928) at /data/src/10.4/sql/sql_select.cc:2256
      #19 0x00005624c81f595c in JOIN::optimize (this=0x7ff650016928) at /data/src/10.4/sql/sql_select.cc:1593
      #20 0x00005624c8200c60 in mysql_select (thd=0x7ff650000af0, tables=0x7ff6500137f8, wild_num=0, fields=..., conds=0x0, og_num=1, order=0x0, group=0x7ff650013fd8, having=0x7ff650015f18, proc_param=0x0, select_options=2147748608, result=0x7ff650016900, unit=0x7ff650004a20, select_lex=0x7ff650013230) at /data/src/10.4/sql/sql_select.cc:4628
      #21 0x00005624c81f0958 in handle_select (thd=0x7ff650000af0, lex=0x7ff650004958, result=0x7ff650016900, setup_tables_done_option=0) at /data/src/10.4/sql/sql_select.cc:420
      #22 0x00005624c81b70d1 in execute_sqlcom_select (thd=0x7ff650000af0, all_tables=0x7ff6500137f8) at /data/src/10.4/sql/sql_parse.cc:6360
      #23 0x00005624c81ac77f in mysql_execute_command (thd=0x7ff650000af0) at /data/src/10.4/sql/sql_parse.cc:3899
      #24 0x00005624c81bb1dd in mysql_parse (thd=0x7ff650000af0, rawbuf=0x7ff650013138 "SELECT a FROM t1 GROUP BY a HAVING a = 8 OR a = ( SELECT MIN(b) FROM t2 )", length=73, parser_state=0x7ff6983f5170, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:7901
      #25 0x00005624c81a6382 in dispatch_command (command=COM_QUERY, thd=0x7ff650000af0, packet=0x7ff65019e7c1 "SELECT a FROM t1 GROUP BY a HAVING a = 8 OR a = ( SELECT MIN(b) FROM t2 )", packet_length=73, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1842
      #26 0x00005624c81a4a0f in do_command (thd=0x7ff650000af0) at /data/src/10.4/sql/sql_parse.cc:1360
      #27 0x00005624c832d3cd in do_handle_one_connection (connect=0x5624cc555500) at /data/src/10.4/sql/sql_connect.cc:1412
      #28 0x00005624c832d11c in handle_one_connection (arg=0x5624cc555500) at /data/src/10.4/sql/sql_connect.cc:1316
      #29 0x00005624c8d2f2ff in pfs_spawn_thread (arg=0x5624cc4d3440) at /data/src/10.4/storage/perfschema/pfs.cc:1862
      #30 0x00007ff6a0b9a4a4 in start_thread (arg=0x7ff6983f6700) at pthread_create.c:456
      #31 0x00007ff69f0e1d0f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:97
      

      Reproducible with at least MyISAM, InnoDB, Aria.
      Reproducible on 10.4-10.5 debug builds.
      EXPLAIN on a debug build also crashes.
      Not reproducible with condition_pushdown_from_having=off.
      No obvious problem on a non-debug build.
      EXPLAIN on a non-debug build returns

      id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
      1	PRIMARY	t1	ALL	NULL	NULL	NULL	NULL	2	100.00	Using temporary; Using filesort
      2	SUBQUERY	t2	ALL	NULL	NULL	NULL	NULL	2	100.00	
      Warnings:
      Note	1003	/* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` group by `test`.`t1`.`a` having 1
      

       

        Attachments

          Activity

            People

            Assignee:
            igor Igor Babaev
            Reporter:
            elenst Elena Stepanova
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: