mirror of
https://github.com/MariaDB/server.git
synced 2025-11-09 11:41:36 +03:00
MDEV-37345 sequences and prelocking
if a bunch of tables are prelocked, when a table is actually needed in the routine, open_tables picks one table out of the prelocked list with a smallest "distance". Distance is simply a difference between the actual table lock and the requested table lock. Say, if the prelocked set contains both t1 write-locked and t1 read-locked, than an UPDATE will prefer write-locked t1 and SELECT will prefer read-locked. if there's only write-locked table in the set, both UPDATE and SELECT will use it. this doesn't distingush between UPDATE and INSERT, but INSERT marks tables with tables->for_insert_data=1, which causes prelocking to invoke add_internal_tables() and prepare sequences for execution. in this bug there were two prelocked t1's, one for INSERT (with for_insert_data=1) and one for UPDATE. INSERT picks the second (they both are write-locked, so the distance is the same), its sequence is not prepared and crashes. Let's add for_insert_data as the lowest bit into the distance.
This commit is contained in:
@@ -394,4 +394,20 @@ create table t (id bigint default(nextval(s))) engine=myisam;
|
||||
insert delayed into t () values();
|
||||
drop table t;
|
||||
drop sequence s;
|
||||
#
|
||||
# MDEV-37345 Item_func_nextval::val_int() crash on INSERT...SELECT with subqueries
|
||||
#
|
||||
create sequence s;
|
||||
create table t1 (a int, b int default(nextval(s)));
|
||||
insert into t1 () values ();
|
||||
create table t2 (c int);
|
||||
create procedure p() update t1 set a = 0;
|
||||
create trigger tr after insert on t2 for each row
|
||||
begin
|
||||
insert into t1 () values ();
|
||||
call p();
|
||||
end $
|
||||
insert into t2 values ();
|
||||
drop table t1, t2, s;
|
||||
drop procedure p;
|
||||
# End of 10.11 tests
|
||||
|
||||
@@ -428,4 +428,24 @@ insert delayed into t () values();
|
||||
drop table t;
|
||||
drop sequence s;
|
||||
|
||||
--echo #
|
||||
--echo # MDEV-37345 Item_func_nextval::val_int() crash on INSERT...SELECT with subqueries
|
||||
--echo #
|
||||
# sequence and prelocking.
|
||||
create sequence s;
|
||||
create table t1 (a int, b int default(nextval(s)));
|
||||
insert into t1 () values ();
|
||||
create table t2 (c int);
|
||||
create procedure p() update t1 set a = 0;
|
||||
--delimiter $
|
||||
create trigger tr after insert on t2 for each row
|
||||
begin
|
||||
insert into t1 () values ();
|
||||
call p();
|
||||
end $
|
||||
--delimiter ;
|
||||
insert into t2 values ();
|
||||
drop table t1, t2, s;
|
||||
drop procedure p;
|
||||
|
||||
--echo # End of 10.11 tests
|
||||
|
||||
Reference in New Issue
Block a user