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();
|
insert delayed into t () values();
|
||||||
drop table t;
|
drop table t;
|
||||||
drop sequence s;
|
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
|
# End of 10.11 tests
|
||||||
|
|||||||
@@ -428,4 +428,24 @@ insert delayed into t () values();
|
|||||||
drop table t;
|
drop table t;
|
||||||
drop sequence s;
|
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
|
--echo # End of 10.11 tests
|
||||||
|
|||||||
@@ -2010,7 +2010,18 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
|
|||||||
table->query_id == 0))
|
table->query_id == 0))
|
||||||
{
|
{
|
||||||
int distance= ((int) table->reginfo.lock_type -
|
int distance= ((int) table->reginfo.lock_type -
|
||||||
(int) table_list->lock_type);
|
(int) table_list->lock_type) * 2;
|
||||||
|
TABLE_LIST *tl= thd->locked_tables_mode == LTM_PRELOCKED
|
||||||
|
? table->pos_in_table_list : table->pos_in_locked_tables;
|
||||||
|
/*
|
||||||
|
note, that merge table children are automatically added to
|
||||||
|
prelocking set in ha_myisammrg::add_children_list(), but their
|
||||||
|
TABLE_LIST's are on the execution arena, so tl will be invalid
|
||||||
|
on the second execution. Let's just skip them below.
|
||||||
|
*/
|
||||||
|
if (table_list->parent_l || !tl ||
|
||||||
|
table_list->for_insert_data != tl->for_insert_data)
|
||||||
|
distance|= 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Find a table that either has the exact lock type requested,
|
Find a table that either has the exact lock type requested,
|
||||||
|
|||||||
Reference in New Issue
Block a user