SQL Server Query occupies 100% of the processor and runs for hours

I have a query that works every day for a little over 2 years and usually takes less than 30 seconds. Suddenly, yesterday, the request began to take 3 hours to complete and used a 100% processor all the time.

SQL:

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- type BIGINT, and beta.id- type INT. dbo.fnGetStuff()- A simple SELECT statement with 2 INNER JOINs on tables in the same database using WHERE id = @id. The function returns approximately 11000 results.

A view vwSomeDatais a simple SELECT statement with two INNER JOINs that returns about 590,000 results.

10 , . , < 10 .

, ? .

+3
8

. , . - , .

+4

SQL Server Profiler SQL Server. , , , , , .

+2

SQL Server Management Studio, , "". , . , - .

, .

+1

? , @ID .

, @ID WHERE, .

, , , Query Analyzer , . , Transact-SQL, , , , .

, INDEX, SQL.

, , , , .

+1

, . , . temp .

0

, , , . , , , , - . , , , - , , , , ? - , . , , - .

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 HASH JOIN vwSomeData alpha ON beta.id = alpha.id
0

- , :

... Profiler ... , . , - [DifferentDatabase]. , , .

0

:

SET SHOWPLAN_ALL ON

. , "" . , , . , , ( ..)

0

Source: https://habr.com/ru/post/1707661/


All Articles