diff options
author | unknown <dlenev@mysql.com> | 2005-09-15 03:56:09 +0400 |
---|---|---|
committer | unknown <dlenev@mysql.com> | 2005-09-15 03:56:09 +0400 |
commit | d5303b8ab8872af54c5947c23b0379d803f96506 (patch) | |
tree | 0f615e302d79fa87c5b5c4e98170b68ece5b0fa8 /mysql-test | |
parent | 8b2b0e2418b2edb1f4732eea4848c5807ef799f9 (diff) | |
download | mariadb-git-d5303b8ab8872af54c5947c23b0379d803f96506.tar.gz |
Fix for bug #12704 "Server crashes during trigger execution".
This bug occurs when some trigger for table used by DML statement is created
or changed while statement was waiting in lock_tables(). In this situation
prelocking set which we have calculated becames invalid which can easily lead
to errors and even in some cases to crashes.
With proposed patch we no longer silently reopen tables in lock_tables(),
instead caller of lock_tables() becomes responsible for reopening tables and
recalculation of prelocking set.
mysql-test/t/trigger.test:
Added tests for bug #12704 "Server crashes during trigger execution".
Unfortunately these tests rely on the order in which tables are locked
by statement so they are non-determenistic and therefore should be disabled.
sql/lock.cc:
mysql_lock_tables():
Now instead of always reopening altered or dropped tables by itself
mysql_lock_tables() can notify upper level and rely on caller doing this.
sql/mysql_priv.h:
Now mysql_lock_tables() can either reopen deleted or altered tables by itself
or notify caller about such situation through 'need_reopen' argument and rely
on it in this.
Also lock_tables() has new 'need_reopen' out parameter through which it
notifies caller that some tables were altered or dropped so he needs to reopen
them (and rebuild prelocking set some triggers may change or simply appear).
sql/sp.cc:
sp_add_used_routine():
To be able to restore LEX::sroutines_list to its state right after parsing
we now adjust LEX::sroutines_list_own_last/sroutines_list_own_elements when
we add directly used routine.
sp_remove_not_own_routines():
Added procedure for restoring LEX::sroutines/sroutines_list to their state
right after parsing (by throwing out non-directly used routines).
sp_cache_routines_and_add_tables_for_view()/sp_update_stmt_used_routines():
We should use LEX::sroutines_list instead of LEX::sroutines as source of
routines used by view, since LEX::sroutines is not availiable for view
on second attempt to open it (see comment in open_tables() about it).
sql/sp.h:
sp_remove_not_own_routines():
Added procedure for restoring LEX::sroutines/sroutines_list to their state
right after parsing (by throwing out non-directly used routines).
sql/sp_head.cc:
Removed assert which is no longer always true.
sql/sql_base.cc:
reopen_table():
When we re-open table and do shallow copy of TABLE object we should adjust
pointers to it in associated Table_triggers_list object. Removed nil
operation.
open_tables():
Now this function is able to rebuild prelocking set for statement if it is
needed. It also correctly handles FLUSH TABLES which may occur during its
execution.
lock_tables():
Instead of allowing mysql_lock_tables() to silently reopen altered or dropped
tables let us notify caller and rely on that it will do reopen itself.
This solves the problem when trigger suddenly appears or changed during
mysq_lock_tables().
close_tables_for_reopen():
Added routine for properly preparing for reopening of tables and recalculation
of set of prelocked tables.
sql/sql_handler.cc:
Here we let mysql_lock_tables() to reopen dropped or altered tables by itself.
sql/sql_insert.cc:
Here we let mysql_lock_tables() to reopen dropped or altered tables by itself.
sql/sql_lex.cc:
LEX:
Added 'sroutines_list_own_last' and 'sroutines_list_own_elements' members
which are used for keeping state in which 'sroutines_list' was right after
statement parsing (and for restoring of this list to this state).
sql/sql_lex.h:
LEX:
Added 'sroutines_list_own_last' and 'sroutines_list_own_elements' members
which are used for keeping state in which 'sroutines_list' was right after
statement parsing (and for restoring of this list to this state).
Added chop_off_not_own_tables() method to simplify throwing away list
of implicitly used (prelocked) tables.
sql/sql_prepare.cc:
Now instead of silently reopening altered or dropped tables in
lock_tables() we notify caller and rely on that the caller will
reopen tables.
sql/sql_table.cc:
Here we let mysql_lock_tables() to reopen dropped or altered tables by itself.
sql/sql_trigger.cc:
Added Table_triggers_list::set_table() method to adjust Table_triggers_list
to new pointer to TABLE instance.
sql/sql_trigger.h:
Added Table_triggers_list::set_table() method to adjust Table_triggers_list
to new pointer to TABLE instance.
sql/sql_update.cc:
Now instead of silently reopening altered or dropped tables in
lock_tables() we notify caller and rely on that the caller will
reopen tables.
Diffstat (limited to 'mysql-test')
-rw-r--r-- | mysql-test/t/trigger.test | 116 |
1 files changed, 113 insertions, 3 deletions
diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index a770782e5db..cd79eb82ace 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -10,6 +10,11 @@ drop function if exists f1; drop procedure if exists p1; --enable_warnings +# Create additional connections used through test +connect (addconroot1, localhost, root,,); +connect (addconroot2, localhost, root,,); +connection default; + create table t1 (i int); # let us test some very simple trigger @@ -680,12 +685,10 @@ end| delimiter ;| update t1 set data = 1; -connect (addconroot, localhost, root,,); -connection addconroot; +connection addconroot1; update t1 set data = 2; connection default; -disconnect addconroot; drop table t1; # @@ -765,3 +768,110 @@ insert into t1 values (3); select * from t1; drop trigger t1_bi; drop tables t1, t2; + +# Tests for bug #12704 "Server crashes during trigger execution". +# If we run DML statements and CREATE TRIGGER statements concurrently +# it may happen that trigger will be created while DML statement is +# waiting for table lock. In this case we have to reopen tables and +# recalculate prelocking set. +# Unfortunately these tests rely on the order in which tables are locked +# by statement so they are non determenistic and are disabled. +--disable_parsing +create table t1 (id int); +create table t2 (id int); +create table t3 (id int); +create function f1() returns int return (select max(id)+2 from t2); +create view v1 as select f1() as f; + +# Let us check that we notice trigger at all +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(id) from t2)), (2); +--sleep 1 +connection addconroot2; +create trigger t1_trg before insert on t1 for each row set NEW.id:= 1; +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; + +# Check that we properly calculate new prelocking set +insert into t2 values (3); +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(id) from t2)), (4); +--sleep 1 +connection addconroot2; +drop trigger t1_trg; +create trigger t1_trg before insert on t1 for each row + insert into t3 values (new.id); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# We should be able to do this even if fancy views are involved +connection addconroot1; +lock tables t2 write; +connection default; +send insert into t1 values ((select max(f) from v1)), (6); +--sleep 1 +connection addconroot2; +drop trigger t1_trg; +create trigger t1_trg before insert on t1 for each row + insert into t3 values (new.id + 100); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# This also should work for multi-update +# Let us drop trigger to demonstrate that prelocking set is really +# rebuilt +drop trigger t1_trg; +connection addconroot1; +lock tables t2 write; +connection default; +send update t1, t2 set t1.id=10 where t1.id=t2.id; +--sleep 1 +connection addconroot2; +create trigger t1_trg before update on t1 for each row + insert into t3 values (new.id); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +# And even for multi-update converted from ordinary update thanks to view +drop view v1; +drop trigger t1_trg; +create view v1 as select t1.id as id1 from t1, t2 where t1.id= t2.id; +insert into t2 values (10); +connection addconroot1; +lock tables t2 write; +connection default; +send update v1 set id1= 11; +--sleep 1 +connection addconroot2; +create trigger t1_trg before update on t1 for each row + insert into t3 values (new.id + 100); +connection addconroot1; +unlock tables; +connection default; +reap; +select * from t1; +select * from t3; + +drop function f1; +drop view v1; +drop table t1, t2, t3; +--enable_parsing |