diff options
-rw-r--r-- | mysql-test/r/derived_cond_pushdown.result | 11 | ||||
-rw-r--r-- | mysql-test/t/derived_cond_pushdown.test | 16 | ||||
-rw-r--r-- | sql/opt_split.cc | 4 | ||||
-rw-r--r-- | sql/sql_select.cc | 9 |
4 files changed, 32 insertions, 8 deletions
diff --git a/mysql-test/r/derived_cond_pushdown.result b/mysql-test/r/derived_cond_pushdown.result index 2d4638fe4f6..1aa228249a0 100644 --- a/mysql-test/r/derived_cond_pushdown.result +++ b/mysql-test/r/derived_cond_pushdown.result @@ -14917,3 +14917,14 @@ EXPLAIN } DROP VIEW v2; DROP TABLE t1,t2; +# +# MDEV-15017: splittable table is constant table +# +CREATE TABLE t1 (a INT) ENGINE=MyISAM; +CREATE TABLE t2 (pk INT, b INT, PRIMARY KEY (pk)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,2),(3,4); +CREATE VIEW v2 AS SELECT pk, MIN(b) FROM t2 GROUP BY pk; +SELECT * FROM t1 LEFT JOIN v2 ON (a = pk); +a pk MIN(b) +DROP VIEW v2; +DROP TABLE t1,t2; diff --git a/mysql-test/t/derived_cond_pushdown.test b/mysql-test/t/derived_cond_pushdown.test index fa977f7ec4b..80403d2c35a 100644 --- a/mysql-test/t/derived_cond_pushdown.test +++ b/mysql-test/t/derived_cond_pushdown.test @@ -2582,3 +2582,19 @@ eval EXPLAIN FORMAT=JSON $q; DROP VIEW v2; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-15017: splittable table is constant table +--echo # + +CREATE TABLE t1 (a INT) ENGINE=MyISAM; + +CREATE TABLE t2 (pk INT, b INT, PRIMARY KEY (pk)) ENGINE=MyISAM; +INSERT INTO t2 VALUES (1,2),(3,4); + +CREATE VIEW v2 AS SELECT pk, MIN(b) FROM t2 GROUP BY pk; + +SELECT * FROM t1 LEFT JOIN v2 ON (a = pk); + +DROP VIEW v2; +DROP TABLE t1,t2; diff --git a/sql/opt_split.cc b/sql/opt_split.cc index ac2972f4264..efc5a5e5551 100644 --- a/sql/opt_split.cc +++ b/sql/opt_split.cc @@ -1118,11 +1118,11 @@ bool JOIN::fix_all_splittings_in_plan() { table_map prev_tables= 0; table_map all_tables= (1 << table_count) - 1; - for (uint tablenr=0 ; tablenr < table_count ; tablenr++) + for (uint tablenr= 0; tablenr < table_count; tablenr++) { POSITION *cur_pos= &best_positions[tablenr]; JOIN_TAB *tab= cur_pos->table; - if (tab->table->is_splittable()) + if (tablenr >= const_tables && tab->table->is_splittable()) { SplM_plan_info *spl_plan= cur_pos->spl_plan; if (tab->fix_splitting(spl_plan, all_tables & ~prev_tables)) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index db8d1c66419..bd9da10e4b1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -4565,12 +4565,6 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, DBUG_EXECUTE("opt", print_keyuse_array(keyuse_array);); } - for (s= stat; s < stat_end; s++) - { - if (s->table->is_splittable()) - s->add_keyuses_for_splitting(); - } - join->const_table_map= no_rows_const_tables; join->const_tables= const_count; eliminate_tables(join); @@ -4877,6 +4871,9 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list, s->scan_time(); } + if (s->table->is_splittable()) + s->add_keyuses_for_splitting(); + /* Set a max range of how many seeks we can expect when using keys This is can't be to high as otherwise we are likely to use |