One of our views, which ordinarily is pretty quick, is taking ages to run since midday yesterday. Nothing has been changed, but it is now taking minutes to run.
SELECT
T1.ITEMNO,
ROUND(SUM(T3.TOTAL * V1.USDCOST), 3) USDTOTALCOST,
ROUND(SUM(T3.TOTAL * V1.GBPCOST), 3) GBPTOTALCOST,
SUM(T3.TOTAL) AS TOTALCOMPONENTS
FROM
TABLE1 T1 WITH (NOLOCK)
INNER JOIN TABLE2 T2 WITH (NOLOCK) ON T1.RECORD_ID = T2.RECORD_ID
INNER JOIN TABLE3 T3 WITH (NOLOCK) ON T1.RECORD_ID = T3.RECORD_ID AND T2.LINENO = T3.LINENO
INNER JOIN VIEW1 V1 ON T2.COMPONENTNO = V1.ITEMNO
WHERE
T2.COMPONENTNO <> '' AND T1.WINDOW_ID = 'COMPONENTS'
GROUP BY T1.ITEMNO
Now, if I remove the calculated USDTOTALCOST
and GBPTOTALCOST
columns, then the query runs really quickly. Separately, if I remove the condition T1.WINDOW_ID = 'COMPONENTS'
then that also vastly increases the speed of the query.
VIEW1
runs really quickly on its own as well, it just seems to cause this view to slow down when it is joined and the T1.WINDOW_ID = 'COMPONENTS'
condition isn't imposed.
I am stuck - I no longer know where to check to try and get this query running in a reasonable amount of time. I would ordinarily check which indexes SSMS recommends I create at the top of the execution plan, but there are no such suggestions when I check the execution plan for this query.
What could have caused the query to slow down so much? What can I do to try and get this working again?
Thanks in advance.