gpt4 book ai didi

database - Couchbase 是有序键值存储吗?

转载 作者:搜寻专家 更新时间:2023-10-30 22:11:08 25 4
gpt4 key购买 nike

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

最佳答案

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

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

(很少有数据库/数据存储能保证磁盘上的文档或行顺序,因为索引提供此功能的成本更低。)

Couchbase 文档检索是通过 View 中的 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

enter image description here

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 View 不断更新它们的索引以确保最佳查询性能。 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

关于database - Couchbase 是有序键值存储吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28397652/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com