This JOIN is very fast because for each row scanned in table A there can be onlyONErow in table B which satisfies the JOIN condition. One and no more than one. That is because B.id is UNIQUE. 给你:* 伪代码 *,说明服务器端的处理:
foreach (rowA in A)
{
if (existsInBRowWithID(rowA.id)
{
addToResult(rowA.text, getRowInBWithID(rowA.id).text);
}
}
2条答案
按热度按时间umuewwlo1#
我会试着解释...
表B具有以下数据:
假设eq_ref是A和B之间的JOIN:
This JOIN is very fast because for each row scanned in table A there can be onlyONErow in table B which satisfies the JOIN condition. One and no more than one. That is because B.id is UNIQUE.
给你:* 伪代码 *,说明服务器端的处理:
假设ref是A和C之间的JOIN:
给你:说明服务器端处理的伪代码:
此JOIN不如前一个JOIN快,因为对于表A中扫描的每一行,表C中可能有SEVERAL行满足JOIN条件(嵌套循环)。这是因为C. ID不是UNIQUE。
bvn4nwqk2#
“类型”指的是您请求中的联接类型。以下是从最佳到最差的列表:
您可以在MySQL文档中找到更详细的解释:http://dev.mysql.com/doc/refman/5.0/en/explain-output.html