Commit 3d88a72f authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: fix subquery not a derived table [#365 bug 9]

Tests affected (forced mode):

main.ps \
main.user_var \
main.myisam_explain_non_select_all \
main.opt_tvc \
main.subselect \
main.subselect_no_exists_to_in \
main.derived \
main.derived_opt \
main.update
parent 56adced3
......@@ -298,6 +298,10 @@ create or replace table t2 (b int) with system versioning;
select * from t1
where exists (select 1 from t2 where t2.b = t1.a and t2.b = t1.a);
a
### Issue #365, bug 9 (not a derived subquery)
create or replace table t1 (x int) with system versioning;
select t1.x in (select x from t1) a from t1, (select x from t1) b;
a
drop view v1;
drop table t1, t2;
call innodb_verify_vtq(28);
......
......@@ -195,6 +195,10 @@ create or replace table t2 (b int) with system versioning;
select * from t1
where exists (select 1 from t2 where t2.b = t1.a and t2.b = t1.a);
--echo ### Issue #365, bug 9 (not a derived subquery)
create or replace table t1 (x int) with system versioning;
select t1.x in (select x from t1) a from t1, (select x from t1) b;
drop view v1;
drop table t1, t2;
......
......@@ -791,14 +791,14 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
if (!vers_conditions && outer_slex && slex->vers_import_outer)
{
TABLE_LIST* derived= slex->master_unit()->derived;
while (outer_slex && (!derived->vers_conditions || derived->vers_conditions.from_inner))
// inner SELECT may not be a derived table (derived == NULL)
while (derived && outer_slex && (!derived->vers_conditions || derived->vers_conditions.from_inner))
{
derived= outer_slex->master_unit()->derived;
outer_slex= outer_slex->next_select_in_list();
}
if (outer_slex)
if (derived && outer_slex && !derived->vers_conditions.from_inner)
{
DBUG_ASSERT(derived);
DBUG_ASSERT(derived->vers_conditions);
vers_conditions= derived->vers_conditions;
}
......
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