mariadb/mysql-test/suite/atomic/create_trigger2.result
Monty ffe7f19fa6 MDEV-24746 Atomic CREATE TRIGGER
The purpose of this task is to ensure that CREATE TRIGGER is atomic

When a trigger is created, we first create a trigger_name.TRN file and then
create or update the table_name.TRG files.
This is done by creating .TRN~ and .TRG~ files and replacing (or creating)
the result files.

The new logic is

- Log CREATE TRIGGER to DDL log, with a marker if old trigger existsted
- If old .TRN or .TRG files exists, make backup copies of these
- Create the new .TRN and .TRG files as before
- Remove the backups

Crash recovery
- If query has been logged to binary log:
  - delete any left over backup files
- else
   - Delete any old .TRN~ or .TRG~ files
   - If there was orignally some triggers (old .TRG file existed)
      - If we crashed before creating all backup files
         - Delete existing backup files
      - else
         - Restore backup files
      - end
   - Delete .TRN and .TRG file (as there was no triggers before

One benefit of the new code is that CREATE OR REPLACE TRIGGER is now
totally atomic even if there existed an old trigger: Either the old
trigger will be replaced or the old one will be left untouched.

Other things:
- If sql_create_definition_file() would fail, there could be memory leaks
  in CREATE TRIGGER, DROP TRIGGER or CREATE OR REPLACE TRIGGER.  This
  is now fixed.
2021-05-19 22:54:13 +02:00

94 lines
4.1 KiB
Text

"position: 1"
"position: 2"
"position: 3"
t1.TRG
t1_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
"position: 4"
t1.TRG
t1_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
"position: 5"
t1.TRG
t1_trg.TRN
t2_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t2_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t2_trg before insert on t1 for each row
begin
if isnull(new.b) then
set new.b:= 2000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
"position: 6"
t1.TRG
t1_trg.TRN
t2_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t2_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t2_trg before insert on t1 for each row
begin
if isnull(new.b) then
set new.b:= 2000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
"position: 7"
t1.TRG
t1_trg.TRN
t2_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t2_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t2_trg before insert on t1 for each row
begin
if isnull(new.b) then
set new.b:= 2000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
"position: 8"
t1.TRG
t1_trg.TRN
t2_trg.TRN
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t1_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t1_trg before insert on t1 for each row
begin
if isnull(new.a) then
set new.a:= 1000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #
Trigger sql_mode SQL Original Statement character_set_client collation_connection Database Collation Created
t2_trg STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` trigger t2_trg before insert on t1 for each row
begin
if isnull(new.b) then
set new.b:= 3000;
end if;
end latin1 latin1_swedish_ci latin1_swedish_ci #