From ea60760e476ae3e5d1dc44d1976fba68e86f679f Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Thu, 22 Dec 2016 07:34:33 +0000 Subject: [PATCH] SQL: missed FOR SYSTEM_TIME ALL for FOR_SYSTEM_TIME_UNSPECIFIED [fixes #105] --- mysql-test/suite/versioning/r/view.result | 4 ++++ mysql-test/suite/versioning/t/view.test | 3 +++ sql/sql_select.cc | 7 +++++-- sql/table.h | 4 ++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/view.result b/mysql-test/suite/versioning/r/view.result index b9538698ec1..eeec506f933 100644 --- a/mysql-test/suite/versioning/r/view.result +++ b/mysql-test/suite/versioning/r/view.result @@ -20,6 +20,10 @@ x 2 select * from t1; x +create or replace view vt1 as select * from t1; +show create view vt1; +View Create View character_set_client collation_connection +vt1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `vt1` AS select `t1`.`x` AS `x` from `t1` where `t1`.`sys_trx_end` = 18446744073709551615 for system_time all latin1 latin1_swedish_ci drop view vt1; drop view vt2; drop table t1; diff --git a/mysql-test/suite/versioning/t/view.test b/mysql-test/suite/versioning/t/view.test index 6c04255bad1..445dcc1f633 100644 --- a/mysql-test/suite/versioning/t/view.test +++ b/mysql-test/suite/versioning/t/view.test @@ -19,6 +19,9 @@ select * from vt1; select * from vt2; select * from t1; +create or replace view vt1 as select * from t1; +show create view vt1; + drop view vt1; drop view vt2; drop table t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b36ccc4e8d6..4dc67267b74 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -721,6 +721,7 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s if (query_type == FOR_SYSTEM_TIME_ALL) { + slex->vers_conditions.unwrapped= true; DBUG_RETURN(0); } } @@ -928,6 +929,8 @@ vers_setup_select(THD *thd, TABLE_LIST *tables, COND **where_expr, SELECT_LEX *s thd->restore_active_arena(arena, &backup); } + slex->vers_conditions.unwrapped= true; + DBUG_RETURN(0); #undef newx } @@ -25548,9 +25551,9 @@ void st_select_lex::print(THD *thd, String *str, enum_query_type query_type) str->append(having_value != Item::COND_FALSE ? "1" : "0"); } - if (vers_conditions.type != FOR_SYSTEM_TIME_UNSPECIFIED) + if (vers_conditions.unwrapped) { - // versioning conditions must be already unwrapped to WHERE clause + // versioning conditions are already unwrapped to WHERE clause str->append(STRING_WITH_LEN(" for system_time all ")); } diff --git a/sql/table.h b/sql/table.h index dbcbee290f8..552e51284a6 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1857,11 +1857,14 @@ struct vers_select_conds_t vers_range_unit_t unit; Item *start, *end; + bool unwrapped; + void empty() { type= FOR_SYSTEM_TIME_UNSPECIFIED; unit= UNIT_TIMESTAMP; start= end= NULL; + unwrapped= false; } void init( @@ -1874,6 +1877,7 @@ struct vers_select_conds_t unit= u; start= s; end= e; + unwrapped= false; } };