SQL Server 2012 partitioned table statistics update behavior change when rebuilding index

Published Jan 15 2019 03:02 PM 410 Views
Microsoft
First published on MSDN on Mar 19, 2013
In this blog, I will talk about a couple of things related to statistics update when rebuilding index on a partitioned table.



In past versions, when you rebuild an index, you will get statistics update equivalent to FULLSCAN for free.   This is true regardless if the table is partitioned table or not.

But SQL Server 2012 changed the behavior for partitioned table.   If a table is partitioned, ALTER INDEX REBUILD will only update statistics for that index with default sampling rate.  In other words, it is no longer a FULLSCAN.  This is documented in http://technet.microsoft.com/en-us/library/ms188388.aspx .  But lots of users do not realized that.  If you want fullscan, you will need to run UPDATE STATISTCS WITH FULLSCAN.   This change was made because we started to support large number of partitions up to 15000 by default.  Previous versions did support 15000 partitions.  But it’s not on by default.  Supporting large number of partitions will cause high memory consumption if we track the stats with old behavior (FULLSCAN).  With partitioned table, ALTER INDEX REBUILD actually first rebuilds index and then do a sample scan to update stats in order to reduce memory consumption.



Another behavior change is actually a bug.  In SQL 2012, ALTER INDEX REBUILD doesn’t preserve norecompute property for partitioned tables.   In other words, if you specify norecompute on an index, it will be gone after you run ALTER INDEX REBUILD for SQL 2012.   We have corrected this issue in a newly released CU 3 of SQL Server 2012 SP1.  Here is the KB: http://support.microsoft.com/kb/2814780





Jack Li | Senior Escalation Engineer | Microsoft SQL Server Support

%3CLINGO-SUB%20id%3D%22lingo-sub-317600%22%20slang%3D%22en-US%22%3ESQL%20Server%202012%20partitioned%20table%20statistics%20update%20behavior%20change%20when%20rebuilding%20index%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-317600%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Mar%2019%2C%202013%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20In%20this%20blog%2C%20I%20will%20talk%20about%20a%20couple%20of%20things%20related%20to%20statistics%20update%20when%20rebuilding%20index%20on%20a%20partitioned%20table.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20past%20versions%2C%20when%20you%20rebuild%20an%20index%2C%20you%20will%20get%20statistics%20update%20equivalent%20to%20FULLSCAN%20for%20free.%26nbsp%3B%26nbsp%3B%20This%20is%20true%20regardless%20if%20the%20table%20is%20partitioned%20table%20or%20not.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20But%20SQL%20Server%202012%20changed%20the%20behavior%20for%20partitioned%20table.%26nbsp%3B%26nbsp%3B%20If%20a%20table%20is%20partitioned%2C%20ALTER%20INDEX%20REBUILD%20will%20only%20update%20statistics%20for%20that%20index%20with%20default%20sampling%20rate.%26nbsp%3B%20In%20other%20words%2C%20it%20is%20no%20longer%20a%20FULLSCAN.%26nbsp%3B%20This%20is%20documented%20in%20%3CA%20href%3D%22http%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fms188388.aspx%22%20title%3D%22http%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fms188388.aspx%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Ftechnet.microsoft.com%2Fen-us%2Flibrary%2Fms188388.aspx%20%3C%2FA%3E%20.%26nbsp%3B%20But%20lots%20of%20users%20do%20not%20realized%20that.%26nbsp%3B%20If%20you%20want%20fullscan%2C%20you%20will%20need%20to%20run%20UPDATE%20STATISTCS%20WITH%20FULLSCAN.%26nbsp%3B%26nbsp%3B%20This%20change%20was%20made%20because%20we%20started%20to%20support%20large%20number%20of%20partitions%20up%20to%2015000%20by%20default.%26nbsp%3B%20Previous%20versions%20did%20support%2015000%20partitions.%26nbsp%3B%20But%20it%E2%80%99s%20not%20on%20by%20default.%26nbsp%3B%20Supporting%20large%20number%20of%20partitions%20will%20cause%20high%20memory%20consumption%20if%20we%20track%20the%20stats%20with%20old%20behavior%20(FULLSCAN).%26nbsp%3B%20With%20partitioned%20table%2C%20ALTER%20INDEX%20REBUILD%20actually%20first%20rebuilds%20index%20and%20then%20do%20a%20sample%20scan%20to%20update%20stats%20in%20order%20to%20reduce%20memory%20consumption.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Another%20behavior%20change%20is%20actually%20a%20bug.%26nbsp%3B%20In%20SQL%202012%2C%20ALTER%20INDEX%20REBUILD%20doesn%E2%80%99t%20preserve%20norecompute%20property%20for%20partitioned%20tables.%26nbsp%3B%26nbsp%3B%20In%20other%20words%2C%20if%20you%20specify%20norecompute%20on%20an%20index%2C%20it%20will%20be%20gone%20after%20you%20run%20ALTER%20INDEX%20REBUILD%20for%20SQL%202012.%26nbsp%3B%26nbsp%3B%20We%20have%20corrected%20this%20issue%20in%20a%20newly%20released%20CU%203%20of%20SQL%20Server%202012%20SP1.%26nbsp%3B%20Here%20is%20the%20KB%3A%20%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F2814780%22%20title%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F2814780%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3E%20http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F2814780%20%3C%2FA%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CP%3EJack%20Li%20%7C%20Senior%20Escalation%20Engineer%20%7C%20Microsoft%20SQL%20Server%20Support%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-317600%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Mar%2019%2C%202013%20In%20this%20blog%2C%20I%20will%20talk%20about%20a%20couple%20of%20things%20related%20to%20statistics%20update%20when%20rebuilding%20index%20on%20a%20partitioned%20table.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-317600%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Esql%202012%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EStorage%20Engine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 03:02 PM
Updated by: