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:

FieldMeaning
idThe 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.
stepconst, key, keyset, source, projection, relate, aggregate or window
functionThe feature's function, such as RELATED or MULTIPLY
namesThe feature names that share this hash
parentsThe direct parents, each one an id. An aggregate lists the inputs it collapses. Those parents are not its grain.
key_inputThe grain, taken from the datakey: the input name, its type, and its keyset. Empty when reason is set.
returnedTrue when the node is a column of this RETURN
reasonEmpty 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:

  1. Drop every node whose reason is set, and drop const, key and keyset. Those name the grain.
  2. Count how often each remaining id shows 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.
  3. Keep aggregate and window. The rollup or the frame is the expensive part, even when the inputs are already stored. Keep a relate that looks up a plain value: ORDER_COUNTRY is keyed by ORDER_ID, and CUSTOMER_ID stays INPUT-NOT-BOUND-TO-KEYSET. A lookup of an aggregate is different. ORDER_COUNTRY.RELATED(COUNTRY_REVENUE) still has COUNTRY as a free input, so it has no datakey: INPUT-NOT-BOUND-TO-KEYSET when only orders are bound, and MULTIPLE-KEY-AXES when COUNTRY is bound as well. NESTED COUNTRY is refused. The query runs; that column is not a cache candidate.
  4. Drop a projection once its parent is cached. COUNTRY_REVENUE * 10 is one column expression on top of COUNTRY_REVENUE. A column read off a source (step projection, parent a source) is the same case the planner already refuses: one join either way.
  5. Group what you kept by key_input, the same name and the same keyset. That is the key column of the cache table. COUNTRY_REVENUE and COUNTRY_ORDERS both name COUNTRY via KS_COUNTRIES, so they share a table, even though both also read ORDER_ID. A country-level count of customers has that same key_input and belongs in the same table. ORDER_COUNTRY names ORDER_ID and 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 CONST to the keyset parameters and to the ON clause 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 = :ds with PARTITION 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_partitions names 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, or NULL after a DELETE.
  • 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 country for the same ds belongs in one table: one join serves all of it.
  • Keep the build and the registration in one job. Register only after the INSERT succeeded.
  • 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.