这是我的 SQL 查询:
SELECT B.TransactionId
FROM BillingInfo B
INNER JOIN OfficeCustomers OC ON B.CustomerId = OC.Id
INNER JOIN CustomerContact CC ON CC.Id = OC.ContactId
WHERE CC.FirstName + ' ' + CC.LastName LIKE '%yog%'
ORDER BY B.TransactionId
OFFSET (0) ROWS FETCH NEXT (50) ROWS ONLY
此查询大约需要 6 秒才能完成。可以采取哪些措施来提高性能?
这两条评论很准确。
如果可能,请将
LIKE '%yog%
替换为 LIKE 'yog%
。
您还可以尝试以下查询:
WITH contacts AS
(
SELECT CC.Id
FROM CustomerContact CC
WHERE CC.FirstName LIKE '%yog%' OR CC.LastName LIKE '%yog%'
)
SELECT B.TransactionId
FROM BillingInfo B
INNER JOIN OfficeCustomers OC ON B.CustomerId = OC.Id
INNER JOIN contacts CC ON CC.Id = OC.ContactId
ORDER BY B.TransactionId
OFFSET (0) ROWS FETCH NEXT (50) ROWS ONLY;