Datakey caches
A datakey cache lets your own orchestrator precompute expensive features into a warehouse table, register that table with FeatureMesh, and have later queries read the stored values instead of recomputing them.
Use a managed FeatureMesh project. Cache rows are registered in the managed registry; the warehouse holds the rows themselves. The local registry refuses CREATE CACHES with CACHE-MANAGED-ONLY. The playgrounds on these pages already run on a managed project. Outside them, set up a managed client with a project access token and a SQL executor connected to the warehouse that holds the tables ( managed mode ).
This page is the model: who does what, the contract a cached value follows, and how to check what the planner did. Then:
| Page | What you do there |
|---|---|
| Tutorial | Build, register, read and rebuild a cache for one date, end to end |
| Ranges of days | Build one day at a time and serve queries over any range of days |
| Deciding what to cache | Pick the features from cache_graph, and the advice that keeps a cache correct |
| Rebuild scripts | Python jobs that rebuild a date and backfill the missing days |
Who does what
FeatureMesh does not schedule or build anything. The work splits in two:
| FeatureMesh | Your orchestrator (Airflow, Dagster, cron, …) |
|---|---|
| Computes the datakey of every feature value a query returns | Decides which features to cache, and for which dates |
Returns cache_graph: the features that query reaches, and how they connect | Counts those hashes across days, and groups features that share a grain into one table |
| Rewrites queries to read a registered cache when that saves work | Writes the cache table, one partition per run |
Shows its decision in EXPLAIN | Registers rows with CREATE CACHES and drops old ones with DROP CACHES |
A datakey identifies what a value means: the feature's logic, the key it is computed for, and the populations it reads, with their parameters. It does not record when the source tables were read. So the partition date must be part of the query, not left to whenever the build happens to run. This tutorial does that with one CONST, named DS.
The contract
These rules say which queries share a datakey, and what a registered cache is allowed to stand in for. The spelling below is what EXPLAIN (FIELDS (DATA_KEYS)) shows in keyset_bindings[].params and const_values.
The type is part of the value. A keyset parameter and a CONST enter the datakey as the SQL literal of their declared type.
| Value | Literal in the datakey |
|---|---|
2 (BIGINT) | 2 |
'2' (VARCHAR) | '2' |
3.5 (DECIMAL) | 3.5 |
DATE '2026-10-07' | CAST('2026-10-07' AS DATE) |
TIMESTAMP '2026-10-07 00:00:00' | CAST('2026-10-07 00:00:00' AS TIMESTAMP) |
a string containing an apostrophe (it's) | 'it''s' |
ARRAY[1, 2] | CAST(CAST([1, 2] AS BIGINT[]) AS BIGINT[]) |
ROW(1, 2) | CAST(ROW({'field_1': 1, 'field_2': 2}['field_1'], {'field_1': 1, 'field_2': 2}['field_2']) AS STRUCT("field_1" BIGINT, "field_2" BIGINT)) |
2 and '2' are two datakeys. An array or a row parameter is a literal, on the same path as a scalar.
EVAL_CONST() is the value it returns. EVAL_CONST(DS AS DATE) with DS := DATE '2026-10-07' contributes the same literal as writing that date, so the two share a datakey. A source that still names the constant, as in ON SELF[ds] = EVAL_CONST(DS AS DATE), keeps that typed literal in const_values. EVAL_CONST(CURRENT_TIMESTAMP()) contributes the timestamp captured for this compilation. A later compilation has another datakey.
The cache column is read as the feature's type. FeatureMesh casts the column to the type declared on the feature. The warehouse type of that column is an assumption: validate states it, with a check you run on the warehouse, and the query still compiles. A DECIMAL column read as BIGINT is cast, so 1.5 becomes 2. A cast that fails fails the query. The same kind of assumption on a mapped table is Data contracts .
A cache leaves the query as it is. A query that fails to compile still fails when a cache is registered. A VARIANT that replaces an external source still fails. A VARIANT or a MACRO is cached from the formula it expands to, so the stored value is that result. Each FEATUREQL(...) island in one SQL statement has its own datakeys: two islands can read the same source, and both stay cacheable.
A registered row is the declaration you wrote. FeatureMesh serves that row as registered. Freshness, completeness and uniqueness of the key are yours to keep. A missing key reads as NULL. A duplicate key repeats rows. Step 6 of the tutorial shows a stale partition and the rebuild.
Understand what the system does
When a query does not read the cache you expect, check these in order:
- Is the value cacheable?
EXPLAIN (FIELDS (DATA_KEYS))on the query. Anulldata_keycomes with areason( step 3 of the tutorial ). - Does a row match? The datakey of the query must equal the registered
DATAKEYexactly. Another date, another keyset, other keyset parameters or anotherNESTEDpopulation each give another datakey. Compare the datakey withSHOW CACHES (COLUMNS (DATAKEY, BACKEND)). For a value withreuseUNION, the days are not in the datakey: each day ofpartition_valuesneeds a row whoseFILTER_VALUEis that day. - Is it the right backend? Only rows for the backend the query runs on are candidates.
- What did the planner decide?
EXPLAIN (FIELDS (CACHE_PLAN))lists every candidate with its decision and saving. With no candidate,skipped_reasonsays why:NO-CACHE-TAG,BACKEND-WITHOUT-CACHES,NOTHING-CACHEABLEorNO-REGISTERED-ROW. - What did the query return?
cache_idsin the output metadata lists every cache row read for that column. An empty list means the column was computed.
CREATE FEATURES, CREATE VIEW (a persisted view stores computed SQL) and prepared statements never read a cache. A FEATUREQL(...) island does, unless it carries /* NO-CACHE */.
Next
Build one in the tutorial .