未索引的外键导致 TM 队列争用
因此,我们得知 TM Enq
争用的来源之一可能是未索引的 FK。 我的问题是哪一个。
我有一个正在记录 TM Enq Wait
的 INSERT INTO Table_B
。
它包含一个作为其他表的父表的 PK
,并且它的列受其他 PK
的 FK
约束。
那么哪些FK
需要索引:该表的列还是它的子表?
注意:我知道这不是 TM 争用的唯一原因。 如果是这样的话,你能解释一下为什么不可能是这样吗?
So we've been told that one source of TM Enq
contention can be unindexed FK's. My question is which one.
I have an INSERT INTO Table_B
that is recording TM Enq Wait
.
It contains a PK
that is the parent to other tables and it has columns that are FK
constrained to other PK
s.
So which FK
s need indexed: that table's columns or its children?
NB: I know that this isn't the only cause of TM Contention. Can you explain why it couldn't possibly be this if that's the case.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定 Oracle TM 争用,但我想说通常外键关系的双方都会建立索引。 否则,数据库将不得不进行表扫描。
两侧的索引还为数据库提供了执行快速(索引)连接的良好机会,无论其优化器更喜欢来自哪一侧。
编辑:通过 Google 搜索 TM 争用,听起来您可能丢失了子记录上的密钥。 但一定要确保两边都有,真的。
编辑2:回答评论,
那么取决于您正在运行的联接和查询。 例如,如果你跑
像这样的查询:
那么查询优化器可能会喜欢子项上的索引
记录。
另外,根据 http://ashmasters.com/waits/enq-tm-contention/< /一>你
如果您更改父表,则几乎需要索引
全部。 显然,您是通过同时更改来获得它们的
父表和子表,除非有索引。 所以这可能是
你所看到的(假设你没有做明显的事情,比如
更新引用的列或删除行)
Not sure about Oracle TM Contention, but I'd say normally both sides of a foreign key relation are indexed. Otherwise, the database will have to do table scans.
The indices on both sides also give the database a good chance of doing fast (indexed) joins, no matter which side its optimizer prefers to come from.
EDIT: Having Googled TM contention, it sounds like you're probably missing the keys on the child records. But make sure to have them on both sides, really.
EDIT 2: Answering the comment,
Depends on the joins and queries you're running, then. E.g., if you run
a query like:
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 Enqueue 是什么模式?
The parent (referenced) column of an enabled foreign key relationship has to be indexed because it has to have an enabled unique or primary key constraint on it.
What mode of TM Enqueue are you seeing?