我有一个非常庞大的数据库,3k +行
加载页面需要4秒钟,有2个大查询 如何加快速度?
首先:
SELECT Description
FROM ComputerIdentity JOIN
MakeModelIdentity
ON ComputerIdentity.MakeModelID = MakeModelIdentity.ID
WHERE MakeModelIdentity.DeviceName='Laptop' AND
ComputerIdentity.Description LIKE '%uitleen%' AND
MakeModelIdentity.DeviceName = 'Laptop' AND
MakeModelIdentity.Model = 'Chromebook'
ORDER BY ComputerIdentity.ID ASC
第二:
SELECT Inlognaam,VolledigeNaam FROM PersoneelEnLeerlingen
答案 0 :(得分:0)
对于此查询(我已经"简化"使用表别名并删除多余的WHERE
条件):
SELECT ci.Description
FROM ComputerIdentity ci JOIN
MakeModelIdentity mmi
ON ci.MakeModelID = mmi.ID
WHERE mmi.DeviceName = 'Laptop' AND
ci.Description LIKE '%uitleen%' AND
mmi.Model = 'Chromebook'
ORDER BY ci.ID ASC;
您可以使用MakeModelIdentity(DeviceName, Model, ID)
和ComputerIdentity(MakeModelID, Description, ID)
上的索引加快查询速度。
第二个查询非常简单,速度只取决于数据的大小。
答案 1 :(得分:0)
3K行是微不足道的,SQL Server Engine不需要您的帮助来优化它。这里仍然是优化书中的一些建议。 首先:
SELECT ci.Description
FROM ComputerIdentity ci JOIN
MakeModelIdentity mmi
ON ci.MakeModelID = mmi.ID
WHERE mmi.DeviceName = 'Laptop' AND
mmi.Model = 'Chromebook' AND
ci.Description LIKE '%uitleen%' --reordered
ORDER BY ci.ID ASC;
For Second:在您选择的列上创建非聚集索引,该索引没有聚集索引