Um gatilho pode ser bloqueado; como alguém determinaria isso?
Ao responderVou sentir falta de alguma mudança se eu substituir um gatilho oracle enquanto meu aplicativo estiver sendo executado?, Eu fui ver se o gatilho estava bloqueado por uma instrução INSERT. Não foi e não consigo encontrar nada na internet para sugerir que um gatilho pode ser bloqueado.
Se eu executar o seguinte em uma sessão:
create table test_trigger (id number);
create table test_trigger_h (id number);
create or replace trigger test_trigger_t
after insert on test_trigger for each row
begin
insert into test_trigger_h (id) values (:new.id);
end;
/
insert into test_trigger
select level
from dual
connect by level <= 1000000;
e, em seguida, em uma segunda sessão, tente descobrir quais bloqueios estão ocorrendo e obtenho o seguinte:
select object_name, object_type
, case l.block
when 0 then 'Not Blocking'
when 1 then 'Blocking'
when 2 then 'Global'
end as status
, case v.locked_mode
when 0 then 'None'
when 1 then 'Null'
when 2 then 'Row-S (SS)'
when 3 then 'Row-X (SX)'
when 4 then 'Share'
when 5 then 'S/Row-X (SSX)'
when 6 then 'Exclusive'
else to_char(lmode)
end as mode_held
from v$locked_object v
join dba_objects d
on v.object_id = d.object_id
join v$lock l
on v.object_id = l.id1
join v$session s
on v.session_id = s.sid
;
OBJECT_NAME OBJECT_TYPE STATUS MODE_HELD
-------------------- -------------------- --------------- ---------------
TEST_TRIGGER TABLE Not Blocking Row-X (SX)
TEST_TRIGGER_H TABLE Not Blocking Row-X (SX)
Segundo a Oracle, o gatilho énão sendo bloqueado.
No entanto, se eu tentar substituir o gatilho enquanto a instrução INSERT estiver em execução, ele não será substituído até que a instrução seja concluída (sem incluir uma confirmação), o que implica que o gatilhoé bloqueado.
Nesta situação, o gatilho é bloqueado e, em caso afirmativo, como se determina que é?