Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-10164

Add support for TRIGGERS that fire on multiple events

Details

    Description

      Add support for TRIGGER events that can fire for one or many of
      INSERT, UPDATE and DELETE

      The current syntax for triggers are:

      CREATE [OR REPLACE]
          [DEFINER = { user | CURRENT_USER }]
          TRIGGER [IF NOT EXISTS] trigger_name trigger_time trigger_event
          ON tbl_name FOR EACH ROW trigger_stmt
      

      The task is to replace trigger_event with:

       { event [ OR ... ] }
      

      Oracle and PostgreSQL both support this extension to CREATE TRIGGER.

      PostgreSQL solves the issue witth information schema by duplicating the trigger for as many times as there are events.The primary key of the view triggers is because of this trigger_catalog, trigger_schema, event_object_table, trigger_name, event.

      To distinguish which event fired the trigger, Oracle supports event flags:

      CREATE TRIGGER tr1
      BEFORE DELETE OR INSERT OR UPDATE ON t1
      FOR EACH ROW
      BEGIN
        IF INSERTING THEN   ...
        ELSIF DELETING THEN ...
        ELSIF UPDATING THEN ...
        ENDIF;
      END;
      

      We should also support this.

      If the clause INSERTING specified inside a trigger's body and the trigger event is not associated with INSERT, then the error ER_INCOMPATIBLE_EVENT_FLAG be produced. The same is true for the relating clauses: UPDATING or DELETING inside a trigger body not associated correspondingly with UPDATE event and DELETE event will produce the error ER_INCOMPATIBLE_EVENT_FLAG

      Oracle DBMS has the following semantic on accessing old and new values of columns being affected by the trigger, quoting:
      "Depending on the type of triggering statement, certain correlation names might not have any meaning.

      A trigger fired by an INSERT statement has meaningful access to new column values only. Because the row is being created by the INSERT, the old values are null.
      A trigger fired by an UPDATE statement has access to both old and new column values for both BEFORE and AFTER row triggers.
      A trigger fired by a DELETE statement has meaningful access to :old column values only. Because the row no longer exists after the row is deleted, the :new values are NULL. However, you cannot modify :new values: ORA-4084 is raised if you try to modify :new values."

      This semantic is also applied to triggers in MariaDB.

      Attachments

        Issue Links

          Activity

            Transition Time In Source Status Execution Times
            Dmitry Shulga made transition -
            Open In Progress
            3166d 15h 29m 1
            Dmitry Shulga made transition -
            Stalled In Progress
            9d 15h 10m 1
            Dmitry Shulga made transition -
            In Progress In Review
            16d 4h 14m 2
            Oleksandr Byelkin made transition -
            In Review Stalled
            13d 7h 20m 2
            Dmitry Shulga made transition -
            Stalled In Testing
            1d 22h 35m 1
            Ramesh Sivaraman made transition -
            In Testing Stalled
            33d 4h 40m 1
            Dmitry Shulga made transition -
            Stalled Closed
            3d 3h 53m 1

            People

              shulga Dmitry Shulga
              monty Michael Widenius
              Votes:
              3 Vote for this issue
              Watchers:
              10 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.