Reputation: 456
As per the documentation primary index (index on document key) is optional in Couchbase. How does Couchbase efficiently ensure uniqueness of document key without an index?
Upvotes: 1
Views: 115
Reputation: 26169
The primary index that documentation refers to is only for N1QL queries, and has nothing to do with enforcing uniqueness.
Instead, uniqueness is enforced by the key/value data service. From the "Data" overview documentation:
Each value (binary or JSON) is identified by a unique key, defined by the user or application when the item is saved. The key is immutable: once the item is saved, the key cannot be changed.
I am not an expert on Couchbase internals, but unique keys are fundamental to how Couchbase stores/retrieves/shards data. Check out Understanding vBuckets for more information ('vBucket' is analogous to 'shard'). Here's a snippet:
Items are written to and retrieved from vBuckets by means of a CRC32 hashing algorithm, which is applied to the item’s key, and so produces the number of the vBucket in which the item resides.
Upvotes: 1