A newer version of this documentation is available.

View Latest

Global Secondary Indexes Versus Views

There are a number of differences between views and GSIs. At a high level, GSIs are built for N1QL queries, which are great for supporting interactive applications that require fast response times. Views, on the other hand, provide sophisticated user defined functions to provide great flexibility in indexing. Views can support complex interactive reporting queries with a precalculated result.
N1QL can utilize both GSIs and Views. However, N1QL only utilizes a subset of view capabilities. N1QL does not support user defined MapReduce definitions and restricts the definitions to a subset of capabilities only available through the CREATE INDEX statement.

The following table lists the key differences between GSIs and Views.

Table 1. Differences between GSIs and Views
GSIs Views

Partitioning model

  • GSIs are part of the index service, thus GSI independently partitions using the new multidimensional scaling capabilities and the services architecture.

  • Each GSI can only be placed in one node.

  • GSIs require manual partitioning to prevent hot spots.

  • GSIs can respond without requiring scatter-gather operations.

For more information, see "GSI and index partitioning" under Global secondary indexes.

  • Views are auto-partitioned based on the data partitioning which is based on the hashing of the keys to vBuckets and vBucket placement.

  • View queries need to perform expensive scatter-gather operations.

Scaling model

GSIs are part of the index service. Using the new multidimensional scaling capabilities, you (as an administrator) can choose to deploy indexes on hardware that is tuned for indexing.

Views are scaled with the data service and thus cannot be independently scaled.

Performance characteristics

N1QL queries that require singleton lookups or range scans can process scans on GSI without scatter-gather operations if the relevant indexes are available for the query.

Views are partitioned based on data distribution and document keys, thus requiring scatter-gather operations for the same type of queries. Network based processing can be more expensive than local in-memory processing because scatter-gather operations are generally much slower. As the node count of the cluster increases, views require a wider fan-out and hence a more network based processing.

Managed cache

GSIs come with a managed cache that can provide higher performance during index maintenance and index scans.

Views depend on the file system cache and can be impacted by fluctuations in the underlying operating system.

Storage engine

For more information on the differences between Couchstore and ForestDB, see "Couchstore versus ForestDB" under Storage Architecture.

GSIs use ForestDB for storage. Starting version 5.0, the default storage for GSIs in the Enterprise Edition is Plasma.

Views use Couchstore for storage.

High availability

GSIs require multiple indexes with identical definitions to be manually placed on multiple nodes.

Views provide built-in replicas with smart placement.