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...

Embed
Preview of the card
<a href="https://lucidace.com/help/materialized-properties"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/5630f124-d2f9-44ac-abea-4dc4e5130ae0/social-card.svg?v=3e7ae33eec8b" alt="Materialized properties" width="600" height="315"></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 (threshold)

1000

A key is hot at this many compiler reads over 7 days

Most columns (max_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:

  1. checks the backfill of columns still being built (system.mutations) and marks them ready or failed;

  2. for each project with auto on, creates columns for the hottest unmaterialized keys, up to 5 per tick and up to max_columns in total, and writes an audit entry (materialized_property.auto_create, system actor).

Without ClickHouse configured the job only persists counters.

Status

Status

Meaning

backfilling

The column exists and new events fill it. Queries already use it; older parts compute it on read until MATERIALIZE COLUMN finishes, so results are correct throughout

ready

Existing data is rewritten

failed

The backfill mutation failed (error says why). Drop the column and create it again

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, with status, source (manual or auto) and hits_7d

  • POST / { "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 /candidates unmaterialized 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.

Updated