TheBugSlayer
Programmer
Hello everyone.
I have a MERGE statement that pulls ~50,000 rows of data from one table in a database to another table table containing >28,500,000 rows in another database, on the same server. However, the SSIS package scheduled to run through a job has been running for 3:00AM and it is almost 1:00 PM! It takes no less than 7 hours. There are other tasks in the package that take a little over an hour to run. This, the last task goes on forever. Both the source and target tables are indexed. Yesterday I changed the recover model to SIMPLE and today I set SQL Server to use up to 28Gb of the available 32Gb memory space.
What other optimizations can I implement to make the MERGE statement run faster?[/]. The query loads an ETL database that will be used to populate a data warehouse.
Below is a section of the MERGE statement
Your help is appreciated!
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA), Training HOTT cert SQL Server 2012 Business Intelligence (SSIS, SSAS).
I have a MERGE statement that pulls ~50,000 rows of data from one table in a database to another table table containing >28,500,000 rows in another database, on the same server. However, the SSIS package scheduled to run through a job has been running for 3:00AM and it is almost 1:00 PM! It takes no less than 7 hours. There are other tasks in the package that take a little over an hour to run. This, the last task goes on forever. Both the source and target tables are indexed. Yesterday I changed the recover model to SIMPLE and today I set SQL Server to use up to 28Gb of the available 32Gb memory space.
What other optimizations can I implement to make the MERGE statement run faster?[/]. The query loads an ETL database that will be used to populate a data warehouse.
Below is a section of the MERGE statement
Code:
[COLOR=red]
MERGE INTO STAGE1.StageAccessionDetail AS target
USING (SELECT * FROM SourceDatabase.dbo.AccessionDetail WITH (NOLOCK)) AS source ON target.AccessionID = source.AccessionID
AND target.SpecimenID = source.SpecimenID
AND CASE WHEN source.BlockTableID IS NULL THEN 1 ELSE source.BlockTableID END = CASE WHEN target.BlockTableID IS NULL THEN 1 ELSE target.BlockTableID END
AND CASE WHEN source.BlockProcedureID IS NULL THEN 1 ELSE source.BlockProcedureID END = CASE WHEN target.BlockProcedureID IS NULL THEN 1 ELSE target.BlockProcedureID END
AND target.ChargeID = source.ChargeID
AND CASE WHEN source.CPTCode IS NULL THEN '1' ELSE source.CPTCode END = CASE WHEN target.CPTCode IS NULL THEN '1' ELSE target.CPTCode END
AND CASE WHEN source.ICDCode IS NULL THEN '1' ELSE source.ICDCode END = CASE WHEN target.ICDCode IS NULL THEN '1' ELSE target.ICDCode END
[/color]
WHEN MATCHED
AND
(target.ClientID <> source.ClientID OR
target.ClientGroupID <> source.ClientGroupID OR
...
)
THEN UPDATE SET
AccessionID = source.AccessionID
,ClientID = source.ClientID
,ClientGroupID = source.ClientGroupID
,PathologistID = source.Pathologist
WHEN NOT MATCHED THEN
INSERT (AccessionID
,ClientID
,ClientGroupID
...
IsLatestCase, CaseNumberVersion)
VALUES
(source.AccessionID
,source.ClientID
,source.ClientGroupID
,source.PathologistID
...
)
Your help is appreciated!
MCP SQL Server 2000, MCTS SQL Server 2005, MCTS SQL Server 2008 (DBD, DBA), Training HOTT cert SQL Server 2012 Business Intelligence (SSIS, SSAS).