Skip to content
  • Gopal Shankar's avatar
    9d07216c
    WL#6383 Define and Implement API for Trigger · 9d07216c
    Gopal Shankar authored
    Triggers are implemented as collection of items per dd::Table
    object.
    
    A) Following are the signature of new DD API's implemented:
    
      * Check if table has triggers.
    
        virtual bool has_trigger() const = 0;
    
      * Get const reference to Trigger_collection.
    
        virtual const Trigger_collection&
        dd::Table::triggers() const = 0;
    
      * Get non-const pointer to Trigger_collection.
    
        virtual Trigger_collection *dd::Table::triggers() = 0;
    
      * Add new trigger.
    
        virtual Trigger *
        add_trigger(Trigger::enum_action_timing at,
                    Trigger::enum_event_type et) = 0;
    
      * Get Trigger object for the given trigger name.
    
        virtual const Trigger*
        get_trigger(const char *name) const = 0;
    
      * Add new trigger just after the trigger specified in argument.
    
        virtual Trigger *
        add_trigger_following(const Trigger *trigger,
                              Trigger::enum_action_timing at,
                              Trigger::enum_event_type et) = 0;
    
      * Add new trigger just before the trigger specified in argument.
    
        virtual Trigger *
        add_trigger_preceding(const Trigger *trigger,
                              Trigger::enum_action_timing at,
                              Trigger::enum_event_type et) = 0;
    
      * Drop the given trigger object.
    
        virtual void drop_trigger(Trigger *trigger) = 0;
    
      * Drop all triggers.
    
        virtual void drop_all_triggers() = 0;
    
      * Get table name of a given trigger name.
    
        dd::cache::Dictionary_client::
          get_table_name_by_trigger_name(
            Object_id schema_id,
            const std::string &trigger_name,
            std::string *table_name);
    
    B) Following section highlight the steps to carry on various
    operations on mysql.triggers DD table.
    
      i) Steps to add trigger:
      - Get dd::Table object for which you want to add trigger.
      - Invoke dd::Table::add_trigger*() API.
      - Set dd::Trigger attributes.
      - Store the dd::Table object. All the trigger objects gets
        stored in mysql.triggers.
    
      ii) Steps to get dd::Table for a given trigger name:
      - Invoke
        Dictionary_client::get_table_name_by_trigger_name()
        with a trigger name to get the table name for which
        the trigger belongs to.
      - Make sure you acquire desired MDL lock on table name.
      - Get dd::Table object using Dictionary_client::acquire<>().
    
      iii) Steps to drop trigger:
      - Follow steps to get dd::Table given trigger name above.
      - Use dd::Table::get_trigger(<trigger_name>) API to get the
        dd::Trigger object.
      - Invoke dd::Table::drop_trigger(Trigger*) to remove the
        trigger on the Table.
      - Store dd::Table object, which will remove the trigger from
        mysql.triggers DD table.
    
    C) Implemented a method to move all triggers from a table to another.
       This is mostly used during ALTER TABLE.
    
      Triggers from from_schema_name.from_table_name will be moved into
      to_schema_name.to_table_name and the transaction will be committed.
    
        bool dd::move_triggers(THD *thd,
                               const char *from_schema_name,
                               const char *from_name,
                               const char *to_schema_name,
                               const char *to_name);
    9d07216c
    WL#6383 Define and Implement API for Trigger
    Gopal Shankar authored
    Triggers are implemented as collection of items per dd::Table
    object.
    
    A) Following are the signature of new DD API's implemented:
    
      * Check if table has triggers.
    
        virtual bool has_trigger() const = 0;
    
      * Get const reference to Trigger_collection.
    
        virtual const Trigger_collection&
        dd::Table::triggers() const = 0;
    
      * Get non-const pointer to Trigger_collection.
    
        virtual Trigger_collection *dd::Table::triggers() = 0;
    
      * Add new trigger.
    
        virtual Trigger *
        add_trigger(Trigger::enum_action_timing at,
                    Trigger::enum_event_type et) = 0;
    
      * Get Trigger object for the given trigger name.
    
        virtual const Trigger*
        get_trigger(const char *name) const = 0;
    
      * Add new trigger just after the trigger specified in argument.
    
        virtual Trigger *
        add_trigger_following(const Trigger *trigger,
                              Trigger::enum_action_timing at,
                              Trigger::enum_event_type et) = 0;
    
      * Add new trigger just before the trigger specified in argument.
    
        virtual Trigger *
        add_trigger_preceding(const Trigger *trigger,
                              Trigger::enum_action_timing at,
                              Trigger::enum_event_type et) = 0;
    
      * Drop the given trigger object.
    
        virtual void drop_trigger(Trigger *trigger) = 0;
    
      * Drop all triggers.
    
        virtual void drop_all_triggers() = 0;
    
      * Get table name of a given trigger name.
    
        dd::cache::Dictionary_client::
          get_table_name_by_trigger_name(
            Object_id schema_id,
            const std::string &trigger_name,
            std::string *table_name);
    
    B) Following section highlight the steps to carry on various
    operations on mysql.triggers DD table.
    
      i) Steps to add trigger:
      - Get dd::Table object for which you want to add trigger.
      - Invoke dd::Table::add_trigger*() API.
      - Set dd::Trigger attributes.
      - Store the dd::Table object. All the trigger objects gets
        stored in mysql.triggers.
    
      ii) Steps to get dd::Table for a given trigger name:
      - Invoke
        Dictionary_client::get_table_name_by_trigger_name()
        with a trigger name to get the table name for which
        the trigger belongs to.
      - Make sure you acquire desired MDL lock on table name.
      - Get dd::Table object using Dictionary_client::acquire<>().
    
      iii) Steps to drop trigger:
      - Follow steps to get dd::Table given trigger name above.
      - Use dd::Table::get_trigger(<trigger_name>) API to get the
        dd::Trigger object.
      - Invoke dd::Table::drop_trigger(Trigger*) to remove the
        trigger on the Table.
      - Store dd::Table object, which will remove the trigger from
        mysql.triggers DD table.
    
    C) Implemented a method to move all triggers from a table to another.
       This is mostly used during ALTER TABLE.
    
      Triggers from from_schema_name.from_table_name will be moved into
      to_schema_name.to_table_name and the transaction will be committed.
    
        bool dd::move_triggers(THD *thd,
                               const char *from_schema_name,
                               const char *from_name,
                               const char *to_schema_name,
                               const char *to_name);
Loading