为什么外键最好加上索引?
来源:互联网 发布:社交网络种子 编辑:程序博客网 时间:2024/06/05 08:58
今天遇到一个数据库DeadLock的问题,与同事讨论,一个同事忽然问了一句:“为什么外键没有索引会导致deadlock“?
为了回答这个问题,我直接翻了Oracle文档,里面两张图画的非常直接。
文章地址:http://docs.oracle.com/cd/B19306_01/server.102/b14220/data_int.htm#sthref3108
Unindexed foreign keys cause DML on the primary key to geta share row exclusive table lock (also sometimes called a share-subexclusive table lock, SSX) on the foreign key table. This prevents DML on the table by other transactions. The SSX lock is released immediately after it is obtained. If multiple primary keys are updated or deleted, the lock is obtained and released once for each row.
Figure 21-8 Locking Mechanisms When No Index Is Defined on the Foreign Key
Indexed foreign keys cause a row share table lock(also sometimes called a subshare table lock, SS). This prevents other transactions from exclusive locking the whole table, but it does not block DML on the parent or the child table.
Figure 21-9 Locking Mechanisms When Index Is Defined on the Foreign Key
- 为什么外键最好加上索引?
- 为什么delete p;后最好加上p = NULL; ? (浅谈内存泄露和内存过度释放)
- select into 语句,最好加上异常捕获
- freemarker 每个 {$name} 最好都加上默认值
- 为什么要加上拉电阻
- 增强for 加上索引 打印指定格式 ,
- Ping命令为什么要加上“-t”参数
- 为什么他的models要加上
- ThreadLocal类为什么要加上static修饰
- 为什么要在linux命令前加上 ./ ?
- 为什么单个元素的元组要加上逗号?
- java中双检锁为什么要加上volatile关键字!
- oracle中varchar2 为什么要加上2?
- 为什么索引会提高效率
- 为什么索引会提高效率
- 数据库为什么使用索引
- 为什么要重建索引
- 为什么要创建索引
- 对于一个整数矩阵,存在一种运算,对矩阵中任意元素加一时,需要其相邻(上下左右)某一个元素也加一, 现给出一正数矩阵,判断其是否能够由一个全零矩阵经过上述运算得到。
- char*,const char*和string的相互转换
- 字符串循环移位
- hive上删除列
- VS 2008快捷操作
- 为什么外键最好加上索引?
- Flex 界面滚动条样式的设置
- 手机和电话的验证
- oracle sql 处理日期
- git tag简介
- ECShop:会员退出不清空购物车
- JDK,JRE,JVM三者分析
- git追踪分支
- git checkout简介