Commit 7e0ff13d authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: derived fixes [related to #185]

parent 8a11f9b2
......@@ -41,7 +41,7 @@ from emp as e for system_time as of timestamp @ts_1,
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors;
select * from ancestors for system_time as of now;
emp_id name mgr salary
1 bill NULL 1000
30 jane 1 750
......@@ -59,7 +59,7 @@ from emp as e for system_time as of timestamp @ts_2,
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors for system_time as of timestamp @ts_2;
select * from ancestors;
emp_id name mgr salary
1 bill NULL 1000
30 jane 1 750
......
......@@ -39,9 +39,13 @@ x
drop prepare stmt;
select * from vt1;
x
2
1
prepare stmt from 'select * from vt1';
execute stmt;
x
2
1
drop prepare stmt;
select * from t1 for system_time as of timestamp @t1;
x
......
......@@ -47,7 +47,7 @@ as
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors;
select * from ancestors for system_time as of now;
/* Expected 3 rows */
with recursive
......@@ -63,7 +63,7 @@ as
ancestors as a
where e.mgr = a.emp_id
)
select * from ancestors for system_time as of timestamp @ts_2;
select * from ancestors;
drop table emp;
drop table dept;
......@@ -824,8 +824,12 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived)
if (!expli_end && (res= sl->vers_push_field(thd, impli_table, impli_end)))
goto exit;
if (impli_table->vers_conditions && !derived->is_view())
if (impli_table->vers_conditions)
{
sl->vers_derived_conds= impli_table->vers_conditions;
if (derived->is_view() && !sl->vers_conditions)
sl->vers_conditions.import_outer= true;
}
else if (sl->vers_conditions)
sl->vers_derived_conds= sl->vers_conditions;
else
......
......@@ -771,6 +771,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
}
SELECT_LEX *outer_slex= slex->next_select_in_list();
bool use_slex_conds= false;
if (outer_slex)
{
if (slex->vers_derived_conds)
......@@ -778,11 +779,12 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
// Propagate derived conditions to outer SELECT_LEX:
if (!outer_slex->vers_conditions)
{
(outer_slex->vers_conditions= slex->vers_derived_conds).
from_inner= true;
outer_slex->vers_conditions= slex->vers_derived_conds;
outer_slex->vers_conditions.from_inner= true;
outer_slex->vers_conditions.used= true;
}
}
else if (slex->vers_conditions.import_outer)
if (slex->vers_conditions.import_outer)
{
// Propagate query conditions from nearest outer SELECT_LEX:
while (outer_slex && (!outer_slex->vers_conditions || outer_slex->vers_conditions.from_inner))
......@@ -791,6 +793,8 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
{
slex->vers_conditions= outer_slex->vers_conditions;
outer_slex->vers_conditions.used= true;
DBUG_ASSERT(slex->master_unit()->derived);
use_slex_conds= slex->master_unit()->derived->is_view();
}
}
}
......@@ -799,7 +803,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
{
if (table->table && table->table->versioned())
{
vers_select_conds_t &vers_conditions= !table->vers_conditions?
vers_select_conds_t &vers_conditions= use_slex_conds || !table->vers_conditions?
(slex->vers_conditions.used= true, slex->vers_conditions) :
table->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