Part 3 of 5 · 2 min read
Partitioning by document versus by term
By document keeps each partition self-contained but needs every partition checked per query; by term checks one partition but needs a scattered write per row.
Think of two ways a library could maintain a subject card catalog. In the first, each branch keeps its own local card catalog covering only its own books. In the second, one shared card catalog lists every matching book across every branch under each subject.
In plain words: partitioning a secondary index by document, also called a local index, keeps each partition's secondary index covering only the rows stored on that same partition, so writing a row only ever touches one partition, but answering a secondary-index query means checking every partition and combining the results. Partitioning a secondary index by term, also called a global index, instead partitions the index itself by the indexed value, so a query for a specific value touches only the partitions covering that value, but writing a single row may need to update a secondary-index partition different from the one holding the row itself.
A worked example. An index on order date, partitioned by document, lives split across every customer-partition, each covering only that partition's own orders; a "March 1st" query must check all of them. The same index partitioned by term groups all March 1st entries together on one or a few index partitions, regardless of which customer-partition the actual order rows live on, so the query touches far fewer partitions but writing one order now also means updating a separate date-indexed partition.
The key lines. No new SQL; whether a secondary index is local or global is a storage-layer configuration a distributed database applies per index, not something expressed per query.
Document-partitioned index, term-partitioned index
A document-partitioned index, or local index, covers only the rows on its own partition, making writes cheap but queries expensive. A term-partitioned index, or global index, partitions by the indexed value itself, making queries cheap but writes potentially more expensive.
Example: each branch keeping its own local subject catalog is document-partitioned; one shared catalog listing every branch's matching books under each subject is term-partitioned.