Commit 8a11f9b2 authored by Aleksey Midenkov's avatar Aleksey Midenkov

SQL: VIEW fix [related to #185]

parent f43726a1
......@@ -824,7 +824,7 @@ 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)
if (impli_table->vers_conditions && !derived->is_view())
sl->vers_derived_conds= impli_table->vers_conditions;
else if (sl->vers_conditions)
sl->vers_derived_conds= sl->vers_conditions;
......
......@@ -694,7 +694,6 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
TABLE_LIST *table;
int versioned_tables= 0;
int slex_conds_used= 0;
if (!thd->stmt_arena->is_conventional() &&
!thd->stmt_arena->is_stmt_prepare() && !thd->stmt_arena->is_sp_execute())
......@@ -789,7 +788,10 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
while (outer_slex && (!outer_slex->vers_conditions || outer_slex->vers_conditions.from_inner))
outer_slex= outer_slex->next_select_in_list();
if (outer_slex)
{
slex->vers_conditions= outer_slex->vers_conditions;
outer_slex->vers_conditions.used= true;
}
}
}
......@@ -798,7 +800,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?
(++slex_conds_used, slex->vers_conditions) :
(slex->vers_conditions.used= true, slex->vers_conditions) :
table->vers_conditions;
if (!vers_conditions)
......@@ -996,7 +998,7 @@ int vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr,
} // if (... table->table->versioned())
} // for (table= tables; ...)
if (!slex_conds_used && slex->vers_conditions)
if (!slex->vers_conditions.used && slex->vers_conditions)
{
my_error(ER_VERS_WRONG_QUERY, MYF(0), "unused `QUERY FOR SYSTEM_TIME` clause!");
DBUG_RETURN(-1);
......
......@@ -1855,13 +1855,14 @@ struct vers_select_conds_t
vers_range_unit_t unit;
bool import_outer:1;
bool from_inner:1;
bool used:1;
Item *start, *end;
void empty()
{
type= FOR_SYSTEM_TIME_UNSPECIFIED;
unit= UNIT_TIMESTAMP;
import_outer= from_inner= false;
import_outer= from_inner= used= false;
start= end= NULL;
}
......@@ -1875,7 +1876,7 @@ struct vers_select_conds_t
unit= u;
start= s;
end= e;
import_outer= from_inner= false;
import_outer= from_inner= used= false;
}
bool init_from_sysvar(THD *thd);
......
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