SQL Server query execution very slow when comparing Primary Keys -
i have sql server 2008 r2 database table 12k address records trying filter out duplicate phone numbers , flag them using following query
select a1.id, a2.id addresses a1 inner join addresses a2 on a1.phonenumber = a2.phonenumber a1.id < a2.id
note: realize there way solve problem using exists
, not part of discussion.
the table has primary key on id field clustered index, fragmentation level 0 , phone number field not null , has 130 duplicates out of 12k records. make sure not server or database instance issue ran on 4 different systems.
execution of query takes several minutes, several hours. after trying 1 of last steps removed primary key , ran query without , voila executed in under 1 second. added primary key , still ran in under 1 second.
does have idea causing problem?
is possible primary key gets somehow corrupted?
edit: apologies had couple of typos in sql query
out of data statistics. dropping , recreating pk give fresh statistics.
too late now, i'd have suggest running sp_updatestats see happened.
if backup , restore database onto different systems, statistics follow data
i'd suspect different plan after non-indexed (i guess) columns phonenumber , ccaphonen
Comments
Post a Comment