Commit b850fc66 authored by Igor Babaev's avatar Igor Babaev

Fixed the bug mdev-12855.

This is actually a legacy bug:
SQL_SELECT::test_quick_select() was called
with SQL_SELECT::head not set.
It looks like that this problem can be
reproduced only on queries with ORDER BY
that use IN predicates converted to semi-joins.
parent 151f4e9b
...@@ -1579,3 +1579,25 @@ Warnings: ...@@ -1579,3 +1579,25 @@ Warnings:
Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where ((rand() < 0)) Note 1003 select `test`.`t1`.`i` AS `i` from `test`.`t1` semi join (`test`.`t2`) where ((rand() < 0))
drop table t1,t2; drop table t1,t2;
set optimizer_switch=@save_optimizer_switch; set optimizer_switch=@save_optimizer_switch;
#
# mdev-12855: materialization of a semi-join subquery + ORDER BY
#
CREATE TABLE t1 (f1 varchar(8), KEY(f1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('qux'),('foo');
CREATE TABLE t2 (f2 varchar(8)) ENGINE=InnoDB;
INSERT INTO t2 VALUES ('bar'),('foo'),('qux');
SELECT f1 FROM t1
WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' )
HAVING f1 != 'foo'
ORDER BY f1;
f1
qux
explain SELECT f1 FROM t1
WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' )
HAVING f1 != 'foo'
ORDER BY f1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 index f1 f1 11 NULL 2 Using index
1 PRIMARY <subquery2> eq_ref distinct_key distinct_key 11 func 1
2 MATERIALIZED t2 ALL NULL NULL NULL NULL 3 Using where
DROP TABLE t1,t2;
...@@ -283,3 +283,23 @@ select * from t1 where (rand() < 0) and i in (select i from t2); ...@@ -283,3 +283,23 @@ select * from t1 where (rand() < 0) and i in (select i from t2);
drop table t1,t2; drop table t1,t2;
set optimizer_switch=@save_optimizer_switch; set optimizer_switch=@save_optimizer_switch;
--echo #
--echo # mdev-12855: materialization of a semi-join subquery + ORDER BY
--echo #
CREATE TABLE t1 (f1 varchar(8), KEY(f1)) ENGINE=InnoDB;
INSERT INTO t1 VALUES ('qux'),('foo');
CREATE TABLE t2 (f2 varchar(8)) ENGINE=InnoDB;
INSERT INTO t2 VALUES ('bar'),('foo'),('qux');
let $q=
SELECT f1 FROM t1
WHERE f1 IN ( SELECT f2 FROM t2 WHERE f2 > 'bar' )
HAVING f1 != 'foo'
ORDER BY f1;
eval $q;
eval explain $q;
DROP TABLE t1,t2;
...@@ -2759,8 +2759,11 @@ JOIN::exec() ...@@ -2759,8 +2759,11 @@ JOIN::exec()
if (sort_table_cond) if (sort_table_cond)
{ {
if (!curr_table->select) if (!curr_table->select)
{
if (!(curr_table->select= new SQL_SELECT)) if (!(curr_table->select= new SQL_SELECT))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
curr_table->select->head= curr_table->table;
}
if (!curr_table->select->cond) if (!curr_table->select->cond)
curr_table->select->cond= sort_table_cond; curr_table->select->cond= sort_table_cond;
else else
...@@ -2846,7 +2849,7 @@ JOIN::exec() ...@@ -2846,7 +2849,7 @@ JOIN::exec()
curr_join->select_limit, curr_join->select_limit,
(select_options & OPTION_FOUND_ROWS ? (select_options & OPTION_FOUND_ROWS ?
HA_POS_ERROR : unit->select_limit_cnt), HA_POS_ERROR : unit->select_limit_cnt),
curr_join->group_list ? TRUE : FALSE)) curr_join->group_list ? FALSE : TRUE))
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
sortorder= curr_join->sortorder; sortorder= curr_join->sortorder;
if (curr_join->const_tables != curr_join->table_count && if (curr_join->const_tables != curr_join->table_count &&
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment