I need to optimize the following SQL Server 2005/2008 update request:
UPDATE
dbo.TargetTable A
SET
TargetColumn = 0
WHERE
TargetColumn = 1
AND 1 =
(
SELECT COUNT(*)
FROM dbo.TargetColumn B
WHERE
A.Id1 = B.Id1
AND A.Id2 = B.Id2
AND A.Id3 = B.Id3
)
About the dbo.TargetTable table: it contains about 100 columns and 8 non-clustered indexes. None of the indices consists of Id1, Id2, Id3 and includes TargetColumn.
I tried to run this update on 3 combinations of indexes (table size about 200,000 records):
- All indexes are disabled.
- All 8 Indexes Included
- All indexes are disabled, except for special ones, to speed up the update:
create index idx0 on dbo.TargetTable (Id1, Id2, Id3) enable (TargetValue)
I get the following timings:
- 7 minutes
- 5 minutes
- 53 seconds
10 , . SQL- , .
, ?