One of our systems has a table that receives around 20k inserts per day - it currently contains ~10m rows. We've just pushed out a system upgrade and I'm getting some shockingly slow performance on inserts to this table now (30-40s traces). Inserts will only ever insert a single row at a time. Entity Framework is generating the following SQL:
declare @generated_keys table([ID] uniqueidentifier)
insert [dbo].[Table]([Col1], Col2], etc)
output inserted.[ID] into @generated_keys values (@0, @1, etc)
select t.[ID] from @generated_keys as g join [dbo].[Table] as t on g.[ID] = t.[ID] where @@ROWCOUNT > 0
Nothing out of the ordinary - at least as far as I can see.
The table has 12 FKs. As the entity represents a time-based event, the clustered index is on a DateCreated
column. There are 8 further non-clustered indexes, with various included columns. The ID
column is the PK and has a unique, non-clustered index.
As a note, I have noticed that, due to an omission, the ID
column is using newid()
instead of newsequentialid()
.
The actual execution plan comprises the following major parts:
7x 3% - Clustered Index Seek on FK tables
1x 8% - Table Insert (@generated_keys)
1x 74% - Clustered Index Insert, 1 actual row, 0.09 cost
I'd really like to get to the bottom of this but I'm stumped now. Any advice?