Expand description
Table and column layout for the PG search backend.
Where a parameter is stored depends on whether it can repeat:
- Singular: a scalar column on its resource type’s table
(
r4_patient_idx). Scalars support ordered comparisons, prefix matches, sorts and composite indexes; arrays only support overlap. - Repeating: one row per value in the shared table for its type
(
r4_param_token_idx, …), keyed by canonical URL. Same indexes, at the cost of a join.
Every table references its resource by res_key, a BIGINT allocated by
the anchor (r4_resource_idx). Only the anchor stores tenant, project, type
and id, which keeps the other indexes small.
Cardinality is precomputed in crate::search_parameter_cardinality.
Anything not known to be singular goes to the shared tables, since a scalar
column would silently drop extra values.
Structs§
- Column
Def - One generated column.
- Resource
Type Schema - One resource type’s table of singular parameters.
- Schema
Registry - Every generated table layout for one FHIR version.
- Shared
Column - A value column of a
SharedTable. Shared by the DDL and the batch insert.
Enums§
- Column
Type - A generated column’s type. Always scalar: repeating values live in rows.
- Index
Kind - How a column is indexed.
- Param
Columns - The columns backing one parameter. Multi-part values keep their parts on the same row, so e.g. a token’s system stays paired with its code.
- Shared
Table - The shared table for one value type, holding repeating parameters.
Constants§
- SHARED_
TABLES - Every shared table, in creation order.
- STRING_
PREFIX_ CHARS - How many leading characters of a string value its prefix B-tree covers.
Functions§
- column_
index - Position of
nameinschema.columns(sorted, so binary search). - column_
names - Every column a parameter occupies, in insert order.
- generate_
schemas - Builds every resource type table from the singular system parameters, plus the anchor’s columns for the resource-level ones.
- resource_
table_ name r4_resource_idx: the anchor, one row per indexed resource.- resource_
type_ to_ table r4_patient_idx: one table per resource type.- shared_
table_ for - The shared table for a parameter type;
Nonefor composite and special. - shared_
table_ kind - The value type a shared table holds.
- shared_
table_ name r4_param_token_idx. Theparam_segment can’t clash with a type table, since no resource type name contains an underscore.- shared_
value_ columns - A shared table’s value columns, after the
res_key, param_identitykeys. The DDL and the inserts both read this list, so they cannot drift. - sql_
type - SQL type for
CREATE TABLE/ADD COLUMN. - string_
prefix_ expr - The indexed expression over a string column. Prefix and exact searches compare it, so the planner can match them to the index.