Commit 7fa9f986 authored by Konstantin Osipov's avatar Konstantin Osipov

Backport of:

------------------------------------------------------------
revno: 2617.69.32
committer: Dmitry Lenev <dlenev@mysql.com>
branch nick: mysql-next-bg46747
timestamp: Wed 2009-08-19 18:12:27 +0400
message:
  Fix for bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
  on TRIGGER + TEMP table".

  Server crashed when one tried to drop trigger which had its subject
  table shadowed by a temporary table with the same name.

  This problem occured because in such situation DROP TRIGGER has opened
  temporary table instead of base table on which trigger was defined.
  Attempt to upgrade metadata lock on this temporary table led to crash
  (we don't acquire metadata locks for temporary tables).

  This fix ensures that DROP TRIGGER ignores temporary tables when
  trying to open table on which trigger to be dropped is defined.
parent 0104ea3c
......@@ -2162,3 +2162,23 @@ Warning 1265 Data truncated for column 'trg2' at row 1
DROP TRIGGER trg1;
DROP TRIGGER trg2;
DROP TABLE t1;
#
# Bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
# on TRIGGER + TEMP table".
#
drop trigger if exists t1_bi;
drop temporary table if exists t1;
drop table if exists t1;
create table t1 (i int);
create trigger t1_bi before insert on t1 for each row set @a:=1;
# Create temporary table which shadows base table with trigger.
create temporary table t1 (j int);
# Dropping of trigger should succeed.
drop trigger t1_bi;
select trigger_name from information_schema.triggers
where event_object_schema = 'test' and event_object_table = 't1';
trigger_name
# Clean-up.
drop temporary table t1;
drop table t1;
End of 6.0 tests.
......@@ -2489,3 +2489,28 @@ DROP TRIGGER trg1;
DROP TRIGGER trg2;
DROP TABLE t1;
--echo #
--echo # Bug #46747 "Crash in MDL_ticket::upgrade_shared_lock_to_exclusive
--echo # on TRIGGER + TEMP table".
--echo #
--disable_warnings
drop trigger if exists t1_bi;
drop temporary table if exists t1;
drop table if exists t1;
--enable_warnings
create table t1 (i int);
create trigger t1_bi before insert on t1 for each row set @a:=1;
--echo # Create temporary table which shadows base table with trigger.
create temporary table t1 (j int);
--echo # Dropping of trigger should succeed.
drop trigger t1_bi;
select trigger_name from information_schema.triggers
where event_object_schema = 'test' and event_object_table = 't1';
--echo # Clean-up.
drop temporary table t1;
drop table t1;
--echo End of 6.0 tests.
......@@ -443,6 +443,11 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
/* We also don't allow creation of triggers on views. */
tables->required_type= FRMTYPE_TABLE;
/*
Also prevent DROP TRIGGER from opening temporary table which might
shadow base table on which trigger to be dropped is defined.
*/
tables->skip_temporary= TRUE;
/* Keep consistent with respect to other DDL statements */
mysql_ha_rm_tables(thd, tables);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment