选择更好的SQL server查询计划以减少服务器I/O和RAM使用
对于我的SQL server数据库,我编写了两个SQL脚本以获得相同的输出。两者的计划大相径庭。我不明白该用哪一个 有人可以查看附带的SQL计划映像(Plan1和Plan2)并帮助我选择正确的映像吗?我的要求是减少这些进程对服务器I/O和RAM的使用 以下是SQL查询: 计划1:选择更好的SQL server查询计划以减少服务器I/O和RAM使用,sql,sql-server,Sql,Sql Server,对于我的SQL server数据库,我编写了两个SQL脚本以获得相同的输出。两者的计划大相径庭。我不明白该用哪一个 有人可以查看附带的SQL计划映像(Plan1和Plan2)并帮助我选择正确的映像吗?我的要求是减少这些进程对服务器I/O和RAM的使用 以下是SQL查询: 计划1: DECLARE @SellerLocationId INT = 5 SELECT (CASE WHEN LOWER(mfn_listing_exists) = 'yes' THEN IsInStock ELSE (
DECLARE @SellerLocationId INT = 5
SELECT (CASE WHEN LOWER(mfn_listing_exists) = 'yes' THEN IsInStock ELSE (CASE WHEN (afn_fulfillable_quantity > 0) THEN 1 ELSE 0 END) END) AS IsInStock
FROM ( select
sku,mfn_listing_exists,mfn_fulfillable_quantity,afn_fulfillable_quantity
from rptFBA_ManageInventoryResponse
where SellerLocationId = @SellerLocationId AND LOWER(condition) not in ('unknown','')
)tvp
LEFT OUTER JOIN ProductAmz p ON p.SKU = tvp.SKU AND p.SellerLocationId = @SellerLocationId
where p.SKU = tvp.SKU AND p.SellerLocationId = @SellerLocationId
计划二:
DECLARE @SellerLocationId INT = 5
SELECT (CASE WHEN (afn_fulfillable_quantity > 0) THEN 1 ELSE 0 END) AS IsInStock
FROM ( select
sku,mfn_listing_exists,mfn_fulfillable_quantity,afn_fulfillable_quantity
from rptFBA_ManageInventoryResponse
where SellerLocationId = @SellerLocationId AND LOWER(condition) not in ('unknown','') AND LOWER(mfn_listing_exists) = 'yes'
)tvp
LEFT OUTER JOIN ProductAmz p ON p.SKU = tvp.SKU AND p.SellerLocationId = @SellerLocationId
where p.SKU = tvp.SKU
AND p.SellerLocationId = @SellerLocationId
谢谢。我认为第二个方案比第一个方案要好,因为第一个方案的密钥查找成本为25%,密钥查找比索引扫描慢,比索引查找慢。因此,与其依赖于键查找,不如依赖于索引扫描。并分析该表可用的索引
rptFBA\u ManageInventoryResponse
,检查创建索引以提高性能的可能性。非常感谢您的宝贵响应。我将尝试在该表上创建索引。