update all statistics

Description

Updates all statistics information for a given table, including histograms on all columns, regardless of whether they are indexed. You can run update all statistics on a single data partition.

Syntax

update all statistics
	table_name [partition data_partition_name]
	[using step values]
	[with consumers = consumers] 
	[, sampling=N [percent]]
	[, no_hashing | partial_hashing | hashing] 
		[, max_resource_granularity = N [percent]]
		[, histogram_tuning_factor = int ]
		[, print_progress = int]

Parameters

table_name

is the name of the table for which statistics are being updated.

data_partition_name

is the name of the partition to be updated. Statistics for each local index partition on the data partition is updated. Does not update statistics for global indexes.

using step values

specifies the number of histogram steps. The default value is 20, for columns where no statistics exist. To change the default, use sp_configure to modify the number of histogram steps parameter. If statistics for a column already exist in sysstatistics, the default value is the current number of steps.

The steps are applied to each partition of a partitioned table—for example, update index statistics uses the default value of 20 steps for each data and index partition involved in the scan for updating statistics. If global statistics are generated through an index scan of a global index, then 20 steps are applied by default. If partition statistics are generated, either through a data scan or local index scan, then by default, 20 steps are applied for each partition.

If the histogram steps specified through using step values is M, and the histogram_tuning_factor parameter is N, then update index statistics uses between 0 and M*N steps, depending on the number of frequency cells that update index statistics isolates and whether any range cells exist.

with consumers = consumers

specifies the number of consumer processes to be used for a sort when column_list is provided and parallel query processing is enabled. The consumers option specifies the degree of parallelism applied to a sort performed for statistics update on a single data partition. For example, if update statistics with a column list is applied to a table with three data partitions, data from each of the three partitions is sorted separately and the consumers option is applied during each of the sort. The three sorts themselves are not performed in parallel.

NoteThe value for the max parallel degree configuration parameter must be greater than the value for with consumers. For example, if with consumers is set to 2, then max parallel degree must be at least 3.

with sampling = N percent

specifies the percentage of the column to be randomly sampled to gather statistics. The value for N is any number between 1 and 100.

[no_hashing | partial_hashing | hashing

indicates the level of hash-based statistics update all statistics gathers. One of:

  • no_hashingupdates all statistics uses the algorithm from Adaptive Server versions earlier than 15.7, gathering sort-based statistics.

  • partial_hashingupdates all statistics uses the algorithm for columns with fewer than 65536 unique values. If updates all statistics encounters unique column counts greater or equal to the 65536 threshold, it uses an extra scan with a sort.

  • hashingupdates all statistics uses low-domain and high-domain hashing to create the histograms.

The default for these parameters is the configured value for update statistics hashing.

max_resource_granularity = N percent

limits the amount of tempdb buffer cache used with the update all statistics and hashing.

histogram_tuning_factor = integer

determines update all statistics’s distribution granularity.

print_progress = int

Determines if update all statistics displays progress messages.

  • 0 – (the default) command does not display any progress messages

  • 1 – command displays progress messages

Examples

Example 1

Updates all statistics for the salesdetail table:

update all statistics salesdetail

Example 2

Updates all statistics for the smallsales partition on salesdetail table:

update all statistics salesdetail partition smallsales

Example 3

Updates hash-based statistics for the authors table:

update all statistics authors with hashing

Usage


Using hash-based statistics

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

You must be the table owner or a user with update statistics permission on the table to run update all statistics.

See also

Commands update statistics, update index statistics, update statistics, update table statistics