B-Tree Based JSON Indexes
Single-value JSON indexes and multivalue JSON indexes are value indexes implemented with B-tree structures. The terms single-value and multivalue describe how many indexed scalar values a document can contribute; B-tree describes the index implementation. These are not competing index families.
Use a single-value JSON index when a path returns at most one scalar value per document. Use a multivalue JSON index when a path can return multiple values per document, typically from arrays or repeated fields. Both are intended for known, stable SQL/JSON path expressions, and the query path and data type must match the index definition.
In all cases, the optimizer can use the index only when the query uses a matching path expression and a matching SQL data type.
The main B-tree-based value index types are:
- Single-value JSON index for a single scalar value.
- Multivalue JSON index for multiple scalar values per document.
- Composite B-tree index for multiple fields in one key.
Note: Bitmap indexes are a separate index type. You can create them for json_value, but they are not B-tree indexes and are discussed separately.
Database Operations Accelerated by B-Tree Indexes
B-tree value indexes on JSON data, including single-value and multivalue JSON indexes, can improve performance for a broad range of database operations. Understanding which operations benefit from these indexes enables more effective query design and indexing strategies.
JSON B-tree indexes enhance performance for these categories of database operations:
-
Data Retrieval Operations:
- Document retrieval using
WHEREclauses with JSON path predicates, including filter expressions. - Selective document counting based on JSON path predicates.
- Full collection document-counting operations.
- Document retrieval using
-
Data Organization Operations:
- Result-set grouping based on JSON path expressions.
- Result-set ordering, or sorting, based on JSON path expressions.
- Join operations between documents on fields selected by JSON path expressions.
-
Structured Query Operations:
JSON_TABLEoperations with column predicates that match indexed paths.