mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
Implementation of Monty's idea: Now we can open mysql.proc table for lookup
of stored routines definitions even if we already have some tables open and locked. To avoid deadlocks in this case we have to put certain restrictions on locking of mysql.proc table. This allows to use stored routines safely under LOCK TABLES without explicitly mentioning mysql.proc in the list of locked tables. It also fixes bug #11554 "Server crashes on statement indirectly using non-cached function". mysql-test/r/sp-error.result: Added test which checks that now we can read stored routines definitions under LOCK TABLES even if we have not locked mysql.proc explicitly. Also added check for restrictions which this ability puts on mysql.proc locking. Updated test for bug #9566 to correspond this new situation. mysql-test/r/sp-threads.result: Added test for bug #11554 "Server crashes on statement indirectly using non-cached function". mysql-test/t/sp-error.test: Added test which checks that now we can read stored routines definitions under LOCK TABLES even if we have not locked mysql.proc explicitly. Also added check for restrictions which this ability puts on mysql.proc locking. Updated test for bug #9566 to correspond this new situation. mysql-test/t/sp-threads.test: Added test for bug #11554 "Server crashes on statement indirectly using non-cached function". sql/lock.cc: get_lock_data(): To be able to open and lock for reading system tables like 'mysql.proc', when we already have some tables opened and locked, and avoid deadlocks we have to disallow write-locking of these tables with any other tables. sql/mysql_priv.h: open_table() has new parameter which allows to open table even if some-one has done a flush or holding namelock on it. sql/share/errmsg.txt: Added error message saying that one cannot write-lock some of system tables with any other tables. sql/sp.cc: open_proc_table_for_read()/close_proc_table(): Added functions to be able open and close mysql.proc table when we already have some tables open and locked. open_proc_table_for_update(): Added function to simplify opening of mysql.proc for updates. db_find_routine_aux()/db_find_routine()/db_update_routine()/... Moved responsibility for opening mysql.proc table from db_find_routine_aux() one level up, since this level knows better which type of table access for reading of for update it needs. sp_function_exists(): Removed unused function. sql/sp.h: sp_function_exists(): Removed unused function. sql/sql_base.cc: open_table(): Added new parameter which allows to open table even if some-one has done a flush or holding namelock on it. open_unireg_entry(): Mark 'mysql.proc' as a system table which has special restrictions on its locking, but thanks to them can be open and locked even if we already have some open and locked. sql/sql_class.cc: Moved THD members holding information about open and locked tables to separate Open_tables_state class to be able to save/restore this state easier. Added THD::push_open_tables_state()/pop_open_tables_state() methods for saving/restoring this state. sql/sql_class.h: Moved THD members holding information about open and locked tables to separate Open_tables_state class to be able to save/restore this state easier. Added THD::push_open_tables_state()/pop_open_tables_state() methods for saving/restoring this state. sql/sql_lex.cc: Removed LEX::proc_table member which was not really used. sql/sql_lex.h: Removed LEX::proc_table member which was not really used. sql/sql_table.cc: open_table() has new parameter which allows to open table even if some-one has done a flush or holding namelock on it. sql/table.h: Added TABLE_SHARE::system_table indicating that this table is system table like 'mysql.proc' and we want to be able to open and read-lock it even when we already have some tables open and locked (and because of this we have to put some restrictions on write locking it).
This commit is contained in:
@ -286,6 +286,19 @@ ERROR 42000: OUT or INOUT argument 2 for routine test.p is not a variable
|
||||
call p(42, @tmp_y, 43)|
|
||||
ERROR 42000: OUT or INOUT argument 3 for routine test.p is not a variable
|
||||
drop procedure p|
|
||||
create procedure p() begin end|
|
||||
lock table t1 read|
|
||||
call p()|
|
||||
unlock tables|
|
||||
drop procedure p|
|
||||
lock tables t1 read, mysql.proc write|
|
||||
ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
|
||||
lock tables mysql.proc write, mysql.user write|
|
||||
ERROR HY000: You can't combine write-locking of system 'mysql.proc' table with other tables
|
||||
lock tables t1 read, mysql.proc read|
|
||||
unlock tables|
|
||||
lock tables mysql.proc write|
|
||||
unlock tables|
|
||||
create procedure bug1965()
|
||||
begin
|
||||
declare c cursor for select val from t1 order by valname;
|
||||
@ -477,7 +490,7 @@ begin
|
||||
select * from t1;
|
||||
end|
|
||||
lock table t1 read|
|
||||
call bug9566()|
|
||||
alter procedure bug9566 comment 'Some comment'|
|
||||
ERROR HY000: Table 'proc' was not locked with LOCK TABLES
|
||||
unlock tables|
|
||||
drop procedure bug9566|
|
||||
|
@ -55,3 +55,12 @@ call bug11158();
|
||||
unlock tables;
|
||||
drop procedure bug11158;
|
||||
drop table t1, t2;
|
||||
drop function if exists bug11554;
|
||||
drop view if exists v1;
|
||||
create table t1 (i int);
|
||||
create function bug11554 () returns int return 1;
|
||||
create view v1 as select bug11554() as f;
|
||||
insert into t1 (select f from v1);
|
||||
drop function bug11554;
|
||||
drop table t1;
|
||||
drop view v1;
|
||||
|
@ -386,6 +386,29 @@ call p(42, @tmp_y, 43)|
|
||||
drop procedure p|
|
||||
|
||||
|
||||
#
|
||||
# Let us test that we can access mysql.proc table for routines
|
||||
# definitions lookup without locking it explicitly.
|
||||
#
|
||||
create procedure p() begin end|
|
||||
lock table t1 read|
|
||||
# This should succeed
|
||||
call p()|
|
||||
unlock tables|
|
||||
drop procedure p|
|
||||
# Let us check restrictions which this ability puts on mysql.proc locking.
|
||||
--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
|
||||
lock tables t1 read, mysql.proc write|
|
||||
--error ER_WRONG_LOCK_OF_SYSTEM_TABLE
|
||||
lock tables mysql.proc write, mysql.user write|
|
||||
# Locking for read should be OK
|
||||
lock tables t1 read, mysql.proc read|
|
||||
unlock tables|
|
||||
# You also should be able lock only mysql.proc for write
|
||||
lock tables mysql.proc write|
|
||||
unlock tables|
|
||||
|
||||
|
||||
#
|
||||
# BUG#1965
|
||||
#
|
||||
@ -676,9 +699,7 @@ create procedure bug6600()
|
||||
# BUG#9566: explicit LOCK TABLE and store procedures result in illegal state
|
||||
#
|
||||
# We should not think that mysql.proc table does not exist if we are unable
|
||||
# to open it under LOCK TABLE or in prelocked mode. Probably this test
|
||||
# should be removed when Monty will allow access to mysql.proc without
|
||||
# locking it.
|
||||
# to open it under LOCK TABLE or in prelocked mode.
|
||||
#
|
||||
--disable_warnings
|
||||
drop procedure if exists bug9566|
|
||||
@ -688,9 +709,11 @@ begin
|
||||
select * from t1;
|
||||
end|
|
||||
lock table t1 read|
|
||||
# This should fail because we forgot to lock mysql.proc table explicitly
|
||||
# This should fail since we forgot to lock mysql.proc for writing
|
||||
# explicitly, and we can't open mysql.proc for _writing_ if there
|
||||
# are locked tables.
|
||||
--error 1100
|
||||
call bug9566()|
|
||||
alter procedure bug9566 comment 'Some comment'|
|
||||
unlock tables|
|
||||
# This should succeed
|
||||
drop procedure bug9566|
|
||||
|
@ -111,6 +111,25 @@ connection con1root;
|
||||
drop procedure bug11158;
|
||||
drop table t1, t2;
|
||||
|
||||
#
|
||||
# BUG#11554: Server crashes on statement indirectly using non-cached function
|
||||
#
|
||||
--disable_warnings
|
||||
drop function if exists bug11554;
|
||||
drop view if exists v1;
|
||||
--enable_warnings
|
||||
create table t1 (i int);
|
||||
create function bug11554 () returns int return 1;
|
||||
create view v1 as select bug11554() as f;
|
||||
connection con2root;
|
||||
# This should not crash server
|
||||
insert into t1 (select f from v1);
|
||||
# Clean-up
|
||||
connection con1root;
|
||||
drop function bug11554;
|
||||
drop table t1;
|
||||
drop view v1;
|
||||
|
||||
#
|
||||
# BUG#NNNN: New bug synopsis
|
||||
#
|
||||
|
Reference in New Issue
Block a user