Triggers and Implicit Locks

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

I trigger possono servirsi di più tabelle, e se viene utilizzata un'istruzione LOCK TABLES su una di queste tabelle, il trigger potrebbe acquisire implicitamente un lock anche alle altre tabelle.

Se il trigger effettua solo letture su una tabella, allora il lock su quella tabella sarà di sola lettura. Se il trigger effettua operazioni di scrittura, il lock sulla tabella sarà in scrittura.

Esempio

LOCK TABLE table1 WRITE

Supponiamo che table1 contenga il seguente trigger:

CREATE TRIGGER trigger1 AFTER INSERT ON table1 FOR EACH ROW
BEGIN
  INSERT INTO table2 VALUES (1);
  UPDATE table3 SET writes = writes+1
    WHERE id = NEW.id AND EXISTS (SELECT id FROM table4);
END;

Not only is table1 write locked, table2 and table3 are also write locked, due to the possible INSERT and UPDATE, while table4 is read locked due to the SELECT.

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.