Materialized properties
Event properties are stored as JSON, so a filter or breakdown on a custom property parses that JSON for every row it scans. A materialized property is a...
Event properties are stored as JSON, so a filter or breakdown on a custom property parses that JSON for every row it scans. A materialized property is a String column on events (mat_<16 hex>) that ClickHouse fills when an event is inserted. The query compiler reads that column instead of the JSON for the project that owns it.
Fifteen properties ($current_url, $pathname, $browser, ...) are always fixed columns. Everything else can be materialized.
What the column holds
The property as text: strings as they are, numbers and booleans as their JSON text (5, true), an absent key as the empty string. This is the same reading the fixed columns use, so filters and numeric aggregates behave the same. Person properties are counted in the usage table but are not materialized.
Settings (Project settings, Materialized properties)
Setting | Default | Meaning |
|---|---|---|
Materialize hot properties automatically | off | The job below creates columns for hot keys |
Reads in 7 days ( | 1000 | A key is hot at this many compiler reads over 7 days |
Most columns ( | 20 | Cap on this project's columns (hard limit 100) |
Nothing happens automatically until you switch it on. Manual materialize and drop work whatever the switch says.
How usage is counted
Each time a query compiles, the keys it reads are counted in memory by lc-api and flushed to Postgres (property_usage, one row per project, key and day) every 30 seconds. Counters older than 30 days are pruned. The counts are a heuristic: a crash loses at most 30 seconds of them.
The job
properties.materialize runs in lc-jobs every 5 minutes. Each tick it:
checks the backfill of columns still being built (
system.mutations) and marks themreadyorfailed;for each project with auto on, creates columns for the hottest unmaterialized keys, up to 5 per tick and up to
max_columnsin total, and writes an audit entry (materialized_property.auto_create, system actor).
Without ClickHouse configured the job only persists counters.
Status
Status | Meaning |
|---|---|
| The column exists and new events fill it. Queries already use it; older parts compute it on read until |
| Existing data is rewritten |
| The backfill mutation failed ( |
API
All under /v1/projects/{id}/materialized-properties (session or key; reads need project read access, changes need settings write access; a project you cannot see answers 404):
GET /list,?limit=&cursor=, ordered by key, withstatus,source(manualorauto) andhits_7dPOST /{ "key": "plan" }materialize now (201; 409 if already done; 400 for fixed columns,calc:/lookup:/meta:/$feature//$lc_keys or a full project)DELETE /{id}stop using the column and drop it (unless another project shares it)GET /candidatesunmaterialized keys at or above the threshold, hottest first (one page of at most 50)GET /settings,PUT /settings{ auto_enabled, threshold, max_columns }
Every change is in the audit log (materialized_property.create, .delete, .settings, .auto_create).
Cost and limits
A column adds storage for every event in the table: two projects reading the same key share one column, and the column is dropped when the last project removes it. Keep max_columns low on small clusters. The backfill is a ClickHouse mutation that rewrites parts, so schedule large manual materializations off-peak. A project removed from Postgres leaves its columns behind; drop them first.