Oracle外键不加索引引起死锁示例建站知识
导读:1建站知识这篇文章主要介绍了Oracle外键不加索引引起死锁的情况及解决,需要的朋友可以参考下如何seo优化推广网站高端网站建设。
--创建一个表,此表作为子表 create table fk_t as select *from user_objects; delete from fk_t where object_id is null; commit; --创建一个表,此表作为父表 create table pk_t as select *from user_objects; d网站建设制作elete from pk_t where object_id is null; commit; --创建父表的主键 alter table PK_t add constraintpk_pktable primary key (OBJECT_ID); --创建子表的外键 alter table FK_t addconstraint fk_fktable foreign key (OBJECT_ID) references pk_t (OBJECT_ID); --session1:执行一个删除操作,这时候在子表和父表上都加了一个Row-S(SX)锁 delete from fk_t whereobject_id=100; delete from pk_t where object_id=100; --session2:执行另一个删除操作,网站优化seo培训发现这时候第二个删除语句等待 delete from fk_t whereobject_id=200; delete from pk_t whereobject_id=200; --回到session1:死锁马上发生 delete from pk_t whereobject_id=100; session2中报错: SQL> delete from pk_table where object_id=200; delete from pk_table where object_id=200 * 第 1seo网站关键词优化 行出现错误: ORA-00060: 等待资源时检测到死锁 当对子表的外键列添加索引后,死锁被消除,因为这时删除父表记录不需要对子表加表级锁。 --为外键建立索引 create index ind_pk_object_id on fk_t(object_id) nologging; --重复上面的操作session1 delete from fk_t whereobject_id=100; delete from pk_t whereobject_id=100; --session2 delete from fk_t whereobject_id=200; delete from pk_t whereobject_id=200; --回到session1不会发生死锁 delete from pk_t whereobject_id=100;相关如何seo优化推广网站高端网站建设。
声明: 本文由我的SEOUC技术文章主页发布于:2023-05-22 ,文章Oracle外键不加索引引起死锁示例建站知识主要讲述死锁,示例,Oracle外键不加索引引起死锁示例建站知网站建设源码以及服务器配置搭建相关技术文章。转载请保留链接: https://www.seouc.com/article/web_4317.html