Skip to main content

Module schema

Module schema 

Source
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§

ColumnDef
One generated column.
ResourceTypeSchema
One resource type’s table of singular parameters.
SchemaRegistry
Every generated table layout for one FHIR version.
SharedColumn
A value column of a SharedTable. Shared by the DDL and the batch insert.

Enums§

ColumnType
A generated column’s type. Always scalar: repeating values live in rows.
IndexKind
How a column is indexed.
ParamColumns
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.
SharedTable
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 name in schema.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; None for composite and special.
shared_table_kind
The value type a shared table holds.
shared_table_name
r4_param_token_idx. The param_ 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_identity keys. 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.