I am running simple select script, which inner join with other 3 table . all the tables are big ( lots of data ) its taking around 20 sec to run. want to optimized it.
I tried to used nolock , but not much deference
SELECT RR.ReportID,
RR.RequestFormat,
RRP.SequenceNumber,
RRP.ParameterName,
RRP.ParameterValue
CASE WHEN RP.ParameterLabelOvrrd IS NULL THEN P.ParameterLabel ELSE .ParameterLabelOvrrd END AS ParameterLabelChosen,
RRP.ParameterValueEntered
FROM ReportRequestParameters AS RRP WITH (NOLOCK)
INNER JOIN ReportRequests AS RR WITH (NOLOCK) ON RRP.RequestID = RR.RequestID
INNER JOIN ReportParameter AS RP WITH (NOLOCK) ON RP.ReportID = RR.ReportID
AND RP.SequenceNumber = RRP.SequenceNumber
INNER JOIN Parameter AS P WITH (NOLOCK) ON P.ParameterID = RP.ParameterID
WHERE RRP.RequestID = '2226765'
ORDER BY SequenceNumber;
Please advice.
with (nolock)suggests SQL Server, so I added the tag.WITH (NOLOCK)against every table here? If it's to "improve" the performance then that isn't whatWITH (NOLOCK)does and you should remove them all (your question suggests that's the reason). Your SQL is also malformed as you're missing a comma afterParameterValue, and.ParameterLabelOvrrdis missing the table alias. The quickest way for you to help us help you is for you to post the DDL of your tables, along with any indexes. It will likely be worth while giving us a copy of your query plan too.