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-using | |
index-with |
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 |
A unique name that identifies the index. |
index-path | |
keyspace-ref |
Index Path
index-path ::= keyspace-full | keyspace-prefix | keyspace-partial
keyspace-full ::= namespace ':' bucket '.' scope '.' collection
keyspace-prefix ::= ( namespace ':' )? bucket
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:
|
Refer to Distribution Statistics for more information on sample size and resolution.
Examples
To try the examples in this section, set the query context to the inventory
scope in the travel sample dataset.
For more information, see Query Context.
UPDATE STATISTICS FOR
INDEX airport.def_inventory_airport_city;
UPDATE STATISTICS FOR
INDEX def_inventory_airport_city ON airport;
This query is equivalent to the query in Example 1.
ANALYZE INDEX airport.def_inventory_airport_city;
This query is equivalent to the query in Example 1.
ANALYZE INDEX def_inventory_airport_city ON airport;
This query is equivalent to the query in Example 1.