如何在SQL Server中优化查询?查询需要2分钟才能运行,但我需要在几秒钟内运行查询

时间:2017-05-25 06:58:23

标签: sql-server

在此查询中,只有一个表AssetAttributes需要1分54秒。此表包含1782895条记录。

我正在从AssetAttributeID, AssetAttributeName, AssetAttributeOwner, AssetAttributeParentID, AssetAttributeTypeID, AssetAttributeTypeName表中选择列AssetAttribute

SELECT     
    AssetAttributes.AssetAttributeID, 
    AssetAttributes.AssetAttributeName, 
    ISNULL(AssetAttributesFriendly.AssetAttributeFriendlyName, AssetAttributes.AssetAttributeName) AS FriendlyAssetAttributeName, 
    AssetAttributes.AssetAttributeOwner, Assets.AssetName, 
    AssetAttributes.AssetAttributeParentID, 
    Categories.CategoryName, 
    AssetAttributes.AssetAttributeTypeID, 
    AssetAttributes.AssetAttributeTypeName, 
    AssetAttributes.Active, 
    AssetAttributes.AssetAttributeDefinitionID, 
    Categories.CategoryParentID, Categories.CategoryOwner, 
    Categories.CategoryDefinitionID, Categories.Active AS CategoriesActive, 
    Assets.ChannelId AS AssetPlantID, 
    Categories.ChannelId AS CategoryPlantID, 
    AssetAttributes.ChannelId AS AssetAttributePlantID
FROM   
    AssetAttributes 
LEFT OUTER JOIN 
    AssetAttributesFriendly ON AssetAttributesFriendly.AssetAttributeID = AssetAttributes.AssetAttributeID 
                            AND AssetAttributesFriendly.plantid = AssetAttributes.ChannelId
LEFT OUTER JOIN 
    Categories ON AssetAttributes.AssetAttributeParentID = Categories.CategoryID        
LEFT OUTER JOIN 
    Assets ON AssetAttributes.AssetAttributeOwner = Assets.AssetID

0 个答案:

没有答案