所以我们被告知TM Enq
争用的一个来源可能是未索引的FK。我的问题是哪一个。
我有一个将“TM Enq Wait”记录到“Table_B”表中的INSERT INTO Table_B
。
它包含一个PK
,其中是其他表的父表,并且它具有列,这些列被FK
限制为其他PK
。
那些FK
需要索引:该表的列或其子级?
NB:我知道这不是 TM 冲突的唯一原因。如果是这种情况,你能解释一下为什么这不可能是这样吗?
所以我们被告知TM Enq
争用的一个来源可能是未索引的FK。我的问题是哪一个。
我有一个将“TM Enq Wait”记录到“Table_B”表中的INSERT INTO Table_B
。
它包含一个PK
,其中是其他表的父表,并且它具有列,这些列被FK
限制为其他PK
。
那些FK
需要索引:该表的列或其子级?
NB:我知道这不是 TM 冲突的唯一原因。如果是这种情况,你能解释一下为什么这不可能是这样吗?
不确定Oracle TM争用情况,但我会说通常外键关系的两个方面都会建立索引。否则,数据库将不得不进行表扫描。
两侧的索引也给数据库提供了充分的机会进行快速(索引)连接,无论优化器更倾向于哪一侧。
编辑:通过谷歌搜索TM竞争,听起来您可能缺少子记录上的密钥。但确保在两侧都有它们。
编辑 2:回答评论,
If you have a OLTP table that has 13 FKs to lookup tables, I m not keen on 13 index updates in addition to the table, pk and any other indexes. An index is important but for specific reasons. If you never update the parent PK nor delete from the parent, the child index is not so useful. Or is it?
Depends on the joins and queries you re running, then. E.g., if you run a query like:
SELECT o.something
FROM oltp_tab o JOIN lookup l ON (o.lookup_no = l.lookup_no)
WHERE l.lookup_name = ?
then the query optimizer would probably like the index on the child records.
Also, according to http://ashmasters.com/waits/enq-tm-contention/ you pretty much need to have the indices if you change the parent tables at all. Apparently you get them from having concurrent changes to the parent and child tables, unless you have the index. So this is probably what you re seeing (assuming you re not doing the obvious things, like updating the referred to columns or deleting rows)
启用的外键关系的引用父列必须创建索引,因为它必须具有启用的唯一或主键约束。
你看到了哪种TM排队模式?