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

Crash on second execution of PS for query over many views

    XMLWordPrintable

Details

    • Bug
    • Status: Stalled (View Workflow)
    • Critical
    • Resolution: Unresolved
    • 10.4(EOL), 10.5, 10.6, 10.11, 11.0(EOL), 11.1(EOL), 11.2(EOL), 11.3(EOL)
    • 10.5, 10.6, 10.11
    • Optimizer
    • None

    Description

      The following test case causes a crash of the server on the second execution of used PS:

      CREATE TABLE t1 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t2 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t3 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t4 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t5 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t6 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t7 (a int PRIMARY KEY) ENGINE=MYISAM;
      CREATE TABLE t8 (a int PRIMARY KEY) ENGINE=MYISAM;
       
      INSERT INTO t1 VALUES (1), (2);
      INSERT INTO t2 VALUES (1), (2);
      INSERT INTO t3 VALUES (1), (2);
      INSERT INTO t4 VALUES (1), (2);
      INSERT INTO t5 VALUES (1), (2);
      INSERT INTO t6 VALUES (1), (2);
      INSERT INTO t7 VALUES (1), (2);
      INSERT INTO t8 VALUES (1), (2);
       
      CREATE VIEW v1 AS
      SELECT t8.a
      FROM t1
           LEFT JOIN t2 ON t2.a = t1.a
           LEFT JOIN t3 ON t3.a = t2.a
           LEFT JOIN t4 ON t4.a = t3.a
           LEFT JOIN t5 ON t5.a = t4.a
           LEFT JOIN t6 ON t6.a = t5.a
           LEFT JOIN t7 ON t7.a = t6.a
           LEFT JOIN t8 ON t8.a = t7.a
      ;
       
      CREATE TABLE t9 (a int PRIMARY KEY, b int) ENGINE=MYISAM;
      INSERT INTO t9 VALUES (1,10), (2,20);
       
      CREATE VIEW v2 AS
      SELECT t8.a, t9.b + 100 as b
      FROM t1
           LEFT JOIN t2 ON t2.a = t1.a
           LEFT JOIN t3 ON t3.a = t2.a
           LEFT JOIN t8 ON t8.a = t3.a
           LEFT JOIN t9 ON t9.a = t8.a
      ;
       
      let $q=
      SELECT dt.b FROM
      (
      SELECT v2.b + 200 as b
      FROM v1 AS s1
           LEFT JOIN v1 AS s2 ON s2.a = s1.a
           LEFT JOIN v1 AS s3 ON s3.a = s2.a
           LEFT JOIN v1 AS s4 ON s4.a = s3.a
           LEFT JOIN v1 AS s5 ON s5.a = s4.a
           LEFT JOIN v1 AS s6 ON s6.a = s5.a
           LEFT JOIN v1 AS s7 ON s7.a = s6.a
           LEFT JOIN v2 ON v2.a = s7.a
      WHERE s1.a > 1
      ) dt;
       
      eval $q;
       
      eval PREPARE stmt FROM "$q";
      EXECUTE stmt;
      EXECUTE stmt;
      DEALLOCATE PREPARE stmt;
       
      DROP VIEW v1,v2;
      DROP TABLE t1,t2,t3,t4,t5,t6,t7,t8,t9;
      

      The crash happens in Dep_analysis_context::get_field_value() with
      the following stack:

      sql/opt_table_elimination.cc:1619(Dep_analysis_context::get_field_value(Field*))[0x56016b2f8999]
      sql/opt_table_elimination.cc:1268(build_eq_mods_for_cond(THD*, Dep_analysis_context*, Dep_module_expr**, unsigned int*, Item*))[0x56016b2f7e85]
      sql/opt_table_elimination.cc:861(check_func_dependency(JOIN*, unsigned long long, List_iterator<TABLE_LIST>*, TABLE_LIST*, Item*))[0x56016b2f6f0e]
      sql/opt_table_elimination.cc:756(eliminate_tables_for_list(JOIN*, List<TABLE_LIST>*, unsigned long long, Item*, unsigned long long, Json_writer_array*))[0x56016b2f6ad8]
      sql/opt_table_elimination.cc:681(eliminate_tables(JOIN*))[0x56016b2f690e]
      sql/sql_select.cc:5249(make_join_statistics(JOIN*, List<TABLE_LIST>&, st_dynamic_array*))[0x56016b13f05c]
      sql/sql_select.cc:2388(JOIN::optimize_inner())[0x56016b134bbb]
      sql/sql_select.cc:1731(JOIN::optimize())[0x56016b13242a]
      sql/sql_select.cc:4832(mysql_select(THD*, TABLE_LIST*, unsigned int, List<Item>&, Item*, unsigned int, st_order*, st_order*, Item*, st_order*, unsigned long long, select_result*, st_select_lex_unit*, st_select_lex*))[0x56016b13dc53]
      sql/sql_select.cc:454(handle_select(THD*, LEX*, select_result*, unsigned long))[0x56016b12cffa]
      sql/sql_parse.cc:6523(execute_sqlcom_select(THD*, TABLE_LIST*))[0x56016b0ef6a6]
      sql/sql_parse.cc:3980(mysql_execute_command(THD*))[0x56016b0e5fad]
      sql/sql_prepare.cc:5025(Prepared_statement::execute(String*, bool))[0x56016b115286]
      sql/sql_prepare.cc:4472(Prepared_statement::execute_loop(String*, bool, unsigned char*, unsigned char*))[0x56016b113587]
      sql/sql_prepare.cc:3532(mysql_sql_stmt_execute(THD*))[0x56016b110dad]
      sql/sql_parse.cc:3997(mysql_execute_command(THD*))[0x56016b0e5ff2]
      sql/sql_parse.cc:8062(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x56016b0f3658]
      sql/sql_parse.cc:1860(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x56016b0dfad0]
      sql/sql_parse.cc:1379(do_command(THD*))[0x56016b0de2f4]
      sql/sql_connect.cc:1419(do_handle_one_connection(CONNECT*))[0x56016b27b578]
      sql/sql_connect.cc:1324(handle_one_connection)[0x56016b27b2d4]
      

      With the setting

      set optimizer_switch="table_elimination=off";
      

      both execution of the used PS return the expected result set.

      Attachments

        Issue Links

          Activity

            People

              igor Igor Babaev
              igor Igor Babaev
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.