Skip to content

Commit 748ef3e

Browse files
kevgsvuvova
authored andcommitted
MDEV-15991 Server crashes in setup_on_expr upon calling SP or function executing DML on versioned tables
Do not try to set versioning conditions on every SP call. It may work incorrectly, but it's a general bug described in MDEV-774. This patch makes system versioning stuff consistent with other code and also fixes a use-after-free bug. Closes #756
1 parent b1efff4 commit 748ef3e

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,27 @@ a
538538
select * from t1 for system_time from @t2 to @t1;
539539
a
540540
drop table t1;
541+
#
542+
# MDEV-15991 Server crashes in setup_on_expr upon calling SP or function executing DML on versioned tables
543+
#
544+
create or replace table t1 (i int);
545+
insert into t1 values (1);
546+
create or replace procedure p(n int)
547+
begin
548+
select * from t1;
549+
end $
550+
call p(1);
551+
i
552+
1
553+
alter table t1 add system versioning;
554+
call p(2);
555+
i
556+
1
557+
call p(3);
558+
i
559+
1
560+
drop procedure p;
561+
drop table t1;
541562
call verify_trt_dummy(34);
542563
No A B C D
543564
1 1 1 1 1

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,24 @@ select * from t1 for system_time from @t1 to @t2;
348348
select * from t1 for system_time from @t2 to @t1;
349349
drop table t1;
350350

351+
--echo #
352+
--echo # MDEV-15991 Server crashes in setup_on_expr upon calling SP or function executing DML on versioned tables
353+
--echo #
354+
create or replace table t1 (i int);
355+
insert into t1 values (1);
356+
--delimiter $
357+
create or replace procedure p(n int)
358+
begin
359+
select * from t1;
360+
end $
361+
--delimiter ;
362+
call p(1);
363+
alter table t1 add system versioning;
364+
call p(2);
365+
call p(3);
366+
drop procedure p;
367+
drop table t1;
368+
351369
call verify_trt_dummy(34);
352370

353371
-- source suite/versioning/common_finish.inc

sql/sql_class.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,8 +1007,6 @@ class Query_arena
10071007
{ return state == STMT_PREPARED || state == STMT_EXECUTED; }
10081008
inline bool is_conventional() const
10091009
{ return state == STMT_CONVENTIONAL_EXECUTION; }
1010-
inline bool is_sp_execute() const
1011-
{ return is_stored_procedure; }
10121010

10131011
inline void* alloc(size_t size) { return alloc_root(mem_root,size); }
10141012
inline void* calloc(size_t size)

sql/sql_select.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ int SELECT_LEX::vers_setup_conds(THD *thd, TABLE_LIST *tables)
725725
TABLE_LIST *table;
726726

727727
if (!thd->stmt_arena->is_conventional() &&
728-
!thd->stmt_arena->is_stmt_prepare() && !thd->stmt_arena->is_sp_execute())
728+
!thd->stmt_arena->is_stmt_prepare_or_first_sp_execute())
729729
{
730730
// statement is already prepared
731731
DBUG_RETURN(0);

0 commit comments

Comments
 (0)