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

A subquery causes crash

    XMLWordPrintable

Details

    Description

      The following example causes a crash:

      create or replace database crashTest;
      use crashTest;
      

      create or replace table location (
      location_code varchar(10),
      country_id varchar(10)
      );
      insert into location values ('HKG', 'HK');
      insert into location values ('NYC', 'US');
      insert into location values ('LAX', 'US');
      

      create or replace table cntr_leg (
      container_id varchar(10),
      cntr_activity_type varchar(10),
      cntr_dest varchar(10)
      );
      insert into cntr_leg values ('AAAA1111', 'VSL', 'NYC');
      insert into cntr_leg values ('AAAA1111', 'CUV', 'NYC');
      insert into cntr_leg values ('BBBB2222', 'VSL', 'LAX');
      insert into cntr_leg values ('BBBB2222', 'XYZ', 'LAX');
      

      select
        (select country_id from location where location_code = cl1.cntr_dest) as dest_cntry,
        (select 
           max(container_id) 
         from cntr_leg as cl2 
         where
          cl2.container_id = cl1.container_id and
          cl2.cntr_activity_type = 'CUV' and
          exists (select location_code 
                  from location 
                  where 
                     location_code = cl2.cntr_dest and 
                     country_id = dest_cntry)
         ) as CUV
      from
        cntr_leg cl1;
      

      Crashes as follows:

        [New Thread 0x7fffd979a700 (LWP 3851)]
        mysqld: /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:953: virtual bool Item_subselect::const_item() const: Assertion `thd' failed.
        
        Thread 34 "mysqld" received signal SIGABRT, Aborted.
        [Switching to Thread 0x7fffd979a700 (LWP 3851)]
        __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
        51	../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
      (gdb) wher
        #0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
        #1  0x00007ffff52258b1 in __GI_abort () at abort.c:79
        #2  0x00007ffff521542a in __assert_fail_base (fmt=0x7ffff539ca38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x555556c0b3d6 "thd", file=file@entry=0x555556c0b0a0 "/home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc", line=line@entry=953, function=function@entry=0x555556c0cf80 <Item_subselect::const_item() const::__PRETTY_FUNCTION__> "virtual bool Item_subselect::const_item() const") at assert.c:92
        #3  0x00007ffff52154a2 in __GI___assert_fail (assertion=0x555556c0b3d6 "thd", file=0x555556c0b0a0 "/home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc", line=953, function=0x555556c0cf80 <Item_subselect::const_item() const::__PRETTY_FUNCTION__> "virtual bool Item_subselect::const_item() const") at assert.c:101
        #4  0x00005555561a43bc in Item_subselect::const_item (this=0x7fff680c44e8) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.cc:953
        #5  0x00005555561b836a in Item_in_subselect::const_item (this=0x7fff680c44e8) at /home/psergey/dev-git/10.4-cl2/sql/item_subselect.h:642
        #6  0x0000555555cdc65c in Used_tables_and_const_cache::used_tables_and_const_cache_join (this=0x7fff680bce78, item=0x7fff680c44e8) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5020
        #7  0x0000555555cdc6ba in Used_tables_and_const_cache::used_tables_and_const_cache_update_and_join (this=0x7fff680bce78, item=0x7fff680c44e8) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5025
        #8  0x0000555555cdc704 in Used_tables_and_const_cache::used_tables_and_const_cache_update_and_join (this=0x7fff680bce78, argc=2, argv=0x7fff680bce60) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5036
        #9  0x0000555555cddcb8 in Item_func::update_used_tables (this=0x7fff680bcdd0) at /home/psergey/dev-git/10.4-cl2/sql/item_func.h:160
        #10 0x0000555555cdc6a7 in Used_tables_and_const_cache::used_tables_and_const_cache_update_and_join (this=0x7fff68015c00, item=0x7fff680bcdd0) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5024
        #11 0x0000555556124b75 in Used_tables_and_const_cache::used_tables_and_const_cache_update_and_join (this=0x7fff68015c00, list=...) at /home/psergey/dev-git/10.4-cl2/sql/item.h:5049
        #12 0x0000555556129390 in Item_cond::update_used_tables (this=0x7fff68015b58) at /home/psergey/dev-git/10.4-cl2/sql/item_cmpfunc.h:2993
        #13 0x0000555555d3be12 in st_select_lex::update_used_tables (this=0x7fff68014488) at /home/psergey/dev-git/10.4-cl2/sql/sql_lex.cc:4598
        #14 0x0000555555d3b150 in st_select_lex::optimize_unflattened_subqueries (this=0x7fff680124d8, const_only=false) at /home/psergey/dev-git/10.4-cl2/sql/sql_lex.cc:4202
        #15 0x0000555555f5a444 in JOIN::optimize_unflattened_subqueries (this=0x7fff680ba858) at /home/psergey/dev-git/10.4-cl2/sql/opt_subselect.cc:5520
        #16 0x0000555555db99db in JOIN::optimize_stage2 (this=0x7fff680ba858) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:2833
        #17 0x0000555555db7956 in JOIN::optimize_inner (this=0x7fff680ba858) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:2289
        #18 0x0000555555db51a2 in JOIN::optimize (this=0x7fff680ba858) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:1610
        #19 0x0000555555dc064a in mysql_select (thd=0x7fff68000d50, tables=0x7fff680b99a0, wild_num=0, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7fff68018100, unit=0x7fff68004c78, select_lex=0x7fff680124d8) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:4673
        #20 0x0000555555db01b5 in handle_select (thd=0x7fff68000d50, lex=0x7fff68004bb8, result=0x7fff68018100, setup_tables_done_option=0) at /home/psergey/dev-git/10.4-cl2/sql/sql_select.cc:410
        #21 0x0000555555d76ae1 in execute_sqlcom_select (thd=0x7fff68000d50, all_tables=0x7fff680b99a0) at /home/psergey/dev-git/10.4-cl2/sql/sql_parse.cc:6358
        #22 0x0000555555d6d10c in mysql_execute_command (thd=0x7fff68000d50) at /home/psergey/dev-git/10.4-cl2/sql/sql_parse.cc:3890
        #23 0x0000555555d7aa7f in mysql_parse (thd=0x7fff68000d50, rawbuf=0x7fff680121a8 "select\n(select country_id from location where location_code = cl1.cntr_dest) as dest_cntry,\n\n(select max(container_id) from cntr_leg as cl2 where\ncl2.container_id = cl1.container_id and\ncl2.cntr_activ"..., length=353, parser_state=0x7fffd9799550, is_com_multi=false, is_next_command=false) at /home/psergey/dev-git/10.4-cl2/sql/sql_parse.cc:7899
      

      Stack trace from the original report :

      Server version: 10.4.11-MariaDB
      ...
      Thread pointer: 0xb4fd85a738
      Attempting backtrace. You can use the following information to find out
      where mysqld died. If you see no messages after this, something went
      terribly wrong...
      mysqld.exe!Item_subselect::const_item()[item_subselect.cc:954]
      mysqld.exe!Item_in_subselect::const_item()[item_subselect.h:642]
      mysqld.exe!Used_tables_and_const_cache::used_tables_and_const_cache_update_and_join()[item.h:4982]
      mysqld.exe!Item_cond::update_used_tables()[item_cmpfunc.h:2992]
      mysqld.exe!st_select_lex::update_used_tables()[sql_lex.cc:4586]
      mysqld.exe!st_select_lex::optimize_unflattened_subqueries()[sql_lex.cc:4190]
      mysqld.exe!JOIN::optimize_stage2()[sql_select.cc:2810]
      mysqld.exe!JOIN::optimize_inner()[sql_select.cc:2274]
      mysqld.exe!JOIN::optimize()[sql_select.cc:1600]
      mysqld.exe!mysql_select()[sql_select.cc:4646]
      mysqld.exe!handle_select()[sql_select.cc:408]
      mysqld.exe!execute_sqlcom_select()[sql_parse.cc:6360]
      mysqld.exe!mysql_execute_command()[sql_parse.cc:3899]
      mysqld.exe!mysql_parse()[sql_parse.cc:7906]
      mysqld.exe!dispatch_command()[sql_parse.cc:1844]
      mysqld.exe!do_command()[sql_parse.cc:1359]
      mysqld.exe!threadpool_process_request()[threadpool_common.cc:366]
      mysqld.exe!tp_callback()[threadpool_common.cc:193]
      ntdll.dll!RtlFreeUnicodeString()
      ntdll.dll!RtlFreeUnicodeString()
      KERNEL32.DLL!BaseThreadInitThunk()
      ntdll.dll!RtlUserThreadStart()
      

      Attachments

        Issue Links

          Activity

            People

              psergei Sergei Petrunia
              psergei Sergei Petrunia
              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.