Deciding what to cache
FeatureMesh does not pick the features. cache_graph is the fact your orchestrator counts.
The graph is {"layers": [ … ]}. A node's parents are in an earlier layer. Each node has:
| Field | Meaning |
|---|---|
id | The semantic hash (sh1:…) of the feature. A const node uses the constant's name, such as DS. The hash of a constant is the value, and the value is the date, so the name is what stays put from one day to the next. |
step | const, key, keyset, source, projection, relate, aggregate or window |
function | The feature's function, such as RELATED or MULTIPLY |
names | The feature names that share this hash |
parents | The direct parents, each one an id. An aggregate lists the inputs it collapses. Those parents are not its grain. |
key_input | The grain, taken from the datakey: the input name, its type, and its keyset. Empty when reason is set. |
returned | True when the node is a column of this RETURN |
reason | Empty when the node has a datakey. Otherwise the same code as in the table of step 3 of the tutorial (INPUT-NOT-BOUND-TO-KEYSET, CONSTANT, …). Skip those nodes. |
SHOW has no graph. The graph is ready as soon as the query compiles, including when the warehouse then fails to run the SQL.
To choose:
- Drop every node whose
reasonis set, and dropconst,keyandkeyset. Those name the grain. - Count how often each remaining
idshows up across queries and days. The hash is stable. The datakey of that hash changes with the date. A hash you recompute every day is a candidate. - Keep
aggregateandwindow. The rollup or the frame is the expensive part, even when the inputs are already stored. Keep arelatethat looks up a plain value:ORDER_COUNTRYis keyed byORDER_ID, andCUSTOMER_IDstaysINPUT-NOT-BOUND-TO-KEYSET. A lookup of an aggregate is different.ORDER_COUNTRY.RELATED(COUNTRY_REVENUE)still hasCOUNTRYas a free input, so it has no datakey:INPUT-NOT-BOUND-TO-KEYSETwhen only orders are bound, andMULTIPLE-KEY-AXESwhenCOUNTRYis bound as well.NESTED COUNTRYis refused. The query runs; that column is not a cache candidate. - Drop a
projectiononce its parent is cached.COUNTRY_REVENUE * 10is one column expression on top ofCOUNTRY_REVENUE. A column read off a source (stepprojection, parent asource) is the same case the planner already refuses: one join either way. - Group what you kept by
key_input, the samenameand the samekeyset. That is the key column of the cache table.COUNTRY_REVENUEandCOUNTRY_ORDERSboth nameCOUNTRYviaKS_COUNTRIES, so they share a table, even though both also readORDER_ID. A country-level count of customers has that samekey_inputand belongs in the same table.ORDER_COUNTRYnamesORDER_IDand belongs in another.
Then register one CREATE CACHES row per column, using that column's datakey for the partition you built.
cache_reads on the same response lists the cache rows this query actually read. An empty list means nothing was served from a cache.
Advice
- Put the partition date in the query. Pass one
CONSTto the keyset parameters and to theONclause of the sources, so the datakey changes with it. A cache built without it is a snapshot that FeatureMesh will serve for every later query, because it trusts the registration. - Partition the keysets that dashboards read over ranges.
WHERE ds = :dswithPARTITION BY, bound to a set of days, and a key that carries its day (DAY, an order,ROW(country, day)). Then one daily build serves every range ( Ranges of days ). - Backfill from the responses.
cache_missing_partitionsnames the days to build, per feature. - Read dimensions at the partition date, not their latest state. A lookup on the latest partition of a dimension gives a different answer once the dimension is updated, under the same datakey.
- Always build with
/* NO-CACHE */inside the island. A build that reads its own cache copies old values, orNULLafter aDELETE. - Rebuild a partition when its source changes. The datakey covers the populations and the dates, not the rows in the source tables. If late orders land in a partition already built, rebuild it. Its rows keep the same datakeys and the same ids.
- Cache aggregates and joins, not plain columns. A column read from a source table costs one join either way, so it is never served from a cache (
NO-SAVING). - Group features by key and partition. Everything keyed by
countryfor the samedsbelongs in one table: one join serves all of it. - Keep the build and the registration in one job. Register only after the
INSERTsucceeded. - Write one row per key. The cache table declares the grain of its key. A duplicate key fans out. See the mental model , section 12.
- Register one row per datakey. A second table or partition registered for the same datakey by mistake is a candidate too, and only one of them is read.
On this page