Your query has an inner join between tables STG.personattribute (stg) and GDW.personattribute (tar)
which includes this predicate: Tar.AttributeID = stg.AttributeID.
The WHERE clause includes this predicate: ISNULL(Tar.AttributeID, 0) != ISNULL(stg.AttributeID, 0),
which fortunately is ORred or you wouldn't get any results at all. However, it's sufficient "red flag dodgy coding"
to put the query back into the test stream rather than the optimisation stream.
Other points to note:
The estimated plan is of limited use for optimisation studies.
Using functions - including ISNULL - on columns in joins or the WHERE clause is likely to impact performance.
Table GDW.Person is joined to both tar and stg. Without the rowcounts available from an "actual" execution plan
it's difficult to tell, but this could be a significant bottleneck.
The plan includes a key lookup to fetch AttributeValue and AttributeTag from tar. Consider adding these two columns
to the INCLUDE column clause of index UQ__PersonAttribute__4F1CD4FC.
The table which is the update target should ideally be the first table in the FROM list, like this:
UPDATE tar
SET AttributeID = stg.AttributeID ,
AttributeValue = stg.AttributeValue ,
AttributeTag = stg.AttributeTag ,
BatchFileID = stg.BatchFileID ,
DateUpdated = 'Jun 16 2014 10:26AM'
FROM GDW.personattribute tar
INNER JOIN STG.personattribute stg
ON tar.AttributeID = stg.AttributeID
AND tar.DateTo IS NULL
INNER JOIN GDW.Person p
ON p.SourceRowID = stg.SourceRowID
AND p.SourceID = stg.SourceID
and p.PersonID = tar.PersonID
WHERE stg.BatchFileID = 5502
AND ( ISNULL(Tar.AttributeID, 0) != ISNULL(stg.AttributeID, 0)
OR ISNULL(Tar.AttributeValue, 0) != ISNULL(stg.AttributeValue, 0)
OR ISNULL(Tar.AttributeTag, '') != ISNULL(stg.AttributeTag, '')
)
Try optimising this query in two phases, beginning with the SELECT equivalent of the UPDATE:
SELECT
tar.AttributeID, stg.AttributeID ,
tar.AttributeValue, stg.AttributeValue ,
tar.AttributeTag, stg.AttributeTag ,
tar.BatchFileID, stg.BatchFileID ,
tar.DateUpdated
FROM GDW.personattribute tar
INNER JOIN STG.personattribute stg
ON tar.AttributeID = stg.AttributeID
AND tar.DateTo IS NULL
INNER JOIN GDW.Person p
ON p.SourceRowID = stg.SourceRowID
AND p.SourceID = stg.SourceID
and p.PersonID = tar.PersonID
WHERE stg.BatchFileID = 5502
AND (
ISNULL(Tar.AttributeID, 0) != ISNULL(stg.AttributeID, 0) OR
ISNULL(Tar.AttributeValue, 0) != ISNULL(stg.AttributeValue, 0) OR
ISNULL(Tar.AttributeTag, '') != ISNULL(stg.AttributeTag, '')
)
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden