On this page
- Status: Accepted (2026-10-20). Operator approved the new table and this ADR on 2026-10-20.
- Date: 2026-10-20
- Owners: Platform (tenant dataset plane).
- Related: ADR 0038 D2 (RLS, ACL and backup cohorts of the dataset family), ADR 0040 D4 (materialise at rollup, never at read), ADR 0042 (packs as data), ADR 0044 D5/D6 (binding cache and its invalidation), §82 (brand-partitioned writes), §121 (a runtime writes only what its role is granted).
Context#
agg_org_dataset_period stores one (dim_key, value_key) per cell. A request that filters on one
dimension and groups on another cannot be answered from it; the resolver reports the filter as
ignored. Records carry only period_month, so there is no week or day grain. Dashboards that cross
several dimensions at once (entity x group x item x week, or a day window around a campaign date)
need every dimension of a record in one place.
Decisions#
D1 — One generic table, org_dataset_panel_rows
One row per record of a record dataset whose pack declares a panel block:
| Column | Type | Meaning |
|---|---|---|
id |
uuid | Row identity. |
org_, brand_, dataset_ |
uuid, NOT NULL | Tenancy and owning dataset; org_ and dataset_ cascade. |
period_ |
varchar(7), NOT NULL | YYYY- of the record. |
period_ |
varchar(10), NULL | W1..W5 or YYYY- inside period_; NULL = month grain. CHECK on the shape. |
dims |
jsonb, NOT NULL | dim_, every dimension of the record except the sub-period field. A NULL value is an unresolved source cell. |
measures |
jsonb, NOT NULL | measure_ for the panel's declared measures. A key is absent when the source did not carry it; never a fabricated 0. |
schema_ |
integer | The dataset's schema_ at write time. |
is_ |
boolean | Copied from the record. |
created_ |
timestamptz | One value per rewrite. |
Index: (org_id, brand_id, dataset_id, period_month). No GIN on dims: a reader scans one
(org, brand, dataset) partition, bounded by D3.
measures is jsonb keyed by measure, not an array with a key list on the dataset: the key list
would be a second source of truth that drifts on a pack upgrade, and the reader idiom already in
use (PanelRow.m in @yng/metrics/dataset-panel) is a keyed record.
The table is generic. Possible consumers are the sales tracker (entity x group x item x week), HR (department x grade x location x month), finance (cost centre x account x scenario x month) and Content Intelligence corpora with several facets per row. Nothing in the table, the writer or the projection names a vertical, a dimension or a customer.
D2 — The declaration is pack data: datasets[].panel
A record dataset in a pack may carry a strict block (Zod: datasetPanelSpecSchema,
@yng/metrics/panel-projection; field references checked in
apps/web/src/server/dataset-packs/pack-schema.ts):
{
"readModel": "panel",
"subPeriodField": "week",
"subPeriodKind": "week_of_month",
"roles": { "entity": "shop", "group": "category", "item": "item_id" },
"measures": ["value", "units"],
"chatQuestions": [
{
"id": "top_groups",
"view": "breakdown",
"request": { "by": "category" },
"vi": "...",
"en": "...",
"requires": { "views": ["breakdown"], "dims": ["category"] }
}
]
}
subPeriodFieldnames a declared dimension;subPeriodKindisweek_of_monthorday. Both or neither. Adayvalue must be a calendar date inside the record'speriod_month.rolesmaps free role names to declared dimensions. Readers and chat look a role up; they never hardcode a dimension key. A role may not name the sub-period field.measureslists declared measure fields. Only listed measures are projected.chatQuestionsare suggested questions:viewis a reader view key (the reader owns the closed set and drops a question whose view it does not serve),requestis a partial view request the reader validates,requires.dimsnames roles or declared dimensions.- A derived dataset may not declare a panel.
The block is persisted where the whole pack already is: org_dataset_packs.content. No column
on org_datasets and no config table. The writer reads the block from the org's active pack rows
by dataset_key; two active packs declaring different blocks for one dataset is a refusal (D4).
D3 — Writer: full replace per (org, brand, dataset), in the rollup executor
refreshDatasetPanel (apps/worker/src/processors/dataset-panel-projection.ts) runs after the
cell rollup of every dataset.rollup.refresh and once after a dataset.backfill. In one
runWithRlsContext(org, brand) transaction it deletes the partition and inserts one row per record
with a period_month, built by the pure projectPanelRows. A dataset without a panel block gets
the delete only, so a dropped block leaves no stale projection. The regrain purge deletes the
dataset's panel rows in the same transaction as its records and cells. The same records always
produce the same rows (idempotent).
Row cap: 500,000 records per (org, brand, dataset) (ORG_DATASET_PANEL_ROW_CAP), counted before
the rewrite.
Only yng_worker writes the table (SELECT, INSERT, DELETE); yng_app holds SELECT. The archive
role carries it as portable.
D4 — Refusals are permanent and leave the partition empty
PanelProjectionRefusal is thrown for: more records than the cap (row_cap); a record with two
values for one dimension, a missing sub-period or one of the wrong shape (unprojectable_records);
two active packs with different blocks (conflicting_spec); a stored block that no longer parses
(invalid_spec). The rewrite rolls back, a second statement empties the partition, and
processDatasetJob routes the job to the DLQ on the first attempt. A reader then finds no rows and
abstains instead of serving a projection older than the records.
D5 — Read-time aggregation is a recorded exception to ADR 0040 D4
A panel reader groups and filters org_dataset_panel_rows at read time inside RLS. This is the
one exception to "materialise at rollup, never at read", bounded by:
- one
(org, brand, dataset)partition per read, capped by D3; - formulas stay server-side in
@yng/metrics/dataset-panel*; no formula in SQL or in the client; - the reader applies the compensation gate (
datasetMeasureReadDecision) to every measure key it returns, exactly as the cell resolver does; - one projection read per filter state, cached by the binding cache (ADR 0044 D5) under
(org, brand, datasetVersion, filterHash)plus the viewer leg.datasetVersioncombines the dataset'sschema_versionand the partition'screated_at, so a rewrite changes the key.
agg_org_dataset_period stays the read path for every non-panel binding.
Consequences#
- A refresh rewrites the whole partition, not only the refreshed periods. At the cap this is one transaction of up to 500,000 inserts; a dataset that needs more uses a narrower grain or a second dataset.
- The panel reader and its widgets, the loader that installs a panel pack, and the chat catalogue
that serves
chatQuestionsare separate changes that build on this table.