I have a query that has been running every day for a little over 2 years now and has typically taken less than 30 seconds to complete. All of a sudden, yesterday, the query started taking 3+ hours to complete and was using 100% CPU the entire time.
The SQL is:
SELECT
@id,
alpha.A, alpha.B, alpha.C,
beta.X, beta.Y, beta.Z,
alpha.P, alpha.Q
FROM
[DifferentDatabase].dbo.fnGetStuff(@id) beta
INNER JOIN vwSomeData alpha ON beta.id = alpha.id
alpha.id
is a BIGINT type and beta.id
is an INT type. dbo.fnGetStuff()
is a simple SELECT statement with 2 INNER JOINs on tables in the same DB, using a WHERE id = @id
. The function returns approximately 11000 results.
The view vwSomeData
is a simple SELECT statement with two INNER JOINs that returns about 590000 results.
Both the view and the function will complete in less than 10 seconds when executed by themselves. Selecting the results of the function into a temporary table first and then joining on that makes the query finish in < 10 seconds.
How do I troubleshoot what's going on? I don't see any locks in the activity manager.