MarioDS
MarioDS

Reputation: 13063

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

In the RavenDB 3.x docs, there are multiple articles that touch on the concept of storing field values in indexes, so that transformers can fetch this data from the index itself rather than having to load the document.

However, the exact implications of doing this are not mentioned and it's unclear to me in which situations that this is going to give benefits vs. too much overhead.

The documentation basically says this about it:

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)

When reading I read it, it doesn't really feel worth looking in to, but when reading the Query Flow I get more convinced about using this.

If I understand correctly, you could make queries not retrieve the document from storage at all, when using projection + indexes with storage, at the cost of disk space?

Assuming that is correct:

  1. Regarding the extra usage of disk space, how much can I expect? Can anyone stick some numbers on this?
  2. How much more performant is this? How are these values stored in indexes anyway? How expensive is it to read that stored data vs. a stored document?

What I think intuitively is, that if your document contains 10 numeric fields, and you store 4 of these in an index, you need roughly 40% more disk space? But you also need to read only 40% of your document when querying it using that index?

Upvotes: 2

Views: 391

Answers (1)

Ayende Rahien
Ayende Rahien

Reputation: 22956

In general, don't bother. This is appropriate for very specific situations, and it is usually not worth it. Unless you have very large documents (hundreds of KB), it is easier to use projections without using index store or using a transformer.

Upvotes: 3

Related Questions