Skip to content

Commit

Permalink
SQL: VIEW fix [related to #185]
Browse files Browse the repository at this point in the history
  • Loading branch information
midenok committed May 5, 2017
1 parent f43726a commit 8a11f9b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sql/sql_derived.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions sql/sql_select.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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;
}
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions sql/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down

0 comments on commit 8a11f9b

Please sign in to comment.