When a Covering Index Is a Lie for FHIR JSON Queries

Editorial illustration in terrazzo-texture style depicting a terrazzo index-coverage matrix with warm-red full and terracotta partial cells

A covering index is supposed to answer a query without touching the underlying table. The index carries every column the query needs, the seek returns the answer, and the latency is minimal. That is the promise. FHIR JSON queries often break the promise because the index carries the shape of the resource but not always the values inside the JSONB payload.

Naming the gap is the discipline. For related walkthroughs, the FHIR learning path collects the surrounding material.

The Traditional Covering Index

A traditional covering index over a search parameter carries the search parameter's value plus the resource ID. The seek walks the index, returns the matching resource IDs, and the query is done in one step.

For simple search parameters like Patient.identifier, the covering index works exactly as advertised. Fast, bounded, predictable. A pass through the site's search-query p99 lookup surfaces the tail figure for these well-behaved parameters.

Where JSONB Breaks the Covering Promise

FHIR servers that store resources as JSONB carry a subtle trap. Search parameter values are extracted from the JSONB at index-build time, but complex parameters like CodeableConcept combinations may not be fully indexable. The engine indexes what it can and falls back to a JSONB scan for the rest.

The plan may still describe the index as "covering," but the fall-back scan happens transparently. Reading the plan carefully surfaces the gap. For the reading habit, reading a FHIR search plan the way you read a SQL EXPLAIN covers the method.

Modifiers Break the Coverage

Modifiers like :exact, :contains, :above, :below, and :not change the query semantics in ways the covering index cannot always support. :contains on a string parameter forces a linear scan across every indexed value; the covering index cannot skip the scan.

Every modifier should be measured for its coverage. Modifiers that fall through to scans need a separate design conversation before they land in a hot path.

Composite Search Parameters

Composite search parameters combine multiple fields into a single index. Observation.code-value-quantity is a composite over the code, the value, and the quantity. Covering indexes for composites work when all three fields are queried together; they degrade when only one is queried.

The disciplined pattern is to name which composites cover which queries and to avoid partial-composite queries in hot paths. For the wider design framing, search parameter design that stays fast at 10x traffic covers the approach.

The Statistics Interaction

Query planners choose the covering index based on statistics. When statistics drift, the planner might reject the index in favor of a scan it thinks will be faster. On the wrong data distribution, the scan is dramatically slower. For the variance framing, why the same FHIR search runs fast on Tuesday and slow on Friday covers the mechanism.

Testing the Coverage Claim

The reliable test for whether an index truly covers a query is to run the query with a plan trace and compare the index seek row count against the actual result row count. When they match, the coverage holds. When the seek row count is orders of magnitude larger than the result, the index is filtering after the seek, and the coverage is partial.

The Design Implication

Every hot-path FHIR search should carry a documented coverage claim: which index covers it, which fields are indexed, which modifiers are compatible. Claims that never get validated become false claims quietly. Every FHIR deployment that lands well tests the claims explicitly.

Terrazzo-texture diagram of a covering-index matrix with confetti chips marking full coverage in warm red and partial-coverage cells in muted terracotta on a creamy binder background

Sources