diff --git a/mysql-test/r/subselect_sj2_mat.result b/mysql-test/r/subselect_sj2_mat.result index 5a5d0065d64..3541653a863 100644 --- a/mysql-test/r/subselect_sj2_mat.result +++ b/mysql-test/r/subselect_sj2_mat.result @@ -760,6 +760,23 @@ LEFT JOIN t2 AS SQ4_alias3 ON SQ4_alias3.f10 GROUP BY field2; field2 drop table t1, t2, t3; +# +# BUG#849763: Wrong result with second execution of prepared statement with semijoin + view +# +CREATE TABLE t1 ( c varchar(1)) engine=innodb; +INSERT INTO t1 VALUES ('r'); +CREATE TABLE t2 ( a integer, b varchar(1), c varchar(1)) engine=innodb; +INSERT INTO t2 VALUES (1,'r','r'); +CREATE OR REPLACE VIEW v1 AS SELECT * FROM t1; +PREPARE st1 FROM 'SELECT * FROM t2 WHERE a = SOME (SELECT a FROM v1 WHERE v1.c = t2.c)'; +EXECUTE st1; +a b c +1 r r +EXECUTE st1; +a b c +1 r r +DROP VIEW v1; +DROP TABLE t1, t2; set optimizer_switch=@subselect_sj2_tmp; set optimizer_switch=default; select @@optimizer_switch like '%materialization=on%'; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index a70d04fccbe..50533c1a7ff 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -2477,6 +2477,8 @@ void Item_in_subselect::fix_after_pullout(st_select_lex *new_parent, Item **ref) { left_expr->fix_after_pullout(new_parent, &left_expr); Item_subselect::fix_after_pullout(new_parent, ref); + //psergey-todo: the above looks odd, why don't we 'aggregate' left_expr with + //the rest? } void Item_in_subselect::update_used_tables()