是的,父表的更新將獲得對子表的鎖定。下面是一個測試案例,證明這是可能的。
查找並追蹤特定的間歇性鎖定問題可能很痛苦。即使你無法追查具體情況,修改任何代碼以避免併發DML和DDL也是一個好主意。它不僅會導致鎖定問題,還會破壞SELECT
語句。
如果卸下併發是出了問題,你可能至少要啓用DDL_LOCK_TIMEOUT使得truncate
語句將等待鎖,而不是立即失敗:alter session set ddl_lock_timeout = 100000;
--Create parent/child tables, with or without an indexed foreign key.
create table parent_table(a number primary key);
insert into parent_table values(1);
insert into parent_table values(2);
create table child_table(a number references parent_table(a));
insert into child_table values(1);
commit;
--Session 1: Update parent table.
begin
loop
update parent_table set a = 2 where a = 2;
commit;
end loop;
end;
/
--Session 2: Truncate child table. Eventulaly it will throw this error:
--ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
begin
loop
execute immediate 'truncate table child_table';
end loop;
end;
/
請參見: http://stackoverflow.com/questions/4842765/ora-00054-resource-busy-and-acquire-with-nowait-specified-or-timeout-expired – Syntax