You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7 KiB

Fix for bug #18153 "ALTER/OPTIMIZE/REPAIR on transactional tables corrupt triggers". Applying ALTER/OPTIMIZE/REPAIR TABLE statements to transactional table or to table of any type on Windows caused disappearance of its triggers. Bug was introduced in 5.0.19 by my fix for bug #13525 "Rename table does not keep info of triggers" (see comment for sql_table.cc for more info). . mysql-test/r/trigger.result: Added test-case covering handling of triggers when one does ALTER TABLE which should move table to different database. mysql-test/t/trigger.test: Added test-case covering handling of triggers when one does ALTER TABLE which should move table to different database. sql/sql_table.cc: mysql_alter_table(): Removal of strdup() which is no longer necessary allows us to preserve nice assumption that "(new_db != db || new_table != table_name) indicates that table will be renamed. So now we really can use this condition to avoid updating trigger definitions when table is not renamed. Note that we can't use (alter_info->flags & ALTER_RENAME) condition instead since it can be also true when we do "ALTER TABLE t1 RENAME TO t1". sql/sql_trigger.cc: Table_triggers_list::change_table_name(): Mentioned assumption that subject table is not renamed to itself in method description. Added DBUG_ASSERT() to catch wrong usage of this method. mysql-test/r/trigger-trans.result: New BitKeeper file ``mysql-test/r/trigger-trans.result'' mysql-test/t/trigger-trans.test: New BitKeeper file ``mysql-test/t/trigger-trans.test''
20 years ago
  1. drop table if exists t1;
  2. create table t1 (a varchar(16), b int) engine=innodb;
  3. create trigger t1_bi before insert on t1 for each row
  4. begin
  5. set new.a := upper(new.a);
  6. set new.b := new.b + 3;
  7. end|
  8. select trigger_schema, trigger_name, event_object_schema,
  9. event_object_table, action_statement from information_schema.triggers
  10. where event_object_schema = 'test' and event_object_table = 't1';
  11. trigger_schema trigger_name event_object_schema event_object_table action_statement
  12. test t1_bi test t1 begin
  13. set new.a := upper(new.a);
  14. set new.b := new.b + 3;
  15. end
  16. insert into t1 values ('The Lion', 10);
  17. select * from t1;
  18. a b
  19. THE LION 13
  20. optimize table t1;
  21. Table Op Msg_type Msg_text
  22. test.t1 optimize status OK
  23. select trigger_schema, trigger_name, event_object_schema,
  24. event_object_table, action_statement from information_schema.triggers
  25. where event_object_schema = 'test' and event_object_table = 't1';
  26. trigger_schema trigger_name event_object_schema event_object_table action_statement
  27. test t1_bi test t1 begin
  28. set new.a := upper(new.a);
  29. set new.b := new.b + 3;
  30. end
  31. insert into t1 values ('The Unicorn', 20);
  32. select * from t1;
  33. a b
  34. THE LION 13
  35. THE UNICORN 23
  36. alter table t1 add column c int default 0;
  37. select trigger_schema, trigger_name, event_object_schema,
  38. event_object_table, action_statement from information_schema.triggers
  39. where event_object_schema = 'test' and event_object_table = 't1';
  40. trigger_schema trigger_name event_object_schema event_object_table action_statement
  41. test t1_bi test t1 begin
  42. set new.a := upper(new.a);
  43. set new.b := new.b + 3;
  44. end
  45. insert into t1 values ('Alice', 30, 1);
  46. select * from t1;
  47. a b c
  48. THE LION 13 0
  49. THE UNICORN 23 0
  50. ALICE 33 1
  51. alter table t1 rename to t1;
  52. select trigger_schema, trigger_name, event_object_schema,
  53. event_object_table, action_statement from information_schema.triggers
  54. where event_object_schema = 'test' and event_object_table = 't1';
  55. trigger_schema trigger_name event_object_schema event_object_table action_statement
  56. test t1_bi test t1 begin
  57. set new.a := upper(new.a);
  58. set new.b := new.b + 3;
  59. end
  60. insert into t1 values ('The Crown', 40, 1);
  61. select * from t1;
  62. a b c
  63. THE LION 13 0
  64. THE UNICORN 23 0
  65. ALICE 33 1
  66. THE CROWN 43 1
  67. alter table t1 rename to t1, add column d int default 0;
  68. select trigger_schema, trigger_name, event_object_schema,
  69. event_object_table, action_statement from information_schema.triggers
  70. where event_object_schema = 'test' and event_object_table = 't1';
  71. trigger_schema trigger_name event_object_schema event_object_table action_statement
  72. test t1_bi test t1 begin
  73. set new.a := upper(new.a);
  74. set new.b := new.b + 3;
  75. end
  76. insert into t1 values ('The Pie', 50, 1, 1);
  77. select * from t1;
  78. a b c d
  79. THE LION 13 0 0
  80. THE UNICORN 23 0 0
  81. ALICE 33 1 0
  82. THE CROWN 43 1 0
  83. THE PIE 53 1 1
  84. drop table t1;