RavenDB 如何决定是否将字段存储在索引中?

How to decide whether to store fields in indexes in RavenDB?

在 RavenDB 3.x 文档中,有多篇文章涉及在索引中存储字段值的概念,以便转换器可以从索引本身获取此数据,而不必加载文档。

但是,没有提到这样做的确切含义,我不清楚这在哪些情况下会带来好处还是过多的开销。

文档基本上是这样说的:

Projections and Stored fields

If projection function only requires fields that are stored, then document will not be loaded from storage and all data will come from index directly. This can increase query performance (by the cost of disk space used) in many situations when whole document is not needed.

(Indexes/Querying/Projections and more or less the same in indexes/storing data in indexes)

当我阅读它时,我真的觉得它不值得研究,但是当阅读 Query Flow 时,我更加确信使用它。

如果我理解正确,当使用带存储的投影+索引时,您可以使查询根本不从存储中检索文档,代价是磁盘 space?

假设正确:

  1. 关于磁盘的额外使用量 space,我可以期待多少?任何人都可以在上面标出一些数字吗?
  2. 这有多高效?这些值是如何存储在索引中的?读取存储的数据与存储的文档的成本是多少?

我的直觉是,如果您的文档包含 10 个数字字段,并且将其中的 4 个存储在索引中,那么您需要大约多 40% 的磁盘 space?但是在使用该索引查询文档时,您也只需要阅读文档的 40%?

总的来说,不用费心。 这适用于非常特殊的情况,通常不值得这样做。除非您有非常大的文档(数百 KB),否则在不使用索引存储或使用转换器的情况下使用投影会更容易。