How to find out why the status of a spid is suspended? What resources the spid is waiting for?

后端 未结 3 1182
迷失自我
迷失自我 2020-12-23 09:29

I run EXEC sp_who2 78 and I get the following results:

\"results

3条回答
  •  温柔的废话
    2020-12-23 10:11

    You can solve it with to ways:

    1. Fix the cluster index.
    2. Use temporal tables to get a part of the all table and work with it.

    I have the same problem with a table with a 400,000,000 rows, and use a temporal tables to get a part of it and then i use my filters and inners because change the index was not a option.

    Some example:

    --
    --this is need be cause DECLARE @TEMPORAL are not well for a lot of data.
    CREATE TABLE #TEMPORAL
    (
        ID BIGINT,
        ID2 BIGINT,
        DATA1 DECIMAL,
        DATA2 DECIMAL
    );
    
    WITH TABLE1 AS
    (
        SELECT
            L.ID,
            L.ID2,
            L.DATA
        FROM LARGEDATA L
        WHERE L.ID = 1
    ), WITH TABLE2 AS
    (
        SELECT
            L.ID,
            L.ID2,
            L.DATA
        FROM LARGEDATA L
        WHERE L.ID = 2
    ) INSERT INTO #TEMPORAL SELECT
        T1.ID,
        T2.ID,
        T1.DATA,
        T2.DATA
    FROM TABLE1 T1
        INNER JOIN TABLE2 T2
            ON T2.ID2 = T2.ID2;
    --
    --this take a lot of resources proces and time and be come a status suspend, this why i need a temporal table.
    SELECT
        *
    FROM #TEMPORAL T
    WHERE T.DATA1 < T.DATA2
    --
    --IMPORTANT DROP THE TABLE.
    DROP TABLE #TEMPORAL
    

提交回复
热议问题