As Couchbase data platform evolved, services like N1QL and GSI Indexing handled the use cases Couchbase VIEWS used to handle and much more.  It’s logical to ask the comparative question between them.  Here is a table comparing both.  This is intended for developers and architects familiar with both them and not as an introductory article. Use the links here to learn more and play with the respective features.

 Topic
Couchbase Map-Reduce Views
Couchbase N1QL+GSI
ApproachBased on user-defined map() and reduce() functions that operate on data in the background. Because map() and reduce() is written in Javascript, you can code complex logic within those functions.Based on declarative N1QL query (SQL for JSON).  Uses appropriate indexes to optimize execution and executed dynamically by orchestrating Query-Index-data services.  N1QL enables easily writeable and readable queries for JSON.  Because it’s inspired by SQL, it’s flexible, composable.  Because, it’s extended for JSON, it works on rich JSON data.  Uses 4-valued boolean logic (true, false,NULL, MISSING)
More InfoCouchbase Docs: http://bit.ly/2jQrY11
  1. http://query.couchbase.com
  2. https://blog.couchbase.com/n1ql-practical-guide-second-edition/

 

QueryingQuery based on

  1. Single key
  2. Set of keys
  3. Start-End key
  4. Start-End document keys
  5. Group BY, Aggregation
  6. Pagination

 

Query Statements

  1. SELECT
  2. INSERT
  3. UPDATE
  4. DELETE
  5. MERGE
  6. INFER
  7. EXPLAIN

Query Operations:

  1. Single key
  2. Set of keys
  3. Range keys
  4. Range of document keys
  5. Arbitrarily complex predicates
  6. INNER JOIN, LEFT OUTER JOIN
  7. NEST, UNNEST
  8. GROUP BY
  9. Aggregation
  10. Pagination (OFFSET, LIMIT)
  11. Optimization
  12. ORDER BY
  13. HAVING
  14. Subqueries (correlated, non-correlated)
  15. Derived tables
  16. SET operations: UNION, UNION ALL, EXCEPT, EXCEPT ALL, INTERSECT
  17. Highly composable queries, meaning these operations can be simply combined with each other to express complex business questions and operations easily.
IndexingSimple index for views.
  1. Primary Index
  2. Named primary index
  3. Secondary index
  4. Composite Secondary Index
  5. Functional index
  6. Array Index
  7. ALL array
  8. ALL DISTINCT array
  9. Partial Index
  10. Adaptive Index
  11. Duplicate Indices
  12. Covering Index
PartitioningAligned to data partitioning.Independent services.

N1QL and GSI scales independent of Data service and each other.

ScaleScales with data serviceIndependent scaling via Multidimensional scaling (MDS)
Fetch with document keyBecause the data is partitioned on document key, fetches the document directly from the nodeSpecify the query via USE KEYS clause.

Because the data is partitioned on document key, fetches the document directly from the node

Fetch with Index keyScatter-GatherEach index scan on a single node; Data on multiple nodes.

Post processing in Query node

Range scanScatter-GatherIndex scan on a single node.

Post processing in Query node

Grouping, aggregationBuilt-in with Views APIBuilt into N1QL
CachingFile systemIndex buffer pool

Data cache

StorageCouchstorePlasma storage engine (5.0 & above)

Memory Optimized Index (4.5 and above)

ForestDB (community)

AvailabilityReplica Based5.0: Replicas

4.x: Equivalent Indexes

Query Latency

(Simple queries)

10 milliseconds to 100 milliseconds5 milliseconds+
Query Throughput

(Simple queries)

3K to 4K queries per second40K queries per second
ScalabilityModerate (scaling tied to data service)High (independent scaling of index and query services: MDS)
ApplicabilityAggregations, best of large scale aggregations for low and moderate latency requirements.  Map-reduce operations on the data is done in the background as the data is modified.Best for attribute based lookup, range scans, complex select-join-project-array

Operations.  Supports grouping, aggregation and ordering — these operations are done dynamically as part of query execution.

Application requirementsReport on well defined metrics

Large scale aggregations

Latency sensitive

Secondary key lookups

Range Scans

Operational aggregations

Filtered queries

Ad-hoc queries with complex predicates, joins, aggregations, app search, pagination, secondary key based updates.

SpatialSupported via Spatial ViewsNot directly.

https://dzone.com/articles/speed-up-spatial-search-in-couchbase-n1ql

ConsistencyStale = UPDATE_AFTER

Stale = OK

Stale = FALSE

Unbounded (stale = OK)

AT_PLUS (read your own writes)

REQUEST_PLUS (read after index updates up to now(). Stale = False).

ToolsWeb consoleWeb console, Developer workbench, Query monitoring, Query Profiling, Visual explain, INFER.

 

Posted by Keshav Murthy

Keshav Murthy is a Senior Director at Couchbase R&D. Previously, he was a Senior Director at MapR, Senior Architect for IBM, with more than 20 years experience in database design & development. He lead the SQL and NoSQL R&D team at IBM Informix. He has received two President's Club awards at Couchbase, two Outstanding Technical Achievement Awards at IBM. Keshav has a bachelors degree in Computer Science and Engineering from the University of Mysore, India, holds eight US patents and invented databases for systems of engagement.

Leave a reply