简体   繁体   中英

How does nesting structures affect DocumentDB query performance?

The question might otherwise be stated as "to flatten or not to flatten?"

If I were to store nested JSON documents in a DocumentDB collection, would querying across those nested structures perform on par with having stored those nested structures in a separate collection as flat documents on their own?

The data in question will be written once and (likely) never updated. Reporting performance is at the top of the requirements list.

On one hand, storing the data in a nested structure seems like the "correct" way to make use of the no-schema / no SQL technology. That is, we naturally want to associate header data with detail data all in one place and in context. But can it scale and continue to perform once we're writing thousands of rows a minute while simultaneously running reports on that collection from a web application?

Or, would it be better to flatten out that detail data, redundantly storing relevant parts of the header data in each row of the detail collection? As a long-time RDBMS developer / user, I tend to want to not store data redundantly, but should I let go of that idea in favor of high performance?

Does a flat data structure query more efficiently in DocumentDB and by how much of a margin? That is, what am I giving up by doing that, and is it worth it if performance is a top (but not the only) priority?

There isn't a single "correct" answer to this.

Choosing whether to represent relationships as a single embedded document (aka de-normalizing) or as references as you would in a RDBMS (aka normalizing) depends highly on your use-case / scenario.

Typically you will want to de-normalize for read-heavy scenarios and normalize for write-heavy scenarios.

The DocumentDB team just published a reference document on this; I'd recommend giving it a read: http://azure.microsoft.com/en-us/documentation/articles/documentdb-modeling-data/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM