Optimizing merge operators

I have two tables in SQL Server where one is the source of a MERGE operation in the other.

There are 30Mil records in the original table

The goals table contains 180Mil records. Both tables have 227 columns.

I have SSIS, but in this case I am told that MERGE assertion is the best option. Below is an abbreviated version:

;WITH MySource as (
    SELECT * FROM [STAGE].[dbo].[STAGE_TABLE]
)
MERGE [EDW].[dbo].[TARGET_TABLE] AS MyTarget
USING MySource
     ON MySource.[ID_FIELD] = MyTarget.[ID_FIELD]
    AND MySource.[LoadDate] >= MyTarget.[LoadDate]
WHEN MATCHED THEN UPDATE SET 
     <<Target Column>> = MySource.<<Source Colums>> --227 columns
WHEN NOT MATCHED THEN INSERT
    (
        [ID_FIELD], 
        [LoadDate], 
       <<225 Other Columns>>
    )
    VALUES (
        MySource.[ID_FIELD], 
        MySource.[LoadDate], 
        MySource.<<225 other columns>>
    );

      

The only changes I made to the script above is truncating the column list to keep the short code short.

My problem is that I am under execution. On the Profile screen displays the suspension CXPACKET

with an error: cwaitpipenewrow, node=2

.

How do I fix this problem? Thank.

+3


source to share


1 answer


It looks like the CXPACKET and the suspended state means that some threads that have terminated are registering a different thread state that hasn't finished yet. Please check here. The query should update to 1 billion values ​​in the table. hence, these will be slow queries.

https://dba.stackexchange.com/questions/96346/cxpacket-suspended-and-null-wait-type



https://www.sqlshack.com/troubleshooting-the-cxpacket-wait-type-in-sql-server/

Hope these articles help you debug.

0


source







All Articles