Background:
I am a developer working on an application that has a relatively large table (in my experience at least) of 1.7 billion records.
The table is a history table, and the application imports to this table daily. On average, it will insert approximately 1.2 million records per day.
Yes, there is a lot of history there, no, it should not all be online at the same time.
The table is not partitioned.
The table contains a report date column and a currency column, among others, but those are the major logical "partitioning" ones if you could call them that.
The table has a clustered index on (ID, ReportDate) as well as a non clustered index on ReportDate, Currency, and a couple other columns.
Today I was tasked with troubleshooting an application issue where there was a command timeout doing a delete by Report Date and Currency. I couldn't retrieve the execution plan for the delete of the entire record set (about 1.2 million rows). I did a delete of 10k records which took 54 seconds.
While working on a completely separate application also dealing with large tables, I found a scenario where the table is big enough that the threshold for automatic statistics updates was higher that the number of records being inserted into the table, so queries against that newly inserted data was not included in the statistics, and so any query assumed there would be 1 record (according to the execution plan) and so SQL chose to use nested loop joins on millions of records.
The actual question:
Do statistics play any role in how SQL actually executes delete operations?
My team has the statistics experience in very recent memory so they asked me if it could be related, and my intuition says "probably not" because there are no joins involved in this delete that timed out.
I went ahead and updated the statistics on the table (specifically the statistics on the indexes) and ran the delete again and it went from taking 54 seconds for a batch delete of 10k records, down to 18 seconds after the statistics update. So there's a correlation there. However, the database is on a shared server with a number of other databases, so I can't isolate it and say "yes the statistics helped" when it could simply be that the server was busy at the time the delete timed out and now when trying it again it's less busy.
In trying to troubleshoot I looked at the activity monitor and saw that the process was frequently waiting for PAGEIOLATCH_SH and I/O was really low, under 3MB/sec.