mirror of
				https://github.com/MariaDB/server.git
				synced 2025-11-03 14:33:32 +03:00 
			
		
		
		
	BOGUS "THE TABLE MYSQL.PROC IS MISSING,..." There was a race condition between loading a stored routine (function/procedure/trigger) specified by fully qualified name SCHEMA_NAME.PROC_NAME and dropping the stored routine database. The problem was that there is a window for race condition when one server thread tries to load a stored routine being executed and the other thread tries to drop the stored routine schema. This condition race window exists in implementation of function mysql_change_db() called by db_load_routine() during loading of stored routine to cache. Function mysql_change_db() calls check_db_dir_existence() that might failed because specified database was dropped during concurrent execution of DROP SCHEMA statement. db_load_routine() calls mysql_change_db() with flag 'force_switch' set to 'true' value so when referenced db is not found then my_error() is not called and function mysql_change_db() returns ok. This shadows information about schema opening error in db_load_routine(). Then db_load_routine() makes attempt to parse stored routine that is failed. This makes to return error to sp_cache_routines_and_add_tables_aux() but since during error generation a call to my_error wasn't made and hence THD::main_da wasn't set we set the generic "mysql.proc table corrupt" error when running sp_cache_routines_and_add_tables_aux(). The fix is to install an error handler inside db_load_routine() for the mysql_op_change_db() call, and check later if the ER_BAD_DB_ERROR was caught.
		
			
				
	
	
		
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			88 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
# This test should work in embedded server after mysqltest is fixed
 | 
						|
-- source include/not_embedded.inc
 | 
						|
 | 
						|
# Save the initial number of concurrent sessions
 | 
						|
--source include/count_sessions.inc
 | 
						|
 | 
						|
--echo Tests of synchronization of stored procedure execution.
 | 
						|
 | 
						|
--source include/have_debug_sync.inc
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # Bug#48157: crash in Item_field::used_tables
 | 
						|
--echo #
 | 
						|
 | 
						|
CREATE TABLE t1 AS SELECT 1 AS a, 1 AS b;
 | 
						|
CREATE TABLE t2 AS SELECT 1 AS a, 1 AS b;
 | 
						|
 | 
						|
DELIMITER |;
 | 
						|
 | 
						|
CREATE PROCEDURE p1()
 | 
						|
BEGIN
 | 
						|
   UPDATE t1 JOIN t2 USING( a, b ) SET t1.b = 1, t2.b = 1;
 | 
						|
END|
 | 
						|
 | 
						|
DELIMITER ;|
 | 
						|
 | 
						|
connect (con1,localhost,root,,);
 | 
						|
connect (con2,localhost,root,,);
 | 
						|
 | 
						|
connection con1;
 | 
						|
LOCK TABLES t1 WRITE, t2 WRITE;
 | 
						|
 | 
						|
connection con2;
 | 
						|
LET $ID= `select connection_id()`;
 | 
						|
SET DEBUG_SYNC = 'multi_update_reopen_tables SIGNAL parked WAIT_FOR go';
 | 
						|
--send CALL p1()
 | 
						|
 | 
						|
connection con1;
 | 
						|
let $wait_condition= SELECT 1 FROM information_schema.processlist WHERE ID = $ID AND
 | 
						|
state = "Locked";
 | 
						|
--source include/wait_condition.inc
 | 
						|
DROP TABLE t1, t2;
 | 
						|
SET DEBUG_SYNC = 'now WAIT_FOR parked';
 | 
						|
CREATE TABLE t1 AS SELECT 1 AS a, 1 AS b;
 | 
						|
CREATE TABLE t2 AS SELECT 1 AS a, 1 AS b;
 | 
						|
SET DEBUG_SYNC = 'now SIGNAL go';
 | 
						|
 | 
						|
connection con2;
 | 
						|
--reap
 | 
						|
 | 
						|
disconnect con1;
 | 
						|
disconnect con2;
 | 
						|
connection default;
 | 
						|
 | 
						|
--echo # Without the DEBUG_SYNC supplied in the same patch as this test in the 
 | 
						|
--echo # code, this test statement will hang.
 | 
						|
DROP TABLE t1, t2;
 | 
						|
DROP PROCEDURE p1;
 | 
						|
 | 
						|
--echo #
 | 
						|
--echo # test for bug#11756013
 | 
						|
--echo #
 | 
						|
--disable_warnings
 | 
						|
DROP SCHEMA IF EXISTS s1;
 | 
						|
--enable_warnings
 | 
						|
CREATE SCHEMA s1;
 | 
						|
CREATE PROCEDURE s1.p1() BEGIN END;
 | 
						|
 | 
						|
connect (con3, localhost, root);
 | 
						|
SET DEBUG_SYNC='before_db_dir_check SIGNAL check_db WAIT_FOR dropped_schema';
 | 
						|
--send CALL s1.p1
 | 
						|
 | 
						|
connection default;
 | 
						|
SET DEBUG_SYNC='now WAIT_FOR check_db';
 | 
						|
DROP SCHEMA s1;
 | 
						|
SET DEBUG_SYNC='now SIGNAL dropped_schema';
 | 
						|
 | 
						|
connection con3;
 | 
						|
--error ER_BAD_DB_ERROR
 | 
						|
--reap
 | 
						|
connection default;
 | 
						|
disconnect con3;
 | 
						|
 | 
						|
SET DEBUG_SYNC = 'RESET';
 | 
						|
 | 
						|
# Wait till we reached the initial number of concurrent sessions
 | 
						|
--source include/wait_until_count_sessions.inc
 |