CREATE STATISTICS
Valid in: SQL
The CREATE STATISTICS statement creates statistics and histograms on specified tables and columns. It has the same effect as optimizedb, but allows applications to manipulate statistics from within a transaction.
This statement allows histograms to be constructed on global temporary tables, providing much better optimization of subsequent queries that reference the temporary tables.
To drop statistics, use the DROP STATISTICS statement.
This statement has the following format:
CREATE {STATISTICS | STATS} FOR table [(column list)] [{, table [(column list)]} [WITH option list]
FOR table (column list)
Specifies the table and optionally columns to create statistics for. The following can be specified instead of a table and column list:
FOR ALL TABLES
Creates statistics for all tables in a database.
FOR ALL user TABLES
Creates statistics for all tables owned by the specified user ID.
WITH option list
Specifies options for creating statistics, as any of the following:
NOSAMPLE
Requests no sampling. All rows from the table are read to create the histograms. It has the same effect as the optimizedb –zns flag.
SAMPLE = n
Specifies the percentage (n) of rows to be sampled in creating the histograms.
Limits: 0 through 100
Default: If this option is not specified, tables with more than two million rows are sampled to reduce the number of rows processed to one million. For example, if there are five million rows, a 20% sample is used.
MAXCELLS = n
Specifies the maximum number of cells (n) to create in the histograms.
Limits: 32000
Default: 1000
COLUMN COMPARE
Requests the building of column comparison statistics for compatible pairs of columns in each table.
COLUMN GROUP
Requests the building of column grouping statistics. These statistics should improve the estimates of some cardinalities that are subject to column correlation. COLUMN GROUP can be specified only with explicit table names and only with column lists with two, three, or four column names. The FOR ALL syntax is not supported for column groups.