A newer version of this documentation is available.

View Latest

Delete Statistics

  • reference
    +
    You can use the UPDATE STATISTICS statement to delete statistics.

    Purpose

    The UPDATE STATISTICS statement provides a syntax which enables you to delete statistics for a set of index expressions, or for an entire keyspace.

    Since the cost-based optimizer uses statistics for cost calculations, deleting statistics for a set of index expressions effectively turns off the cost-based optimizer for queries which utilize predicates on those expressions. Deleting all statistics for a keyspace turns off the cost-based optimizer for all queries referencing that keyspace.

    Syntax

    update-statistics-delete ::=
      ( UPDATE STATISTICS [ FOR ] | ANALYZE [ KEYSPACE | COLLECTION ] )
        keyspace-ref delete-clause
    ( 'UPDATE' 'STATISTICS' 'FOR'? | 'ANALYZE' ( 'KEYSPACE' | 'COLLECTION')? ) keyspace-ref delete-clause

    For this syntax, UPDATE STATISTICS and ANALYZE are synonyms. The statement must begin with one of these alternatives.

    When using the UPDATE STATISTICS keywords, the FOR keyword is optional. Including this keyword makes no difference to the operation of the statement.

    When using the ANALYZE keyword, the COLLECTION or KEYSPACE keywords are optional. Including either of these keywords makes no difference to the operation of the statement.

    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

    The simple name or fully-qualified name of the keyspace for which you want to delete statistics. Refer to the CREATE INDEX statement for details of the syntax.

    DELETE Clause

    delete-clause ::= DELETE delete-expressions | delete-all
    'DELETE' ( delete-expressions | delete-all )

    The DELETE clause enables you to provide a comma-separated list of index expressions for which you want to delete statistics, or to specify that you want to delete all statistics for the keyspace.

    Delete Expressions

    delete-expressions ::= [ STATISTICS ] '(' index-expr [ ',' index-expr ]* ')'
    'STATISTICS'? '(' index-expr ( ',' index-expr )* ')'

    If you used the UPDATE STATISTICS keywords at the beginning of the statement, you may not use the STATISTICS keyword in this clause.

    Conversely, if you used the ANALYZE keyword at the beginning of the statement, you must include the STATISTICS keyword in this clause.

    index-expr

    The expression for which you want to delete statistics. This may be any expression that is supported as an index key, including, but not limited to:

    Delete All Statistics

    delete-all ::= ALL | STATISTICS
    'ALL' | 'STATISTICS'

    If you used the UPDATE STATISTICS keywords at the beginning of the statement, you must use the ALL keyword in this clause.

    Conversely, if you used the ANALYZE keyword at the beginning of the statement, you must use the STATISTICS keyword in this clause.

    Result

    The statement returns an empty array.

    Examples

    Example 1. Delete statistics with UPDATE STATISTICS
    UPDATE STATISTICS FOR `travel-sample`.inventory.hotel
    DELETE (city, country, free_breakfast);
    Example 2. Delete statistics with ANALYZE
    ANALYZE KEYSPACE `travel-sample`.inventory.hotel
    DELETE STATISTICS (city, country, free_breakfast);

    This query is equivalent to the query in Example 1.

    Example 3. Delete all statistics with UPDATE STATISTICS
    UPDATE STATISTICS FOR `travel-sample`.inventory.airport DELETE ALL;
    Example 4. Delete all statistics with ANALYZE
    ANALYZE KEYSPACE `travel-sample`.inventory.airport DELETE STATISTICS;

    This query is equivalent to the query in Example 3.