パフォーマンスの悪い SQL クエリがあります。テーブル スキャンや IO スパイクが発生しています。以下のスクリプトと実行計画を確認し、クエリ自体のインデックスまたはリファクタリングが必要かどうかをお知らせください。ありがとう
--クエリ
SELECT TOP 20
CustomerPrimaryExtID,
Max(POSTimeStamp) AS TransactionDate,
ExtLocationCode,
0 AS RedemptionAmount,
0 AS RedemptionCount,
TerminalNum,
LogixTransNum,
POSTransNum AS TransNum,
0 AS DetailRecords,
CustomerTypeID,
PresentedCustomerID,
PresentedCardTypeID,
HHID,
Replayed,
0 AS TransContext,
ISNULL(TransTotal, 0) AS TransTotal
FROM TransHist AS TH WITH(nolock)
WHERE
(
(
( CustomerPrimaryExtID IN ( '' ) AND HHID IS NULL )
OR HHID = '0000000250000007320' AND CustomerTypeID <> 1
) OR ( CustomerPrimaryExtID = '0000000250000007320' AND CustomerTypeID = 1 )
)
AND NOT EXISTS
(
SELECT
LogixTransNum
FROM TransRedemptionView AS TR2
WHERE
(
( ( CustomerPrimaryExtID IN ( '' ) AND HHID IS NULL ) OR HHID = '0000000250000007320' AND CustomerTypeID <> 1 )
OR ( CustomerPrimaryExtID = '0000000250000007320' AND CustomerTypeID = 1 )
)
AND TH.LogixTransNum = TR2.LogixTransNum
)
GROUP BY
CustomerPrimaryExtID,
HHID,
CustomerTypeID,
PresentedCustomerID,
PresentedCardTypeID,
LogixTransNum,
POSTransNum,
TerminalNum,
ExtLocationCode,
Replayed,
TransTotal
ORDER BY TransactionDate DESC