I have a fulltext query which is usually very fast but may time out when it causes a statistics update since statistics updating is very slow on this database. Usually the query "recovers" to normal speed after the statistics have been updated but I have seen a case where the query always times out which I can only explain with the fact that the statistics are never updated (or so I think).
Unfortunately I cannot reproduce the problem at this point since we switched statistics updating to “Auto Update Statistics Asynchronously” to prevent the timeout from happening in the first place (slightly out of date statistics are not a problem for us).
So my question is
Is there a guarantee that statistics are updated on a query that times out if statistics updating is set to the (default) synchronous statistics updating (Auto Update Statistics Asynchronously = false)?
I found a reference that states otherwise – if that is the case I cannot explain the continuously timing out query case.
Best Answer
That was actually my question at AskSSC. I should have just tested it myself as I accepted an incorrect answer.
With the following test table
And the following test code
Profiler shows the following
First it creates the stats for column
b
successfully (the initialSP:StmtStarting
/SP:StmtCompleted
pair) . Then it starts creating the stats for columna
(The selectedSP:StmtStarting
entry in the screen shot). This entry is followed by anAUTOSTATS
event confirming that the statistics onb
were created then the timeout kicks in.It can be seen that the stats creation occurs on the same spid as the query and so this also aborts the creation of stats on column
a
. At the end of the process only one set of stats exists on the table.Edit
The above refers to stats creation, to test auto update of the stats I ran the above query without a timeout so both sets of stats were successfully created then updated all columns of all rows so that the stats would be out of date and re-ran the test. The trace for that is pretty similar
Finally just for completeness with
SET AUTO_UPDATE_STATISTICS_ASYNC ON
the trace looks as follows. It can be seen that system spids are used to perform the operation and they are unaffected by the query timeout as would be expected.