English 中文(简体)
未索引的外键导致TM Enqueue争用。
原标题:
  • 时间:2008-12-08 23:58:49
  •  标签:

所以我们被告知TM Enq争用的一个来源可能是未索引的FK。我的问题是哪一个。

我有一个将“TM Enq Wait”记录到“Table_B”表中的INSERT INTO Table_B

它包含一个PK,其中是其他表的父表,并且它具有列,这些列被FK限制为其他PK

那些FK需要索引:该表的列或其子级?

NB:我知道这不是 TM 冲突的唯一原因。如果是这种情况,你能解释一下为什么这不可能是这样吗?

问题回答

不确定Oracle TM争用情况,但我会说通常外键关系的两个方面都会建立索引。否则,数据库将不得不进行表扫描。

  • The index on the parent record is used whenever you insert a new child record, to verify that the parent exists. Often this is a primary key as well, so of course has an index.
  • The index on the child record is used whenever you change or delete a parent record, to perform cascades (including refusing the update/delete).

两侧的索引也给数据库提供了充分的机会进行快速(索引)连接,无论优化器更倾向于哪一侧。

编辑:通过谷歌搜索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排队模式?





相关问题
热门标签