SQL Server Merge and Indexing Speed -
I have a merge statement that needs to be comparing multiple columns. The source table has 26,000 rows There are several million lines in the Destination table, Desintation table has a typical primary key index on only one int-type column.
I have made some selections with the group to count the number of unique values in the source.
Part of the merge test
at #temptable (desttable.ColumnA = # temptable.ColumnA and desttable.ColumnB = # temptable.ColumnB and desttable.ColumnC = # temptable Using value .ColumnC and desttable.ColumnD = # temptable.ColumnD and desttable.ColumnE = # temptable.ColumnE and desttable.ColumnF = # temptable.ColumnF) Enter the value when it is not matched (.......) - Column A: 167 Unique values #temptable - In ColumnB: 1 unique value in #temptable - Column C: # Unique values in # real values - Column: 89 # Exclusive value in criteria # - column: 550 # Unique value in criteria - Column F : 487 untold Values are #temptable - Column A: 3690 unique value in destett - 3 unique values (plus empty possible) - Column C: 1113 unique value enabled - column: 2662 unique value in destately - column E: dest70 In 1770 unique value - Column: 1480 Unique Values in Destell
Merge takes a very, very long time. I think I need to change my primary key but I'm not sure what the best strategy is. 26,000 rows can be inserted on the first merge, but later the merge can only contain ~ 2,000 inserts. Since I do not have any index and is just a simple PK, everything is slow
thanks
"text">
OK, a clear candidate will be an indicator in the MERGE
statement to match you in the column - do you have a Index is (Column A, Column B, Column C, Column, Column E, Column F)
On Your Appointment Table ??
This column in the column is being used to determine whether a line already exists from your source table in the database. If you do not have that index and no other useful indicator location, then you get a table scan on the big destination table for each row in your source table, basically
if not: I will try to add it and see how the Runtime behavior changes. Does merge
go a little longer, too long ??
Comments
Post a Comment