我是否需要在外键上创建索引?
问题描述:
我有一张桌子 A
和一张桌子 B
。 A
在 B
上有 B
的外键主键, B_ID
。
I have a table A
and a table B
. A
has a foreign key to B
on B
's primary key, B_ID
.
出于某种原因(我知道有正当理由)它没有使用索引当我在密钥上加入这两个表时。
For some reason (I know there are legitimate reasons) it is not using an index when I join these two tables on the key.
我是否需要在 A.B_ID
上单独创建索引或者是否存在外键提供?
Do I need to separately create an index on A.B_ID
or should the existence of a foreign key provide that?
答
仅外键约束不提供索引 - 必须(并且应该创建。
The foreign key constraint alone does not provide the index - one must (and should) be created.