Hi,
A query using clustered index key has performed an index scan instead of seek. The query was captured by heavy queries Extended Event and had Physical reads that matched the size of the table. Also the execution time was several minutes.
Statement is similar to the following:
(@P1 bigint)INSERT INTO ProductionTable WITH(ROWLOCK) ("ALL", "THE", "COLUMNS" FROM (DELETE FROM HistoricTable WITH(ROWLOCK) OUTPUT deleted.* WHERE ClusterKey = @P1) AS deleted
Both tables have the same Cluster key and it is used to fetch the row.
We actually retrieve a row from the historic table to the production one.
Running the query will execute in milliseconds and use clustered index seek ( as it should). It once happened (until now) to scan the table and I cannot imagine why.
- Is there something special I miss when using output ? Should we change the statement to 2 simple insert , delete statements?
- There is a possibility for statistics were updated during the execution time. Is there any way this could impact the optimizer although we are using the cluster key in the query?
Thank you in advance,
Marios