问题
There are some other similar question to this but, please, do not confuse.
I know there's a function STATS_DATE()
to know where the stats where updated, which is fine, but what I want to know is what triggers an update of this stats, or a cut-off.
I know there's a report for this as well.
But last week I saw the stats in certain server and they gave me very good information with amounts of 4 digits for the main tables in this particular database.
Right now looking in the same production server and the STATS_UPDATE
function returned they were updated last Saturday, but this server has been up for weeks without reboot not even service restart. So I know I'm looking the stats accumulated basically just this Monday morning.
So, I would like to know where can I set this settings so the server keeps accumulating the index usage stats until I clear the log or whatever storage it use.
回答1:
There are various "stats" that SQL server maintains for Tables and indexes.
Histogram statistics. Thes are the stats that the query optimizer uses. STATS_DATE() returns the last date/time these were updated. The criteria for automatic updating of histogram statistics is 500 rows + 20% of the table. So a table with 100,000 rows, you'd have to update 20,500 rows before triggering a recalculation of these. You can't change the threshold for automatic statistic updating, however, you can turn off automatic statistic updating and/or manually update statistics on particular tables and indexes.
Usage statistics: These are found in sys.dm_db_index_usage_stats. Index usage statistics keep track of things like seeks and scans from SELECT queries. They are not persisted and get reset on restart of sql server. These statistics also get reset if the underlying index is rebuilt "ALTER INDEX ... REBUILD", but not with "ALTER INDEX ... REORG"
Operational Statistics: These are found in sys.dm_db_index_operational_stats. Operational statistics are things such as page splits, leaf level inserts and PAGEIOLATCH delay. These are also non persisted.
来源:https://stackoverflow.com/questions/13689186/how-often-are-sql-server-index-usage-stats-updated-and-what-triggers-it