Couchbase 是有序键值存储吗?

Is Couchbase an ordered key-value store?

Couchbase 中的文档是否按键顺序存储?换句话说,它们是否允许有效查询以检索键落在特定范围内的所有文档?特别是我需要知道这是否适用于 Couchbase lite。

查询效率与添加到服务器的视图的构造相关。

Couchbase/Couchbase Lite 只存储程序员在这些视图中指定和生成的索引。当 Couchbase 重新平衡时,它会在节点之间移动文档,因此保证键顺序或保持一致似乎不切实际。

(很少 databases/datastores 保证磁盘上的文档或行排序,因为索引提供此功能的成本更低。)

Couchbase 文档检索是通过 map/reduce 视图中的查询执行的:

A view creates an index on the data according to the defined format and structure. The view consists of specific fields and information extracted from the objects in Couchbase. Views create indexes on your information that enables search and select operations on the data.

来源:views intro

A view is created by iterating over every single document within the Couchbase bucket and outputting the specified information. The resulting index is stored for future use and updated with new data stored when the view is accessed. The process is incremental and therefore has a low ongoing impact on performance. Creating a new view on an existing large dataset may take a long time to build but updates to the data are quick.

来源:Views Basics

source

最后,关于 Translating SQL to map/reduce 的部分可能会有帮助:

In general, for each WHERE clause you need to include the corresponding field in the key of the generated view, and then use the key, keys or startkey / endkey combinations to indicate the data you want to select.

总而言之,Couchbase 视图不断更新它们的索引以确保最佳查询性能。 Couchbase Lite 类似于查询,但服务器的机制略有不同:

View indexes are updated on demand when queried. So after a document changes, the next query made to a view will cause that view's map function to be called on the doc's new contents, updating the view index. (But remember that you shouldn't write any code that makes assumptions about when map functions are called.)

How to improve your view indexing: The main thing you have control over is the performance of your map function, both how long it takes to run and how many objects it allocates. Try profiling your app while the view is indexing and see if a lot of time is spent in the map function; if so, optimize it. See if you can short-circuit the map function and give up early if the document isn't a type that will produce any rows. Also see if you could emit less data. (If you're emitting the entire document as a value, don't.)

来自 Couchbase Lite - View