为什么 CouchDB 视图支持压缩但 Mango 索引不支持?

Why do CouchDB views support compaction but mango indexes do not?

当我阅读 CouchDB 文档时,我发现视图需要压缩而芒果索引不需要,这很奇怪。它们本质上不是同一件事,并且需要遵守清除未使用或旧条目的相同要求吗?这对我来说似乎是一个疏忽。

我想我只需要澄清一下它们之间的索引树有何不同。

谢谢!

实际上可以压缩芒果索引,因为在 /db/_index 端点1 创建的每个索引都有一个“ddoc”(设计文档),就像设计文档一样获得 map/reduce 次观看。

引用 /db/_index 文档,

Mango is a declarative JSON querying language for CouchDB databases. Mango wraps several index types, starting with the Primary Index out-of-the-box. Mango indexes, with index type json, are built using MapReduce Views.1

现在查看 /db/_compact/design-doc2 端点的文档*

Compacts the view indexes associated with the specified design document. It may be that compacting a large view can return more storage than compacting the actual db. Thus, you can use this in place of the full database compaction if you know a specific set of view indexes have been affected by a recent database change.

*强调我的

由于每个“芒果索引”都有一个设计文档,因此可以使用 /db/_compact/design-doc 端点压缩任何芒果索引。

这可以通过 curl 轻松验证。假设在“堆栈”数据库中有一个带有 ddoc="foo-json-index-ddoc" 的芒果索引,

curl -v -X POST -H "Content-Type: application/json" http://localhost:5984/stack/_compact/foo-json-index-ddoc 

详细(成功)响应如下所示

< HTTP/1.1 202 Accepted
< Cache-Control: must-revalidate
< Content-Length: 12
< Content-Type: application/json
< Date: Tue, 18 May 2021 14:30:33 GMT
< Server: CouchDB/2.3.1 (Erlang OTP/19)
< X-Couch-Request-ID: bbf2b7b0c9
< X-CouchDB-Body-Time: 0
<
{"ok":true}
* Connection #0 to host localhost left intact

为了清楚起见,我没有授权。

[1] /db/_index
[2]/db/_compact/design-doc