A client recently hit a pain point on a long-running process that could no longer be ignored. A data warehouse load consisting of several steps took roughly 7-10 hours to complete on a nightly basis. One of the steps consumed five of those hours. The SQL Server has 8 cores running at 93–95% CPU capacity during this time. During this step, everything else had to queue and wait, and it started to interfere with morning operations.
This process was several years old. Different data loads were added and removed as lines of business were updated. One line of business, however, was not properly being updated.
The Warning Nobody Knew About
Root cause analysis is one of our strengths. The team is meticulous and patient in reviewing all logs and pieces of information we can find. In this case, senior DBA Brian Woolwine led our team in root cause analysis to find the best resolution. The SSIS execution log had a warning of duplicate reference key values while caching reference data.
The SSIS package completes without error each evening. It does, however, warn of the duplicates. Diving deeper into the warning led to a GROUP BY statement that could return several rows per key. The much bigger problem was upstream.
Where The Five Hours Actually Went
None of the usual suspects were the issue: memory pressure, oversized commits, and a slow destination all cleared when checked in the log. Moving on to database activity held more information. One source query held high CPU for over four hours, followed by an hour of hash and sort waits. Query Store confirmed the findings:
Tracking The Duplicates Upstream
The table feeding the query held 28M enrollments but only a few million members. The monitoring tool used for original diagnosis flagged an index of roughly 28M rows on a staging table. The team checked that staging table and found it to be a straight copy of the main enrollment table. This staging table was being reloaded every night.
The enrollment table held 27,771,942 rows but only 4,721,075 distinct combinations of columns. In this count, roughly 23M rows were duplicates.
One other oddity: growth of 36,000 to 38,000 rows every night. This is not the normal growth pattern for this kind of business. Three more queries closed it:
Last night’s inserts by line of business. One line of business added 36,119 rows, and all the others combined added 1,285. The staging table held exactly 36,119 rows for that line of business. Every single one had been inserted again.
One member’s history. A member in that line of business had 716 enrollment rows, one per night, going back to September 2023.
The staging data. All 36,119 rows had a NULL in a unique column.
How a Duplicate Becomes a Five-Hour Query
The root cause was a mismatch between two queries. The enrollment load uses a lookup to decide between insert and update. Its reference query only included existing enrollments where a member number matched the staging table’s unique column, while the source identified members through a different column.
For that line of business, the unique column was NULL. No enrollments made it into the lookup cache. Every night, each member looked new. Nothing in the schema stopped it: there was no unique constraint on the matching key. Every copy got its own auto-generated ID.
The extra rows then multiplied through everything building on and using them. The slow source query joined the staging table to the enrollment copy table, spreading out to an estimated 7.4M rows, roughly 204 for each staging row. Three details in the query plan made it worse:
Stale statistics. The staging tables had just been reloaded. Statistics were rebuilt a minute before the query ran, from a 1% to 2% sample. The optimizer expected one row.
An adaptive join. The plan contained an adaptive join that switches to nested loops when it sees fewer than about 49,000 input rows. We had 36,119, so it very likely took the nested-loop branch.
A lookup on group and location only. That branch looked up the enrollment copy by group and location only. In this line of business, every group used the same location, so each of roughly 36,000 lookups walked through millions of rows. The big groups held between 4M and 7.5M rows.
The pinned CPU hurt other workloads too. An application query’s wait time per call roughly tripled overnight, from about 120 ms to about 355 ms, even though its call volume fell by half.
The Fix And The Results
Match on the same column the source uses. The proper column was used, and a filter with EXISTS replaced the join.
Load the staging copy with one row per key. The oldest enrollment, which had all needed data, was kept. The roughly 23M duplicates could now be seen and prepared for removal.
Clean up the duplicates. The duplicates were removed in batches after checking the foreign key. A unique index was added on the matching key to prevent future duplicates.
An exact copy of the production database in test provided the perfect test area. The problem step had taken 4h 36m, 5h 15m and 5h 14m on its last three runs. After the fix, it took about an hour, and the data flow itself took 100 seconds.
The fix was deployed into production that afternoon. That night’s wait chart looked very different. These figures are approximate values.
| Measure | Before | After |
|---|---|---|
| Test: step duration | about 5 hours | about 1 hour |
| Production: peak hour of total wait | about 17,600 s | about 4,300 s |
| Production: wait in the heaviest window | baseline | about 84% lower |
Three source queries that had ranked among the top consumers dropped out of the top fifteen. We also wrote the case up for the client’s developers: the evidence, the proposed changes, a validation plan and the open questions.
A Bonus Finding
The biggest consumer on the server was an unrelated application query. It accounted for 10 hours and 38 minutes of wait in a single day, about double the waits for the nightly job.
Each run was a full scan of a 1.2-million-row table to return less than one row.. The table had no index on the two columns the query filters by.
The fix is a small index on member and year, which should take seconds to build on a table that size. It has not been applied yet.
What We Took Away
A green job is not always a healthy job. The package succeeded every night while a duplicate-key warning sat in the log.
Read the timestamps before forming theories. Our log showed within minutes that the time was not in the data flow.
A suspiciously flat number is a fingerprint. About 37,000 new rows a night, matching one staging count exactly, pointed at a systematic cause, not real growth.
Compare estimated rows to actual rows. A plan that expects one row and returns millions chooses every operator incorrectly.
Make the database enforce what the ETL assumes. A unique constraint on the matching key would have caught the first duplicate in 2023.
Measure before and after. The numbers are what turn a fix into a case a client will approve.
Need Expert Help?
Slow ETL jobs and duplicate rows can delay reporting and erode trust in your data. Moser’s Data Intelligence team can help pinpoint the bottleneck, strengthen validation, and make your data pipeline more reliable. Talk with Moser about your ETL challenges.

