Skip to content

Commit db32d94

Browse files
committed
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
1 parent a7cf0db commit db32d94

File tree

7 files changed

+71
-14
lines changed

7 files changed

+71
-14
lines changed

mysql-test/suite/versioning/r/partition.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ delete from t1 where a is not null;
504504
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current);
505505
select * from t1 partition (p0) for system_time all;
506506
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
507+
# MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
508+
create or replace procedure sp()
509+
select * from t1 partition (p0) for system_time all;
510+
call sp;
511+
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
512+
call sp;
513+
ERROR HY000: SYSTEM_TIME partitions in table `t1` does not support historical query
514+
drop procedure sp;
507515
# MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
508516
create or replace table t1 (pk int primary key)
509517
engine=myisam

mysql-test/suite/versioning/r/select.result

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,21 @@ ERROR HY000: Table `t` is not system-versioned
320320
create or replace table t1 (x int) with system versioning engine myisam;
321321
select * from t1 for system_time as of transaction 1;
322322
ERROR HY000: Transaction-precise system versioning for `t1` is not supported
323+
# MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
324+
create or replace procedure sp()
325+
select * from t1 for system_time as of transaction 1;
326+
call sp;
327+
ERROR HY000: Transaction-precise system versioning for `t1` is not supported
328+
call sp;
329+
ERROR HY000: Transaction-precise system versioning for `t1` is not supported
330+
create or replace table t1 (a int);
331+
create or replace procedure sp()
332+
select * from t1 for system_time all;
333+
call sp;
334+
ERROR HY000: Table `t1` is not system-versioned
335+
call sp;
336+
ERROR HY000: Table `t1` is not system-versioned
337+
drop procedure sp;
323338
create or replace table t1 (
324339
x int,
325340
sys_trx_start bigint unsigned as row start invisible,

mysql-test/suite/versioning/r/view.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ i
146146
create or replace view v1 as select * from t1 for system_time as of date_sub(now(), interval 6 second);
147147
show create view v1;
148148
View Create View character_set_client collation_connection
149-
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
149+
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
150150
drop view v1, vt1, vt12;
151151
drop tables t1, t3;
152152
#

mysql-test/suite/versioning/t/partition.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,14 @@ delete from t1 where a is not null;
455455
create or replace table t1 (i int) with system versioning partition by system_time limit 10 (partition p0 history, partition pn current);
456456
--error ER_VERS_QUERY_IN_PARTITION
457457
select * from t1 partition (p0) for system_time all;
458+
--echo # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
459+
create or replace procedure sp()
460+
select * from t1 partition (p0) for system_time all;
461+
--error ER_VERS_QUERY_IN_PARTITION
462+
call sp;
463+
--error ER_VERS_QUERY_IN_PARTITION
464+
call sp;
465+
drop procedure sp;
458466

459467
--echo # MDEV-15380 Index for versioned table gets corrupt after partitioning and DELETE
460468
create or replace table t1 (pk int primary key)

mysql-test/suite/versioning/t/select.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,21 @@ for system_time all as t;
202202
create or replace table t1 (x int) with system versioning engine myisam;
203203
--error ER_VERS_ENGINE_UNSUPPORTED
204204
select * from t1 for system_time as of transaction 1;
205+
--echo # MDEV-18929 2nd execution of SP does not detect ER_VERS_NOT_VERSIONED
206+
create or replace procedure sp()
207+
select * from t1 for system_time as of transaction 1;
208+
--error ER_VERS_ENGINE_UNSUPPORTED
209+
call sp;
210+
--error ER_VERS_ENGINE_UNSUPPORTED
211+
call sp;
212+
create or replace table t1 (a int);
213+
create or replace procedure sp()
214+
select * from t1 for system_time all;
215+
--error ER_VERS_NOT_VERSIONED
216+
call sp;
217+
--error ER_VERS_NOT_VERSIONED
218+
call sp;
219+
drop procedure sp;
205220

206221
create or replace table t1 (
207222
x int,

sql/sql_select.cc

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -719,23 +719,22 @@ void vers_select_conds_t::print(String *str, enum_query_type query_type) const
719719
}
720720
}
721721

722+
static
723+
bool skip_setup_conds(THD *thd)
724+
{
725+
return (!thd->stmt_arena->is_conventional()
726+
&& !thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
727+
|| thd->lex->is_view_context_analysis();
728+
}
729+
722730
int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
723731
{
724732
DBUG_ENTER("SELECT_LEX::vers_setup_cond");
725733
#define newx new (thd->mem_root)
726734

735+
const bool update_conds= !skip_setup_conds(thd);
727736
TABLE_LIST *table;
728737

729-
if (!thd->stmt_arena->is_conventional() &&
730-
!thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
731-
{
732-
// statement is already prepared
733-
DBUG_RETURN(0);
734-
}
735-
736-
if (thd->lex->is_view_context_analysis())
737-
DBUG_RETURN(0);
738-
739738
if (!versioned_tables)
740739
{
741740
for (table= tables; table; table= table->next_local)
@@ -805,13 +804,15 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
805804
*/
806805
if (table->partition_names && table->table->part_info->vers_info)
807806
{
808-
if (vers_conditions.is_set())
807+
/* If the history is stored in partitions, then partitions
808+
themselves are not versioned. */
809+
if (vers_conditions.was_set())
809810
{
810811
my_error(ER_VERS_QUERY_IN_PARTITION, MYF(0), table->alias.str);
811812
DBUG_RETURN(-1);
812813
}
813-
else
814-
vers_conditions.init(SYSTEM_TIME_ALL);
814+
else if (!vers_conditions.is_set())
815+
vers_conditions.type= SYSTEM_TIME_ALL;
815816
}
816817
#endif
817818

@@ -866,6 +867,9 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
866867
}
867868
}
868869

870+
if (!update_conds)
871+
continue;
872+
869873
Item *cond1= NULL, *cond2= NULL, *cond3= NULL, *curr= NULL;
870874
Item *point_in_time1= vers_conditions.start.item;
871875
Item *point_in_time2= vers_conditions.end.item;

sql/table.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,7 @@ class Vers_history_point : public vers_history_point_t
18711871
struct vers_select_conds_t
18721872
{
18731873
vers_system_time_t type;
1874+
vers_system_time_t orig_type;
18741875
bool used:1;
18751876
bool delete_history:1;
18761877
Vers_history_point start;
@@ -1879,6 +1880,7 @@ struct vers_select_conds_t
18791880
void empty()
18801881
{
18811882
type= SYSTEM_TIME_UNSPECIFIED;
1883+
orig_type= SYSTEM_TIME_UNSPECIFIED;
18821884
used= false;
18831885
delete_history= false;
18841886
start.empty();
@@ -1890,6 +1892,7 @@ struct vers_select_conds_t
18901892
Vers_history_point _end= Vers_history_point())
18911893
{
18921894
type= _type;
1895+
orig_type= _type;
18931896
used= false;
18941897
delete_history= (type == SYSTEM_TIME_HISTORY ||
18951898
type == SYSTEM_TIME_BEFORE);
@@ -1905,6 +1908,10 @@ struct vers_select_conds_t
19051908
{
19061909
return type != SYSTEM_TIME_UNSPECIFIED;
19071910
}
1911+
bool was_set() const
1912+
{
1913+
return orig_type != SYSTEM_TIME_UNSPECIFIED;
1914+
}
19081915
bool resolve_units(THD *thd);
19091916
bool eq(const vers_select_conds_t &conds) const;
19101917
};

0 commit comments

Comments
 (0)