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

Subselect using index cause crashes

    XMLWordPrintable

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Major
    • Resolution: Unresolved
    • 10.6.9, 10.3(EOL), 10.4(EOL), 10.5, 10.6, 10.7(EOL), 10.8(EOL), 10.9(EOL), 10.10(EOL)
    • 10.5, 10.6, 10.11, 11.4, 11.7
    • Optimizer
    • None
    • Ubuntu 22
      Mariadb 10.6.9

    Description

      By switching to Mariadb 10.6.9, we notice that some requests cause mariadb crashes.
      These crashes seems link with optimizer & subselect.

      Code to reproduce :

      create table applicants
      (
          users_id int unsigned not null primary key
      );
       
      create table missions
      (
          id             int unsigned auto_increment
              primary key,
          offers_id      int unsigned                  not null,
          mission_status tinyint(1) unsigned           null,
          mission_type   tinyint(1) unsigned default 1 not null
      );
       
      create index idx_mission_status
          on missions (mission_status);
       
      create table rel_applicants_to_missions
      (
          applicants_users_id int unsigned not null,
          missions_id         int unsigned not null,
          primary key (applicants_users_id, missions_id)
      );
       
      SELECT *
      FROM (SELECT DISTINCT a.users_id AS id
            FROM applicants a
                     INNER JOIN (SELECT ram.applicants_users_id
                                 FROM rel_applicants_to_missions ram
                                          INNER JOIN missions m ON m.id = ram.missions_id
                                 WHERE (m.mission_status > 2 AND m.mission_type = 2)
                                 GROUP BY ram.applicants_users_id) m2 ON m2.applicants_users_id = a.users_id) result
      

      By executing this code you can reproduce crash.
      No crash if :

      • There is no index on `mission_status`
      • The optimizer switch has `split_materialized` to `off` (`SET optimizer_switch = "split_materialized=off"`)

      Mariadb logs :

      2022-09-26 15:40:01 0 [Note] mariadbd: ready for connections.
      Version: '10.6.9-MariaDB-1:10.6.9+maria~ubu2004'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
      220926 15:40:22 [ERROR] mysqld got signal 11 ;
      This could be because you hit a bug. It is also possible that this binary
      or one of the libraries it was linked against is corrupt, improperly built,
      or misconfigured. This error can also be caused by malfunctioning hardware.
       
      To report this bug, see https://mariadb.com/kb/en/reporting-bugs
       
      We will try our best to scrape up some info that will hopefully help
      diagnose the problem, but since we have already crashed, 
      something is definitely wrong and this may fail.
       
      Server version: 10.6.9-MariaDB-1:10.6.9+maria~ubu2004
      key_buffer_size=134217728
      read_buffer_size=131072
      max_used_connections=3
      max_threads=153
      thread_count=3
      It is possible that mysqld could use up to 
      key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467959 K  bytes of memory
      Hope that's ok; if not, decrease some variables in the equation.
       
      Thread pointer: 0x7f180c000c58
      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...
      stack_bottom = 0x7f18549d4d98 thread_stack 0x49000
      Printing to addr2line failed
      mariadbd(my_print_stacktrace+0x32)[0x560930f3cf62]
      mariadbd(handle_fatal_signal+0x485)[0x5609309fdfb5]
      /lib/x86_64-linux-gnu/libpthread.so.0(+0x14420)[0x7f186cdbc420]
      mariadbd(_Z16best_access_pathP4JOINP13st_join_tableyPK8POSITIONjbdPS3_S6_+0xde3)[0x560930803353]
      mariadbd(+0x7e4f67)[0x560930805f67]
      mariadbd(+0x7e5212)[0x560930806212]
      mariadbd(_Z11choose_planP4JOINy+0x2e2)[0x560930806da2]
      mariadbd(_ZN13st_join_table21choose_best_splittingEdy+0x57e)[0x56093097cb4e]
      mariadbd(_Z16best_access_pathP4JOINP13st_join_tableyPK8POSITIONjbdPS3_S6_+0x13c)[0x5609308026ac]
      mariadbd(+0x7e4f67)[0x560930805f67]
      mariadbd(+0x7e5212)[0x560930806212]
      mariadbd(_Z11choose_planP4JOINy+0x2e2)[0x560930806da2]
      mariadbd(_ZN4JOIN14optimize_innerEv+0x3862)[0x560930834042]
      mariadbd(_ZN4JOIN8optimizeEv+0xc3)[0x560930834833]
      mariadbd(+0x76334c)[0x56093078434c]
      mariadbd(_Z27mysql_handle_single_derivedP3LEXP10TABLE_LISTj+0x99)[0x560930783b89]
      mariadbd(_ZN13st_select_lex14handle_derivedEP3LEXj+0x47)[0x5609307a0ae7]
      mariadbd(_ZN4JOIN14optimize_innerEv+0x1215)[0x5609308319f5]
      mariadbd(_ZN4JOIN8optimizeEv+0xc3)[0x560930834833]
      mariadbd(_Z12mysql_selectP3THDP10TABLE_LISTR4ListI4ItemEPS4_jP8st_orderS9_S7_S9_yP13select_resultP18st_select_lex_unitP13st_select_lex+0xb7)[0x560930834907]
      mariadbd(_Z13handle_selectP3THDP3LEXP13select_resultm+0x157)[0x560930835117]
      mariadbd(+0x7a25f1)[0x5609307c35f1]
      mariadbd(_Z21mysql_execute_commandP3THDb+0x4489)[0x5609307d19c9]
      mariadbd(_Z11mysql_parseP3THDPcjP12Parser_state+0x1e7)[0x5609307be1e7]
      mariadbd(_Z16dispatch_command19enum_server_commandP3THDPcjb+0x1095)[0x5609307ca4d5]
      mariadbd(_Z10do_commandP3THDb+0x138)[0x5609307cc718]
      mariadbd(_Z24do_handle_one_connectionP7CONNECTb+0x3b7)[0x5609308de137]
      mariadbd(handle_one_connection+0x5d)[0x5609308de48d]
      mariadbd(+0xc23916)[0x560930c44916]
      /lib/x86_64-linux-gnu/libpthread.so.0(+0x8609)[0x7f186cdb0609]
      /lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f186c99c133]
       
      Trying to get some variables.
      Some pointers may be invalid and cause the dump to abort.
      Query (0x7f180c0108c0): SELECT *
      FROM (SELECT DISTINCT a.users_id AS id
            FROM applicants a
                     INNER JOIN (SELECT ram.applicants_users_id
                                 FROM rel_applicants_to_missions ram
                                          INNER JOIN missions m ON m.id = ram.missions_id
                                 WHERE (m.mission_status > 2 AND m.mission_type = 2)
                                 GROUP BY ram.applicants_users_id) m2 ON m2.applicants_users_id = a.users_id) result
       
      Connection ID (thread ID): 5
      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=on,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=off,partial_match_rowid_merge=on,partial_match_table_scan=on,subquery_cache=on,mrr=on,mrr_cost_based=off,mrr_sort_keys=on,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=off,table_elimination=on,extended_keys=on,exists_to_in=off,orderby_uses_equalities=on,condition_pushdown_for_derived=off,split_materialized=on,condition_pushdown_for_subquery=on,rowid_filter=on,condition_pushdown_from_having=on,not_null_range_scan=off
       
      The manual page at https://mariadb.com/kb/en/how-to-produce-a-full-stack-trace-for-mysqld/ contains
      information that should help you find out what is causing the crash.
      Writing a core file...
      Working directory at /var/lib/mysql
      Resource Limits:
      Limit                     Soft Limit           Hard Limit           Units     
      Max cpu time              unlimited            unlimited            seconds   
      Max file size             unlimited            unlimited            bytes     
      Max data size             unlimited            unlimited            bytes     
      Max stack size            8388608              unlimited            bytes     
      Max core file size        0                    unlimited            bytes     
      Max resident set          unlimited            unlimited            bytes     
      Max processes             unlimited            unlimited            processes 
      Max open files            1048576              1048576              files     
      Max locked memory         65536                65536                bytes     
      Max address space         unlimited            unlimited            bytes     
      Max file locks            unlimited            unlimited            locks     
      Max pending signals       23298                23298                signals   
      Max msgqueue size         819200               819200               bytes     
      Max nice priority         0                    0                    
      Max realtime priority     0                    0                    
      Max realtime timeout      unlimited            unlimited            us        
      Core pattern: core
       
      Kernel version: Linux version 5.10.124-linuxkit (root@buildkitsandbox) (gcc (Alpine 10.2.1_pre1) 10.2.1 20201203, GNU ld (GNU Binutils) 2.35.2) #1 SMP Thu Jun 30 08:19:10 UTC 2022
      

      Thanks for help

      Attachments

        Issue Links

          Activity

            People

              Johnston Rex Johnston
              nicoperrony Nicolas Perrony
              Votes:
              2 Vote for this issue
              Watchers:
              7 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.