MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED

Don't do skip_setup_conds() unless all errors are checked.

Fixes following errors:
      ER_PERIOD_NOT_FOUND
      ER_VERS_QUERY_IN_PARTITION
      ER_VERS_ENGINE_UNSUPPORTED
      ER_VERS_NOT_VERSIONED
This commit is contained in:
Aleksey Midenkov 2019-12-02 11:48:37 +03:00
parent a7cf0db3d8
commit db32d9457e
7 changed files with 71 additions and 14 deletions

View File

@ -504,6 +504,14 @@ delete from t1 where a is not null;
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current); create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current);
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0) for system_time all;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
# MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
create or replace procedure sp()
select * from t1 partition (p0) for system_time all;
call sp;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
call sp;
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
drop procedure sp;
# MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
create or replace table t1 (pk int primary key) create or replace table t1 (pk int primary key)
engine=myisam engine=myisam

View File

@ -320,6 +320,21 @@ ERROR HY000: Table `t` is not system-versioned
create or replace table t1 (x int) with system versioning engine myisam; create or replace table t1 (x int) with system versioning engine myisam;
select * from t1 for system_time as of transaction 1; select * from t1 for system_time as of transaction 1;
ERROR HY000: Transaction-precise system versioning for `t1` is not supported ERROR HY000: Transaction-precise system versioning for `t1` is not supported
# MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
create or replace procedure sp()
select * from t1 for system_time as of transaction 1;
call sp;
ERROR HY000: Transaction-precise system versioning for `t1` is not supported
call sp;
ERROR HY000: Transaction-precise system versioning for `t1` is not supported
create or replace table t1 (a int);
create or replace procedure sp()
select * from t1 for system_time all;
call sp;
ERROR HY000: Table `t1` is not system-versioned
call sp;
ERROR HY000: Table `t1` is not system-versioned
drop procedure sp;
create or replace table t1 ( create or replace table t1 (
x int, x int,
sys_trx_start bigint unsigned as row start invisible, sys_trx_start bigint unsigned as row start invisible,

View File

@ -146,7 +146,7 @@ i
create or replace view v1 as select * from t1 for system_time as of date_sub(now(), interval 6 second); create or replace view v1 as select * from t1 for system_time as of date_sub(now(), interval 6 second);
show create view v1; show create view v1;
View Create View character_set_client collation_connection View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` FOR SYSTEM_TIME AS OF current_timestamp() - interval 6 second latin1 latin1_swedish_ci v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`i` AS `i` from `t1` FOR SYSTEM_TIME AS OF TIMESTAMP current_timestamp() - interval 6 second latin1 latin1_swedish_ci
drop view v1, vt1, vt12; drop view v1, vt1, vt12;
drop tables t1, t3; drop tables t1, t3;
# #

View File

@ -455,6 +455,14 @@ delete from t1 where a is not null;
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current); create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current);
--error ER_VERS_QUERY_IN_PARTITION --error ER_VERS_QUERY_IN_PARTITION
select * from t1 partition (p0) for system_time all; select * from t1 partition (p0) for system_time all;
--echo # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
create or replace procedure sp()
select * from t1 partition (p0) for system_time all;
--error ER_VERS_QUERY_IN_PARTITION
call sp;
--error ER_VERS_QUERY_IN_PARTITION
call sp;
drop procedure sp;
--echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE --echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
create or replace table t1 (pk int primary key) create or replace table t1 (pk int primary key)

View File

@ -202,6 +202,21 @@ for system_time all as t;
create or replace table t1 (x int) with system versioning engine myisam; create or replace table t1 (x int) with system versioning engine myisam;
--error ER_VERS_ENGINE_UNSUPPORTED --error ER_VERS_ENGINE_UNSUPPORTED
select * from t1 for system_time as of transaction 1; select * from t1 for system_time as of transaction 1;
--echo # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
create or replace procedure sp()
select * from t1 for system_time as of transaction 1;
--error ER_VERS_ENGINE_UNSUPPORTED
call sp;
--error ER_VERS_ENGINE_UNSUPPORTED
call sp;
create or replace table t1 (a int);
create or replace procedure sp()
select * from t1 for system_time all;
--error ER_VERS_NOT_VERSIONED
call sp;
--error ER_VERS_NOT_VERSIONED
call sp;
drop procedure sp;
create or replace table t1 ( create or replace table t1 (
x int, x int,

View File

@ -719,23 +719,22 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const
} }
} }
static
bool skip_setup_conds(THD *thd)
{
return (!thd->stmt_arena->is_conventional()
&& !thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
|| thd->lex->is_view_context_analysis();
}
int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables) int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
{ {
DBUG_ENTER("SELECT_LEX::vers_setup_cond"); DBUG_ENTER("SELECT_LEX::vers_setup_cond");
#define newx new (thd->mem_root) #define newx new (thd->mem_root)
const bool update_conds= !skip_setup_conds(thd);
TABLE_LIST *table; TABLE_LIST *table;
if (!thd->stmt_arena->is_conventional() &&
!thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
{
// statement is already prepared
DBUG_RETURN(0);
}
if (thd->lex->is_view_context_analysis())
DBUG_RETURN(0);
if (!versioned_tables) if (!versioned_tables)
{ {
for (table= tables; table; table= table->next_local) for (table= tables; table; table= table->next_local)
@ -805,13 +804,15 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
*/ */
if (table->partition_names && table->table->part_info->vers_info) if (table->partition_names && table->table->part_info->vers_info)
{ {
if (vers_conditions.is_set()) /* If the history is stored in partitions, then partitions
themselves are not versioned. */
if (vers_conditions.was_set())
{ {
my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str); my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str);
DBUG_RETURN(-1); DBUG_RETURN(-1);
} }
else else if (!vers_conditions.is_set())
vers_conditions.init(SYSTEM_TIME_ALL); vers_conditions.type= SYSTEM_TIME_ALL;
} }
#endif #endif
@ -866,6 +867,9 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
} }
} }
if (!update_conds)
continue;
Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL; Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL;
Item *point_in_time1= vers_conditions.start.item; Item *point_in_time1= vers_conditions.start.item;
Item *point_in_time2= vers_conditions.end.item; Item *point_in_time2= vers_conditions.end.item;

View File

@ -1871,6 +1871,7 @@ public:
struct vers_select_conds_t struct vers_select_conds_t
{ {
vers_system_time_t type; vers_system_time_t type;
vers_system_time_t orig_type;
bool used:1; bool used:1;
bool delete_history:1; bool delete_history:1;
Vers_history_point start; Vers_history_point start;
@ -1879,6 +1880,7 @@ struct vers_select_conds_t
void empty() void empty()
{ {
type= SYSTEM_TIME_UNSPECIFIED; type= SYSTEM_TIME_UNSPECIFIED;
orig_type= SYSTEM_TIME_UNSPECIFIED;
used= false; used= false;
delete_history= false; delete_history= false;
start.empty(); start.empty();
@ -1890,6 +1892,7 @@ struct vers_select_conds_t
Vers_history_point _end= Vers_history_point()) Vers_history_point _end= Vers_history_point())
{ {
type= _type; type= _type;
orig_type= _type;
used= false; used= false;
delete_history= (type == SYSTEM_TIME_HISTORY || delete_history= (type == SYSTEM_TIME_HISTORY ||
type == SYSTEM_TIME_BEFORE); type == SYSTEM_TIME_BEFORE);
@ -1905,6 +1908,10 @@ struct vers_select_conds_t
{ {
return type != SYSTEM_TIME_UNSPECIFIED; return type != SYSTEM_TIME_UNSPECIFIED;
} }
bool was_set() const
{
return orig_type != SYSTEM_TIME_UNSPECIFIED;
}
bool resolve_units(THD *thd); bool resolve_units(THD *thd);
bool eq(const vers_select_conds_t &conds) const; bool eq(const vers_select_conds_t &conds) const;
}; };