You are viewing the documentation for a prerelease version.

Updating Statistics for a Single Index

  • Couchbase Server 7.0
    +
    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 ]
    ( '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 )
    '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

    keyspace-full | keyspace-prefix | keyspace-partial
    keyspace-full ::= namespace ':' bucket '.' scope '.' collection
    namespace ':' bucket '.' scope '.' collection
    keyspace-prefix ::= [ namespace ':' ] bucket
    ( namespace ':' )? bucket
    keyspace-partial ::= collection
    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 | keyspace-partial
    keyspace-path ::= [ namespace ':' ] bucket [ '.' scope '.' collection ]
    ( namespace ':' )? bucket ( '.' scope '.' collection )?
    keyspace-partial ::= collection
    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
    '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
    '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 is 0.02 (5000 distribution bins) and the maximum is 5.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.

    Refer to Distribution Statistics for more information on sample size and resolution.

    Result

    The statement returns an empty array.

    Examples

    Example 1. UPDATE STATISTICS with index identifier
    UPDATE STATISTICS FOR
    INDEX default:`travel-sample`.inventory.airport.def_inventory_airport_city;
    Example 2. UPDATE STATISTICS with ON clause
    UPDATE STATISTICS FOR
    INDEX def_inventory_airport_city ON default:`travel-sample`.inventory.airport;

    This query is equivalent to the query in Example 1.

    Example 3. ANALYZE with index identifier
    ANALYZE INDEX default:`travel-sample`.inventory.airport.def_inventory_airport_city;

    This query is equivalent to the query in Example 1.

    Example 4. ANALYZE with ON clause
    ANALYZE INDEX def_inventory_airport_city ON default:`travel-sample`.inventory.airport;

    This query is equivalent to the query in Example 1.