So I have the following code - written by a 3rd party supplier. Can anyone suggest what indexes should be used to prevent bookmark lookups? Do you need the content of the UDFs as well?
SELECT reportTbl.ReportDBID,
case when reportTbl.ResultStatus = 'P' then 'PRELIMINARY'
when reportTbl.ResultStatus = 'I' then 'INTERIM'
else reportTbl.ResultStatus end As Status, 1 as isAccessible,
dbo.repAb(reportTbl.ReportDBID) As Abnormality,
dbo.repAb(reportTbl.ReportDBID) As Importance,
reportTbl.UniversalServiceDescription as Title,
reportTbl.DiagnosticServSectID as ServiceDescription,
case when ResultStatus='X' then 'Cancelled' when ResultStatus='C' OR dbo.inferStatus(reportTbl.ReportDBID) = 'C' then 'Amended'
else reportTbl.DiagnosticServSectID end AS subCategory,
reportTbl.DiagnosticServSectID as subCategoryAlt,
case when cdrOth.FamilyName is not null then cdrOth.FamilyName else cdrOth.IDNumber end As Autho开发者_Python百科r,
reportTbl.ObservationDateTime
FROM reportTbl WITH (NOLOCK)
INNER JOIN patientTbl WITH (NOLOCK) ON reportTbl.patID = patientTbl.patID
LEFT OUTER JOIN cdrOth WITH (NOLOCK) ON reportTbl.ordID = cdrOth.SegCrossReferenceDBID
WHERE
patientTbl.recNumber ='111111111'
and reportTbl.ResultStatus IN ('G', 'H','I', 'J')
and reportTbl.DiagnosticServSectID IN ('E', 'F')
and reportTbl.UniversalServiceCode NOT IN ('A', 'B', 'C', 'D') -- there are roughly 750 options so using NOT IN is easier
ORDER BY ReportDBID
Bookmark lookups are usually removed by using covering indexes
Some great examples here
This explains it better than I would. But the summary is that columns in the bookmark lookup should be added to the index.
精彩评论