当前位置: 动力学知识库 > 问答 > 编程问答 >

sql server - Filtering parent or child database entity - optimization

问题描述:

I'm doing some optimizations and I need some technical help regarding optimization.

Consider the following query :

SELECT *

FROM Employees E

JOIN Data D ON E.idDataType = D.idDataType

WHERE E.idDataType = 1

Does it matter (from optimization point of view) if I filter the parent table or the child table? Which one would be faster?

E.idDataType = 1 VS D.idDataType = 1

Employees:

|idEmployee|Name|Data1|idDataType|AttributeValue2

1 A X 3 xx

2 B T 2 xx

PrimaryKey(idEmployee);

ForeginKey(idDataType) References Data(idDataType);

Data table:

idDataType|Description

1 etc

2 etc

3 etc

4 etc

PrimaryKey(idDataType);

网友答案:

No, it does not matter, the result will be the same. Even if they would have different execution times, the DataBase would take care of that so it will always be executed in the fastest possible way.

The * has probably a greater impact.

分享给朋友:
您可能感兴趣的文章:
随机阅读: