diff options
author | Alexander Nozdrin <alexander.nozdrin@oracle.com> | 2011-03-10 11:07:57 +0300 |
---|---|---|
committer | Alexander Nozdrin <alexander.nozdrin@oracle.com> | 2011-03-10 11:07:57 +0300 |
commit | 2b86f34a483e4fd09241abf0297acb5272358ead (patch) | |
tree | 5fa3a4d25f85e9fca1dd6180886d6e2bd4399afb | |
parent | d7a4372fbe367d54c086f5dfe3cdddf050247868 (diff) | |
download | mariadb-git-2b86f34a483e4fd09241abf0297acb5272358ead.tar.gz |
Patch for Bug#11765684 (58674: SP-cache does not detect changes in
pre-locking list caused by triggers).
The thing is that CREATE TRIGGER / DROP TRIGGER may actually
change pre-locking list of (some) stored routines.
The SP-cache does not detect such changes. Thus if sp_head-instance
is cached in SP-cache, subsequent executions of the cached
sp_head will use inaccurate pre-locking list.
The patch is to invalidate SP-cache on CREATE TRIGGER / DROP TRIGGER.
-rw-r--r-- | mysql-test/r/sp.result | 30 | ||||
-rw-r--r-- | mysql-test/r/trigger.result | 1 | ||||
-rw-r--r-- | mysql-test/t/sp.test | 41 | ||||
-rw-r--r-- | mysql-test/t/trigger.test | 4 | ||||
-rw-r--r-- | sql/sql_trigger.cc | 7 |
5 files changed, 78 insertions, 5 deletions
diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 243bfb6c07d..f9b338dd414 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -7452,4 +7452,34 @@ c1 # Cleanup drop table t1; drop procedure p1; + +# -- +# -- Bug 11765684 - 58674: SP-cache does not detect changes in +# -- pre-locking list caused by triggers +# --- +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS p1; +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT); +CREATE TABLE t3(a INT); +CREATE PROCEDURE p1() +INSERT INTO t1(a) VALUES (1); + +CREATE TRIGGER t1_ai AFTER INSERT ON t1 +FOR EACH ROW +INSERT INTO t2(a) VALUES (new.a); + +CALL p1(); + +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 +FOR EACH ROW +INSERT INTO t3(a) VALUES (new.a); + +CALL p1(); + +DROP TABLE t1, t2, t3; +DROP PROCEDURE p1; + # End of 5.5 test diff --git a/mysql-test/r/trigger.result b/mysql-test/r/trigger.result index b24c5b87fa0..11e0d7313b7 100644 --- a/mysql-test/r/trigger.result +++ b/mysql-test/r/trigger.result @@ -821,7 +821,6 @@ drop trigger t1_bi; create trigger t1_bi after insert on t1 for each row insert into t3 values (new.id); execute stmt1; call p1(); -ERROR 42S02: Table 'test.t3' doesn't exist deallocate prepare stmt1; drop procedure p1; drop table t1, t2, t3; diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 11edeaf9811..1ed11c50ba8 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -8713,4 +8713,45 @@ call p1(3, 2); drop table t1; drop procedure p1; +--echo +--echo # -- +--echo # -- Bug 11765684 - 58674: SP-cache does not detect changes in +--echo # -- pre-locking list caused by triggers +--echo # --- + +--disable_warnings +DROP TABLE IF EXISTS t1; +DROP TABLE IF EXISTS t2; +DROP TABLE IF EXISTS t3; +DROP PROCEDURE IF EXISTS p1; +--enable_warnings + +CREATE TABLE t1(a INT); +CREATE TABLE t2(a INT); +CREATE TABLE t3(a INT); + +CREATE PROCEDURE p1() + INSERT INTO t1(a) VALUES (1); + +--echo +CREATE TRIGGER t1_ai AFTER INSERT ON t1 + FOR EACH ROW + INSERT INTO t2(a) VALUES (new.a); + +--echo +CALL p1(); + +--echo +CREATE TRIGGER t1_bi BEFORE INSERT ON t1 + FOR EACH ROW + INSERT INTO t3(a) VALUES (new.a); + +--echo +CALL p1(); + +--echo +DROP TABLE t1, t2, t3; +DROP PROCEDURE p1; +--echo + --echo # End of 5.5 test diff --git a/mysql-test/t/trigger.test b/mysql-test/t/trigger.test index 3e4c3660f88..e5039c3ea23 100644 --- a/mysql-test/t/trigger.test +++ b/mysql-test/t/trigger.test @@ -998,10 +998,6 @@ call p1(); drop trigger t1_bi; create trigger t1_bi after insert on t1 for each row insert into t3 values (new.id); execute stmt1; -# Until we implement proper mechanism for invalidation of SP statements -# invoked whenever a table used in SP changes, this statement will fail with -# 'Table ... does not exist' error. ---error ER_NO_SUCH_TABLE call p1(); deallocate prepare stmt1; drop procedure p1; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index e986f6d7e92..4908fce5950 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -30,6 +30,7 @@ #include "sql_db.h" // get_default_db_collation #include "sql_acl.h" // *_ACL, is_acl_user #include "sql_handler.h" // mysql_ha_rm_tables +#include "sp_cache.h" // sp_invalidate_cache /*************************************************************************/ @@ -517,6 +518,12 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create) */ thd->locked_tables_list.reopen_tables(thd); + /* + Invalidate SP-cache. That's needed because triggers may change list of + pre-locking tables. + */ + sp_cache_invalidate(); + end: if (!result) { |