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

Pushdown from having: Item_field::type_handler

Details

    • Bug
    • Status: Confirmed (View Workflow)
    • Major
    • Resolution: Unresolved
    • 11.1.2, 11.2.1, 10.6, 10.9(EOL), 10.10(EOL), 10.11, 11.0(EOL), 11.1(EOL), 11.2(EOL)
    • 10.6, 10.11
    • Optimizer
    • Ubuntu 20.04 x86-64, docker image mariadb:11.1.2

    Description

      PoC:

      SELECT * 
      FROM 
        ( SELECT 1 x ) ss 
      GROUP BY x 
      HAVING 
        ( ( ( ( SELECT x 
                HAVING 
                  ( ( 'x' IN ( SELECT x ) ) ) 
        ) ) ) ) 
        AND x;
      

      docker log:

      mariadbd(my_print_stacktrace+0x32)[0x5639ce23f7c2]
      mariadbd(handle_fatal_signal+0x488)[0x5639cdd18cf8]
      /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7fb20c1ee520]
      mariadbd(_ZNK10Item_field12type_handlerEv+0xc)[0x5639cdd47adc]
      mariadbd(_ZN8Item_ref10check_colsEj+0x25)[0x5639cda3bcf5]
      mariadbd(_ZN8Item_ref10fix_fieldsEP3THDPP4Item+0xd1)[0x5639cdd44d61]
      mariadbd(_ZN10Item_field10fix_fieldsEP3THDPP4Item+0x83f)[0x5639cdd44a9f]
      mariadbd(_ZN9Item_func10fix_fieldsEP3THDPP4Item+0x8c)[0x5639cdd89fec]
      mariadbd(_ZN13st_select_lex31pushdown_from_having_into_whereEP3THDP4Item+0x17a)[0x5639cda8ed7a]
      mariadbd(_ZN4JOIN14optimize_innerEv+0x992)[0x5639cdb24e52]
      mariadbd(_ZN4JOIN8optimizeEv+0xda)[0x5639cdb25e2a]
      mariadbd(_Z12mysql_selectP3THDP10TABLE_LISTR4ListI4ItemEPS4_jP8st_orderS9_S7_S9_yP13select_resultP18st_select_lex_unitP13st_select_lex+0xd1)[0x5639cdb25f21]
      mariadbd(_Z13handle_selectP3THDP3LEXP13select_resulty+0x154)[0x5639cdb26774]
      mariadbd(+0x826f55)[0x5639cda99f55]
      mariadbd(_Z21mysql_execute_commandP3THDb+0x419e)[0x5639cdaa8f0e]
      mariadbd(_Z11mysql_parseP3THDPcjP12Parser_state+0x1e7)[0x5639cdaaa237]
      mariadbd(_Z16dispatch_command19enum_server_commandP3THDPcjb+0x14bd)[0x5639cdaaca1d]
      mariadbd(_Z10do_commandP3THDb+0x138)[0x5639cdaae818]
      mariadbd(_Z24do_handle_one_connectionP7CONNECTb+0x3bf)[0x5639cdbd63af]
      mariadbd(handle_one_connection+0x5d)[0x5639cdbd66fd]
      mariadbd(+0xcd1906)[0x5639cdf44906]
      /lib/x86_64-linux-gnu/libc.so.6(+0x94b43)[0x7fb20c240b43]
      /lib/x86_64-linux-gnu/libc.so.6(clone+0x44)[0x7fb20c2d1bb4]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x7fb1a80130d8): SELECT * FROM ( SELECT 1 x ) ss GROUP BY x HAVING ( ( ( ( SELECT x HAVING ( ( 'x' IN ( SELECT x ) ) ) ) ) ) ) AND x
       
      Connection ID (thread ID): 4
      Status: NOT_KILLED
       
      Optimizer switch: index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,index_merge_sort_intersection=off,engine_condition_pushdown=off,index_condition_pushdown=on,derived_merge=on,derived_with_keys=on,firstmatch=on,loosescan=on,materialization=on,in_to_exists=on,semijoin=on,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=off,mrr_cost_based=off,mrr_sort_keys=off,outer_join_with_cache=on,semijoin_with_cache=on,join_cache_incremental=on,join_cache_hashed=on,join_cache_bka=on,optimize_join_buffer_size=on,table_elimination=on,extended_keys=on,exists_to_in=on,orderby_uses_equalities=on,condition_pushdown_for_derived=on,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off,hash_join_cardinality=on
      

      Attachments

        Issue Links

          Activity

            alice Alice Sherepa added a comment -

            Thank you!
            Reproducible as described on 10.6-11.2, with optimizer_switch='condition_pushdown_from_having=on'

            Version: '10.6.16-MariaDB-debug-log' 
            231009 12:43:01 [ERROR] mysqld got signal 11 ;
             
            Server version: 10.6.16-MariaDB-debug-log source revision: 8941bdc4748a94c1207723d86a8e46df8ae129b3
             
            sql/signal_handler.cc:241(handle_fatal_signal)[0x5644e14a4f76]
            sigaction.c:0(__restore_rt)[0x7f3bd96b5420]
            sql/item.h:3625(Item_field::type_handler() const)[0x5644e155e8e8]
            sql/item.h:5594(Item_ref::type_handler() const)[0x5644e0a99789]
            sql/item.h:1276(Item::result_type() const)[0x5644e0959d94]
            sql/item.h:5696(Item_ref::check_cols(unsigned int))[0x5644e0a9b1b0]
            sql/item.cc:8205(Item_ref::fix_fields(THD*, Item**))[0x5644e154091c]
            sql/item.cc:6062(Item_field::fix_fields(THD*, Item**))[0x5644e153034b]
            sql/item.h:1150(Item::fix_fields_if_needed(THD*, Item**))[0x5644e0959c7b]
            sql/item_func.cc:350(Item_func::fix_fields(THD*, Item**))[0x5644e1600d58]
            sql/sql_lex.cc:11168(st_select_lex::pushdown_from_having_into_where(THD*, Item*))[0x5644e0bcb618]
            sql/sql_select.cc:2285(JOIN::optimize_inner())[0x5644e0cd8775]
            sql/sql_select.cc:1868(JOIN::optimize())[0x5644e0cd3d21]
            sql/sql_select.cc:5077(mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x5644e0cf58ae]
            sql/sql_select.cc:559(handle_select(THD*, LEX*, select_result*, unsigned long))[0x5644e0cc5539]
            sql/sql_parse.cc:6285(execute_sqlcom_select(THD*, TABLE_LIST*))[0x5644e0c25f4e]
            sql/sql_parse.cc:3961(mysql_execute_command(THD*, bool))[0x5644e0c1491d]
            sql/sql_parse.cc:8050(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x5644e0c312f1]
            sql/sql_parse.cc:1898(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x5644e0c06fcd]
            sql/sql_parse.cc:1409(do_command(THD*, bool))[0x5644e0c03d0e]
            sql/sql_connect.cc:1416(do_handle_one_connection(CONNECT*, bool))[0x5644e10843e1]
            sql/sql_connect.cc:1320(handle_one_connection)[0x5644e1083d3e]
            perfschema/pfs.cc:2203(pfs_spawn_thread)[0x5644e1d240fa]
            nptl/pthread_create.c:478(start_thread)[0x7f3bd96a9609]
             
            Query (0x62b0000c42a8): SELECT * FROM ( SELECT 1 x ) ss 
            GROUP BY x 
            HAVING ( ( ( ( SELECT x HAVING ( ( 'x' IN ( SELECT x ) ) ) ) ) ) ) AND x
            
            

            alice Alice Sherepa added a comment - Thank you! Reproducible as described on 10.6-11.2, with optimizer_switch='condition_pushdown_from_having=on' Version: '10.6.16-MariaDB-debug-log' 231009 12:43:01 [ERROR] mysqld got signal 11 ;   Server version: 10.6.16-MariaDB-debug-log source revision: 8941bdc4748a94c1207723d86a8e46df8ae129b3   sql/signal_handler.cc:241(handle_fatal_signal)[0x5644e14a4f76] sigaction.c:0(__restore_rt)[0x7f3bd96b5420] sql/item.h:3625(Item_field::type_handler() const)[0x5644e155e8e8] sql/item.h:5594(Item_ref::type_handler() const)[0x5644e0a99789] sql/item.h:1276(Item::result_type() const)[0x5644e0959d94] sql/item.h:5696(Item_ref::check_cols(unsigned int))[0x5644e0a9b1b0] sql/item.cc:8205(Item_ref::fix_fields(THD*, Item**))[0x5644e154091c] sql/item.cc:6062(Item_field::fix_fields(THD*, Item**))[0x5644e153034b] sql/item.h:1150(Item::fix_fields_if_needed(THD*, Item**))[0x5644e0959c7b] sql/item_func.cc:350(Item_func::fix_fields(THD*, Item**))[0x5644e1600d58] sql/sql_lex.cc:11168(st_select_lex::pushdown_from_having_into_where(THD*, Item*))[0x5644e0bcb618] sql/sql_select.cc:2285(JOIN::optimize_inner())[0x5644e0cd8775] sql/sql_select.cc:1868(JOIN::optimize())[0x5644e0cd3d21] sql/sql_select.cc:5077(mysql_select(THD*, TABLE_LIST*, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x5644e0cf58ae] sql/sql_select.cc:559(handle_select(THD*, LEX*, select_result*, unsigned long))[0x5644e0cc5539] sql/sql_parse.cc:6285(execute_sqlcom_select(THD*, TABLE_LIST*))[0x5644e0c25f4e] sql/sql_parse.cc:3961(mysql_execute_command(THD*, bool))[0x5644e0c1491d] sql/sql_parse.cc:8050(mysql_parse(THD*, char*, unsigned int, Parser_state*))[0x5644e0c312f1] sql/sql_parse.cc:1898(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool))[0x5644e0c06fcd] sql/sql_parse.cc:1409(do_command(THD*, bool))[0x5644e0c03d0e] sql/sql_connect.cc:1416(do_handle_one_connection(CONNECT*, bool))[0x5644e10843e1] sql/sql_connect.cc:1320(handle_one_connection)[0x5644e1083d3e] perfschema/pfs.cc:2203(pfs_spawn_thread)[0x5644e1d240fa] nptl/pthread_create.c:478(start_thread)[0x7f3bd96a9609]   Query (0x62b0000c42a8): SELECT * FROM ( SELECT 1 x ) ss GROUP BY x HAVING ( ( ( ( SELECT x HAVING ( ( 'x' IN ( SELECT x ) ) ) ) ) ) ) AND x
            alice Alice Sherepa added a comment -

            please check also the test from MDEV-32719:

            CREATE TABLE x ( x BOOLEAN ) ;
            INSERT INTO x ( x ) VALUES ( 1 ) ;
            UPDATE x SET x = NULL WHERE x = ( SELECT 'x' / 'x' WHERE NULL BETWEEN ( SELECT x AS x FROM x AS x GROUP BY x ) AND 1 ) ;
            INSERT INTO x ( x ) VALUES ( 1 ) , ( 1 ) ;
            SELECT ( 1 + 1 ) / 1 AS x WHERE EXISTS ( SELECT 1 FROM ( SELECT x FROM x UNION SELECT x FROM x WHERE x < ( SELECT x FROM x GROUP BY x + 1 , x ) ) AS x WHERE x IN ( SELECT x FROM ( SELECT x = 'x' AND x = 1 FROM x WHERE x < ( WITH x AS ( SELECT NOT ( SELECT 1 WHERE ( SELECT x FROM x WHERE x != 1 GROUP BY x ) != x ) FROM x ) SELECT x FROM x GROUP BY x + 1 , x ) UNION SELECT x FROM x ) AS x GROUP BY x , x HAVING ( x IN ( SELECT x WHERE x = 'x' AND x IN ( SELECT x FROM x WHERE x = 'x' ) GROUP BY x HAVING ( x IN ( SELECT x WHERE x = 'x' AND x IN ( SELECT x FROM x WHERE x = 'x' ) ) AND x IS NULL AND x IN ( 1 , x = 1 AND x IN ( x NOT IN ( SELECT x ) ) , 1 , 1 , 1 ) ) ) AND x IS NULL AND x IN ( 1 , x = 1 AND x IN ( x NOT IN ( SELECT x FROM x ) ) , 1 , 1 , 1 ) ) ) ) ;
            

            alice Alice Sherepa added a comment - please check also the test from MDEV-32719 : CREATE TABLE x ( x BOOLEAN ) ; INSERT INTO x ( x ) VALUES ( 1 ) ; UPDATE x SET x = NULL WHERE x = ( SELECT 'x' / 'x' WHERE NULL BETWEEN ( SELECT x AS x FROM x AS x GROUP BY x ) AND 1 ) ; INSERT INTO x ( x ) VALUES ( 1 ) , ( 1 ) ; SELECT ( 1 + 1 ) / 1 AS x WHERE EXISTS ( SELECT 1 FROM ( SELECT x FROM x UNION SELECT x FROM x WHERE x < ( SELECT x FROM x GROUP BY x + 1 , x ) ) AS x WHERE x IN ( SELECT x FROM ( SELECT x = 'x' AND x = 1 FROM x WHERE x < ( WITH x AS ( SELECT NOT ( SELECT 1 WHERE ( SELECT x FROM x WHERE x != 1 GROUP BY x ) != x ) FROM x ) SELECT x FROM x GROUP BY x + 1 , x ) UNION SELECT x FROM x ) AS x GROUP BY x , x HAVING ( x IN ( SELECT x WHERE x = 'x' AND x IN ( SELECT x FROM x WHERE x = 'x' ) GROUP BY x HAVING ( x IN ( SELECT x WHERE x = 'x' AND x IN ( SELECT x FROM x WHERE x = 'x' ) ) AND x IS NULL AND x IN ( 1 , x = 1 AND x IN ( x NOT IN ( SELECT x ) ) , 1 , 1 , 1 ) ) ) AND x IS NULL AND x IN ( 1 , x = 1 AND x IN ( x NOT IN ( SELECT x FROM x ) ) , 1 , 1 , 1 ) ) ) ) ;

            People

              igor Igor Babaev
              fuboat Jingzhou Fu
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.