You can use the UPDATE STATISTICS
statement to gather statistics on a single index.
Purpose
The UPDATE STATISTICS
statement provides a syntax which enables you to analyze a single index.
With this syntax, the statement gathers statistics for all the index key expressions in the specified index.
This provides a shorthand so that you do not need to list all the index key expressions explicitly.
Syntax
update-statistics-index ::= ( UPDATE STATISTICS FOR | ANALYZE ) index-clause [ index-using ] [ index-with ]
For this syntax, UPDATE STATISTICS FOR
and ANALYZE
are synonyms.
The statement must begin with one of these alternatives.
INDEX Clause
index-clause ::= INDEX ( index-path '.' index-name | index-name ON keyspace-ref )
For this syntax, the INDEX
clause enables you to specify the index name and a keyspace.
- index-name
-
(Required) A unique name that identifies the index.
Index Path
index-path ::= keyspace-full | keyspace-prefix | keyspace-partial
keyspace-full ::= namespace ':' bucket '.' scope '.' collection
keyspace-partial ::= collection
You can use a dotted notation to specify the index and the keyspace on which the index is built. Refer to the ALTER INDEX or DROP INDEX statements for details of the syntax.
Keyspace Reference
keyspace-ref ::= keyspace-path | keyspace-partial
keyspace-path ::= [ namespace ':' ] bucket [ '.' scope '.' collection ]
keyspace-partial ::= collection
Alternatively, you can use the index name with the ON
keyword and a keyspace reference to specify the keyspace on which the index is built.
Refer to the ALTER INDEX or DROP INDEX statements for details of the syntax.
USING Clause
index-using ::= USING GSI
In Couchbase Server 6.5 and later, the index type for a secondary index must be Global Secondary Index (GSI).
The USING GSI
keywords are optional and may be omitted.
WITH Clause
index-with ::= WITH expr
Use the WITH
clause to specify additional options.
- expr
-
An object with the following properties:
- sample_size
-
[Optional] An integer specifying the sample size to use for distribution statistics. A minimum sample size is also calculated. If the specified sample size is smaller than the minimum sample size, the minimum sample size is used instead.
- resolution
-
[Optional] A float representing the percentage of documents to store in each distribution bin. If omitted, the default value is
1.0
, meaning each distribution bin contains 1% of the documents, and therefore 100 bins are required. The minimum resolution is0.02
(5000 distribution bins) and the maximum is5.0
(20 distribution bins). - update_statistics_timeout
-
[Optional] A number representing a duration in seconds. The command times out when this timeout period is reached. If omitted, a default timeout value is calculated based on the number of samples used.
- batch_size
-
[Optional] Only applies when processing multiple index expressions at once. If there is a large number of index expressions to process, the cost-based optimizer deals with them in batches. This option is an integer specifying the maximum number of index expressions in each batch. If omitted, the default value is
10
. You can specify a different value based on the memory availability of the system. Note that when index expressions are processed in batches, theupdate_statistics_timeout
value (above) applies to each batch.
Refer to Distribution Statistics for more information on sample size and resolution.
Examples
UPDATE STATISTICS FOR
INDEX default:`travel-sample`.inventory.airport.def_inventory_airport_city;
UPDATE STATISTICS FOR
INDEX def_inventory_airport_city ON default:`travel-sample`.inventory.airport;
This query is equivalent to the query in Example 1.
ANALYZE INDEX default:`travel-sample`.inventory.airport.def_inventory_airport_city;
This query is equivalent to the query in Example 1.
ANALYZE INDEX def_inventory_airport_city ON default:`travel-sample`.inventory.airport;
This query is equivalent to the query in Example 1.