You are viewing the documentation for a prerelease version.

View Latest

DROP PRIMARY INDEX

    +

    The DROP PRIMARY INDEX statement allows you to drop an unnamed primary index.

    Named primary indexes that are created using CREATE PRIMARY INDEX can only be dropped using the DROP INDEX command.
    RBAC Privileges

    User executing the DROP PRIMARY INDEX statement must have the Query Manage Index privilege granted on the keyspace. For more details about user roles, see Roles.

    Syntax

    drop-primary-index ::= DROP PRIMARY INDEX ON keyspace-ref [ index-using ]
    'DROP' 'PRIMARY' 'INDEX' 'ON' keyspace-ref index-using?

    Keyspace Reference

    keyspace-ref ::= keyspace-path | keyspace-partial
    keyspace-path | keyspace-partial

    Specifies the keyspace for the primary index to drop.

    If there is a hyphen (-) inside any part of the keyspace reference, you must wrap that part of the keyspace reference in backticks (` `). Refer to the examples below.

    Keyspace Path

    keyspace-path ::= [ namespace ':' ] bucket [ '.' scope '.' collection ]
    ( namespace ':' )? bucket ( '.' scope '.' collection )?

    If the keyspace is a named collection, or the default collection in the default scope within a bucket, the keyspace reference may be a keyspace path. In this case, the query context should not be set.

    namespace

    (Optional) An identifier that refers to the namespace of the keyspace. Currently, only the default namespace is available. If the namespace name is omitted, the default namespace in the current session is used.

    bucket

    (Required) An identifier that refers to the bucket name of the keyspace.

    scope

    (Optional) An identifier that refers to the scope name of the keyspace. If omitted, the bucket’s default scope is used.

    collection

    (Optional) An identifier that refers to the collection name of the keyspace. If omitted, the default collection in the bucket’s default scope is used.

    For example, default:`travel-sample` indicates the default collection in the default scope in the travel-sample bucket in the default namespace.

    Similarly, default:`travel-sample`.places.cities indicates the cities collection in the places scope in the travel-sample bucket in the default namespace.

    Keyspace Partial

    keyspace-partial ::= collection
    collection

    Alternatively, if the keyspace is a named collection, the keyspace reference may be just the collection name with no path. In this case, you must set the query context to indicate the required namespace, bucket, and scope.

    collection

    (Required) An identifier that refers to the collection name of the keyspace.

    For example, cities indicates the cities collection, assuming the query context is set.

    USING Clause

    index-using ::= USING GSI
    'USING' 'GSI'

    In Couchbase Server 6.5 and later, the index type for a primary index must be Global Secondary Index (GSI). The USING GSI keywords are optional and may be omitted.

    Example

    Example 1. Drop unnamed primary index

    Create an unnamed primary index on the travel-sample keyspace. Once the index creation statement comes back, query system:indexes for status of the index.

    CREATE PRIMARY INDEX ON `travel-sample` USING GSI;
    SELECT * FROM system:indexes;

    Subsequently, drop the unnamed primary index with the following statement so that it is no longer reported in the system:indexes output.

    DROP PRIMARY INDEX ON `travel-sample` USING GSI;
    SELECT * FROM system:indexes;