summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/sp-bugs.result14
-rw-r--r--mysql-test/t/sp-bugs.test21
-rw-r--r--sql/sp_cache.cc5
-rw-r--r--sql/sql_view.cc13
4 files changed, 43 insertions, 10 deletions
diff --git a/mysql-test/r/sp-bugs.result b/mysql-test/r/sp-bugs.result
index 38ddab52b8a..2374b433fba 100644
--- a/mysql-test/r/sp-bugs.result
+++ b/mysql-test/r/sp-bugs.result
@@ -59,4 +59,18 @@ CALL p1 ();
ERROR HY000: Trigger does not exist
DROP TABLE t1;
DROP PROCEDURE p1;
+#
+# Bug#50423: Crash on second call of a procedure dropping a trigger
+#
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+CALL p1 ();
+CALL p1 ();
+ERROR HY000: Trigger does not exist
+DROP TABLE t1;
+DROP PROCEDURE p1;
End of 5.1 tests
diff --git a/mysql-test/t/sp-bugs.test b/mysql-test/t/sp-bugs.test
index 1eb283f7874..8aa0791e265 100644
--- a/mysql-test/t/sp-bugs.test
+++ b/mysql-test/t/sp-bugs.test
@@ -80,4 +80,25 @@ CALL p1 ();
DROP TABLE t1;
DROP PROCEDURE p1;
+--echo #
+--echo # Bug#50423: Crash on second call of a procedure dropping a trigger
+--echo #
+
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+DROP TRIGGER IF EXISTS tr1;
+DROP PROCEDURE IF EXISTS p1;
+--enable_warnings
+
+CREATE TABLE t1 (f1 INTEGER);
+CREATE TRIGGER tr1 BEFORE INSERT ON t1 FOR EACH ROW SET @aux = 1;
+CREATE PROCEDURE p1 () DROP TRIGGER tr1;
+
+CALL p1 ();
+--error ER_TRG_DOES_NOT_EXIST
+CALL p1 ();
+
+DROP TABLE t1;
+DROP PROCEDURE p1;
+
--echo End of 5.1 tests
diff --git a/sql/sp_cache.cc b/sql/sp_cache.cc
index b8209a373a2..12d21aee22c 100644
--- a/sql/sp_cache.cc
+++ b/sql/sp_cache.cc
@@ -175,8 +175,9 @@ sp_head *sp_cache_lookup(sp_cache **cp, sp_name *name)
sp_cache_invalidate()
NOTE
- This is called when a VIEW definition is modifed. We can't destroy sp_head
- objects here as one may modify VIEW definitions from prelocking-free SPs.
+ This is called when a VIEW definition is created or modified (and in some
+ other contexts). We can't destroy sp_head objects here as one may modify
+ VIEW definitions from prelocking-free SPs.
*/
void sp_cache_invalidate()
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index c6d412112c2..c66990c54c6 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -400,17 +400,14 @@ bool mysql_create_view(THD *thd, TABLE_LIST *views,
DBUG_ASSERT(!lex->proc_list.first && !lex->result &&
!lex->param_list.elements);
- if (mode != VIEW_CREATE_NEW)
+ if (mode == VIEW_ALTER && fill_defined_view_parts(thd, view))
{
- if (mode == VIEW_ALTER &&
- fill_defined_view_parts(thd, view))
- {
- res= TRUE;
- goto err;
- }
- sp_cache_invalidate();
+ res= TRUE;
+ goto err;
}
+ sp_cache_invalidate();
+
if (!lex->definer)
{
/*