Configure Pocket Tables

The Minimum served hits to retain a pocket model setting is separate from minimum source-query demand. Its default is 3 successful pocket-served user queries in 24 hours; reaching it protects a pocket from idle eviction. Automatic replacement at the model limit also considers recent served usage.
What this covers
A pocket table is a cached, filtered slice of a model — not free SQL over the model's tables. The Query Router redirects matching reads to the pocket instead of running them against the source. This article covers the model-subset contract, how to author the defining SQL, validate it, measure it with a dry-run, schedule refreshes, handle drift when the model changes, and understand when the Router will and will not use a pocket.
When to use a pocket table
Use a pocket table when a narrow filter on a large source table is scanned repeatedly, and the result set is small enough to cache. Aggregates cover rolled-up summaries; pocket tables cover row-level slices. Pockets may use a separate connected query target. The Router tries an aggregate first, then a suitable pocket, then the source.
Select a fact group
In the Query tab, choose Fact group when the model has independent facts, for example sales and balances. SELECT * FROM model then copies the chosen group's rows and fields. Whole model requires one compatible row surface; it cannot combine independent facts into one row set. The choice also applies to validation and dry-run sizing. Changing it makes the pocket stale until it is rebuilt. An unavailable or undeployed group is refused.
The router applies the calling user's persona, column security and row security on every read. A pocket for sales cannot answer a balances question. Automatic suggestions retain their fact group, and planning never merges their row counts with another group.
Pocket identity
A pocket is identified by its model, optional fact group and persona, query shape and predicates:
| Part | Meaning |
|---|---|
model_id | The model the pocket belongs to. |
fact_group_id | The selected fact group, or no group for the whole model. |
persona_id | Optional workload affinity; every read still applies the calling user's security. |
query_fingerprint | A stable hash of the defining SQL's shape (projection, measures, grain). |
predicate_set_hash | A stable hash of the sorted canonical form of the pocket's predicates (column, operator, value). |
Two pockets on the same model with the same query shape but different filter values are distinct rows. An attempt to create a second pocket with the same identity returns HTTP 409 and no row is inserted — the existing pocket is left alone. The automated optimiser follows the same rule silently, so duplicate candidates do not pile up errors.
A pocket saves the complete matching slice. Row limits such as LIMIT 0 or LIMIT 10 are rejected when you create a pocket or edit its SQL. The same rule applies when you validate or dry-run the SQL, and at refresh: a stored pocket whose SQL carries a row limit fails its refresh and is not served. The word LIMIT inside a filter value or a quoted field name is ordinary data and does not impose a row limit.
OFFSET and SELECT DISTINCT are rejected the same way. OFFSET 10 skips rows, and SELECT DISTINCT * drops rows that repeat exactly, for example two identical sales on the same day. Either would cache fewer rows than the model holds, so a count or total answered from the pocket would differ from the same query answered from the source. To cache a smaller slice, narrow it with WHERE.
A pocket may hold at most pocket.max_rows rows (default 5,000). When you create a pocket or edit its SQL, Tessallite counts the rows the SQL selects and refuses the pocket if the count is above the limit, with the count and the limit in the message (POCKET_TOO_LARGE). If the rows cannot be counted, for example because row-level security hides every row from your account, the pocket is refused too (POCKET_SIZE_UNKNOWN). Pockets created before this rule are kept; a refresh that finds more rows than the limit still evicts the copy and marks the pocket failed. Example: WHERE auth_method_name = 'Biometric' selects 11,823 rows and is refused; WHERE auth_method_name = 'Biometric' AND payment_status_name = 'Cancelled' selects 1,764 rows and is accepted.
Pocket creation and definition edits are refused with POCKET_IDP_SUBJECT_UNAVAILABLE when the creator's row security depends on IdP groups or claims. Scheduled refresh cannot obtain the creator's current IdP subject. Role-based row security remains supported. A pocket without a human creator uses the technical persona; the same refusal applies only if that persona's own row security needs IdP attributes. If rules change after creation, refresh fails with the same reason and the pocket is not served.
An edit to a pocket definition is checked against the pocket's stored creator before it is saved.
The pocket's source table list is not a stored field. It is parsed from the defining SQL each time it is needed, so the SQL is the single source of truth.
Automatic pocket planning
The optimiser counts eligible successful source queries inside the configured
optimizer window (ai_scheduler.lookback_hours). Served accelerator hits remain
usage. Old cumulative counts do not become current demand.
Pockets have no ROI score. A candidate must cover pocket.min_demand source
queries (default 3), and its measured raw slice must fit pocket.max_rows
(default 5,000). Candidates rank by covered demand, then fewer rows. Unknown
size is reported as SIZE_UNAVAILABLE.
The optimiser combines low-cardinality values into IN lists and relaxes
high-cardinality filters, so it avoids one pocket per customer or order number.
It measures the entire widened slice, including any extra combinations. Queries
retain their own filters when they use that copy. A model within the row limit
gets a whole-model copy. For larger models, pocket.max_model_share (default
0.5) also limits the copied fraction.
The model limit, pocket.max_per_model, defaults to 50. Manual and unclassified
pockets count toward it and remain protected. Automatic pockets may be replaced
only after a usable replacement is built; at the cap it must cover more demand.
Editing an automatic pocket or its schedule makes it manual. Receipts never
determine replacement eligibility.
Set the independent Pocket query target in the model's Settings → Pocket tables, or inherit the model query target. New manual pockets start with that default and let you choose another model-owned target. BigQuery sources can be copied to connected PostgreSQL storage through the existing streaming refresh. The source and storing connection must still pass the measured behaviour gates for each query. A full copy reads the selected source rows again at every full refresh, which can incur BigQuery scan charges; choose the schedule accordingly.
Diagnostics → Optimisation → Evaluate pocket demand reports accepted plans,
merging/relaxation, and reasons such as SUBSUMED, TOO_LARGE, TOO_SPARSE or
MODEL_CAP. Candidate evaluation retains its administrator permission check.
Automatic creation remains off until Auto-create pocket tables is enabled.
Pocket table properties
When importing a project, a pocket must have a positive number of days to keep its data. An enabled refresh schedule must have a valid schedule expression. An error names the pocket and the setting to repair; fix it and retry the import. Missing optional settings in an older export keep their usual defaults.
| Property | Description |
|---|---|
| Fact group | Optional group whose complete row surface is copied. Leave Whole model only when all fields belong together. |
| Target | The data target where the pocket is stored. A model-owned target is required; the default is the configured pocket target, then the model target. |
| Defining SQL | A model-subset SELECT of the form SELECT * FROM <model_slug> [WHERE ...] [ORDER BY ...]. No trailing semicolon. |
| Schedule | Cron expression controlling when the Scheduler rebuilds the pocket. |
| Schedule enabled | When off, no automatic refreshes run. Manual refresh still works. |
The default refresh strategy is full refresh — the pocket is rebuilt from scratch on each run. Optional incremental mode is considered when incremental_column is set, but it is used only when the shared refresh driver can prove complete watermark coverage for every table in the captured deployed model snapshot. Under the current single-column contract, that proof exists only for a one-table snapshot; a multi-table pocket always takes the full-refresh path (Bug-8745).
Choose a date or timestamp column from this model for the incremental column. Saving rejects unknown columns, columns from another model, and other data types. An explicitly named hidden date column is allowed. This check does not guarantee an incremental run; the refresh still checks the cached output and may safely rebuild in full.
Incremental refresh re-reads only the rows whose incremental column changed since the last successful refresh and replaces those rows in the cache. It also checks which rows the source still produces at all, so a row that was deleted at the source — or that stopped matching the pocket's WHERE clause — is removed from the cache too. The one thing it still cannot see is an update that leaves the incremental column unchanged: if your source edits a row without touching its updated_at, that edit is invisible to every incremental run. Choose an incremental column your source genuinely bumps on every change.
Three things have to be true before an incremental top-up is even attempted, and if any is missing the pocket is simply rebuilt in full instead. You do not have to do anything; it is automatic, and a full rebuild is always correct. The Recent rebuilds table shows the mode actually applied (Full or Incremental), so an incremental setting that safely falls back because a fact key is hidden is visible rather than silent.
- The pocket must expose a row key. To replace a row, the refresh has to be able to find the copy already in the cache. It uses the primary key you declared on the model's fact table — but only if that column is actually visible in the pocket's columns. If the key column is hidden in the model, or the pocket exposes renamed business columns instead of the physical ones, there is no way to tell one cached row from another and the whole table is rebuilt. (Most models hide their fact key, so a full rebuild every run is the normal, expected behaviour.)
- The pocket must have refreshed successfully at least once before. The window to re-read is measured from the previous successful run, not from the current time, so a pocket with no previous success has nothing to measure from.
- The deployed model snapshot must have complete watermark coverage. A pocket over one model table can be covered by its single
incremental_column. A pocket over multiple joined tables cannot be proven fresh with that one column, because a dimension or lookup edit can change the joined value without moving the fact watermark. Tessallite therefore refuses the incremental leg and runs a full refresh (Bug-8745); it never silently serves the stale joined value as fresh.
Measuring the window from the last successful run is what makes a top-up safe after an outage. If the Scheduler was paused for a week, the next run re-reads a week's worth of changes, not just the last few hours — nothing that changed while it was away is skipped. The look-back hours you set are an extra cushion on top of that, for data that arrives at the source slightly late. Store a naive timestamp watermark as UTC; Tessallite evaluates that window against the source's UTC clock even when the source session uses an ahead-of-UTC timezone. Offset-aware timestamps keep their instant semantics.
Before every top-up, Tessallite checks one thing about your source: for every row the source has right now, does the cache already hold that row unchanged, or is the row inside the window we are about to re-read? If the answer is no for even one row, it quietly rebuilds the whole pocket instead of patching. You see a slower run; you do not see a wrong number.
That check is what catches the awkward cases a "recently changed" window cannot: a row that only starts matching because a table it joins to was loaded later, and a correction file that restates an existing row but stamps it with an old business date. Both are invisible to the window itself, and both are caught.
The current-key scan, changed-row scan, and patch share one repeatable-read source snapshot. A row inserted or deleted while the refresh is running therefore cannot appear in only one of the two scans.
Three honest limits remain, so you know what a top-up does and does not promise:
- If your source changes a row without changing its incremental column, nothing can see it. That is not a Tessallite limitation — no incremental refresh anywhere can detect a change its own change-marker did not record, and the check above cannot either, because the row still looks unchanged. The same applies to a row whose incremental column is empty: there is nothing to compare, so the row is treated as unchanged. Pick a column your source genuinely fills in and updates on every write.
- A multi-table pocket is always rebuilt in full under the current product contract. This is deliberate: with one
incremental_column, Tessallite cannot prove that every joined table's changes are covered. If a fact total was cached as 500 and a joined FX-rate edit makes source truth 700 without moving the fact watermark, the next refresh uses full CTAS so the pocket cannot report 500 as fresh. Complete per-table watermark metadata would be required before a future product change could safely allow joined incremental refreshes (Bug-8745). - If a top-up runs while your source is halfway through a bulk reload, it can briefly disagree with the source. Tessallite detects that on the very next run and repairs it then, so the disagreement lasts one refresh cycle rather than persisting. If your loads are large and non-atomic, schedule pocket refreshes outside the load window.
One thing to keep in mind about speed: a top-up still reads the source twice (once for the changed rows, once to check which rows still exist). What it saves is the writing, not the reading. Do not expect it to be dramatically faster than a full rebuild on a small pocket.
One exception is automatic, and you do not have to think about it. If the model has been deployed or reverted since the pocket was last built, or the pocket is currently marked stale or failed, the very next refresh is always a full rebuild even when an incremental column is set. The reason is worth understanding: a top-up only re-reads the recent window, so every older row in the cache would still hold numbers calculated from the previous version of the model. You would end up with one table holding two different definitions of the same measure, and nothing on screen would tell you. Rebuilding the whole table is slower for that one run, and it is the only way to guarantee every row in the cache means the same thing. After that run, incremental top-ups resume only for an eligible single-table model with proven coverage.
Refresh trigger: schedule or source change
Each pocket refreshes one of two ways, chosen by the Refresh trigger setting in the pocket drawer:
- On a schedule — the pocket rebuilds on the cron schedule you set, just like an aggregate. Use this when the source updates on a predictable rhythm.
- On source change — the pocket rebuilds automatically whenever the source schema for this model changes, with no cron schedule at all. Use this when structural changes to the source are the thing you actually need to keep up with, and you would rather not guess a cadence. (The daily drift sweep is what detects the change and fires the rebuild, so a source-change refresh happens shortly after the change is noticed, not the instant it occurs.)
Older than model data
A pocket table whose last refresh is earlier than the model's Data refreshed date shows Older than model data next to its refresh time. It still serves; its rows reflect an older read of the source than the rest of the model. Refresh it, or align its schedule, when reports must agree. See Model details.
When a pocket stops earning its keep
A pocket that has been refreshed but that no query has matched since its last refresh is flagged with a "No matches since refresh" badge, and the panel raises a model-level alert counting how many pockets are in that state, along with the most common reason queries skipped them over the last seven days. A fresh pocket nothing routes to is pure cost — storage and refresh work for no benefit. Treat the badge as a prompt to re-scope the pocket's defining SQL so it matches the queries people actually run, or to retire it.
A pocket for North and South can answer a query for North and South, or just North. It cannot answer North and East, or all regions; those queries use the source. A total (SUM), average (AVG) and highest value (MAX) can use the same values stored in the pocket. Each person still gets only their allowed fields and the rows their required filters permit.
The model-subset contract
A pocket is a horizontal slice of its model, expanded to physical SQL at refresh time by the same join expansion path the gateway uses for ad-hoc model queries. The defining SQL must therefore stay inside a small, predictable shape:
SELECT * FROM <model_slug> [WHERE ...] [ORDER BY ...]
The following are rejected at create / validate / refresh time and reported as a structured violation list (each with a code, a message and a one-line suggestion):
| Code | What it means |
|---|---|
FROM_NOT_MODEL | FROM references a physical table or unknown name instead of the model slug. |
MULTIPLE_FROM_TABLES | More than one table in FROM. |
JOIN_NOT_ALLOWED | A JOIN was used. Pockets cache the model's join output, not their own. |
GROUP_BY_NOT_ALLOWED / HAVING_NOT_ALLOWED / DISTINCT_NOT_ALLOWED | Aggregation keywords. Use an aggregate, not a pocket. |
AGGREGATE_NOT_ALLOWED / WINDOW_NOT_ALLOWED | SUM/COUNT/AVG/etc. or window functions. |
SUBQUERY_NOT_ALLOWED / SET_OP_NOT_ALLOWED / CTE_NOT_ALLOWED | Subqueries, UNION/INTERSECT/EXCEPT, or WITH clauses. |
SELECT_MUST_BE_STAR | An explicit projection list. Pockets must SELECT * so the matcher can serve any sub-projection. |
WHERE_UNKNOWN_COLUMN / ORDER_BY_UNKNOWN_COLUMN | A column reference that does not resolve to a model dimension or measure. |
EMPTY_SQL / PARSE_ERROR / NOT_SELECT / MODEL_MISSING | Trivial shape failures. |
Filtering a pocket on a measure
The WHERE clause may compare a measure, for example SELECT * FROM inventory WHERE line_total > 10000. The condition is applied to each row's own value of the measure, before anything is added up. It keeps the rows whose line total is above 10,000; it does not keep groups whose total is above 10,000. The dry-run row count and the size check use the same rows.
Only a measure that has a value on a single row can filter rows. These are refused, with a message that names the measure:
- a counting measure (count or distinct count): one row has no count;
- a calculated or composite measure, a time variant, and a semi-additive measure.
Filter on a dimension instead, or use an aggregate with a grouped query when the condition is about totals.
Worked example: a pocket of large inventory lines. SELECT * FROM inventory WHERE line_total > 10000 holds every inventory row above 10,000. If that is more rows than the pocket row limit (pocket.max_rows, 5,000 by default), create and edit refuse it with POCKET_TOO_LARGE. Narrow the slice, for example by adding a region or a date range.
Authoring workflow
- Open the model in Model Builder.
- Click Pocket Tables in the Toolbelt.
- Click New Pocket. The drawer opens on the Query tab.
- Pick a Target and type the Defining SQL into the editor. No separate source-table input is needed — the source is read from the SQL.
- Click Validate. The service parses the SQL and checks the model-subset contract. The result banner reports the stage (
parseorsubset) and, on failure, lists the violation codes and suggestions. - Click Dry run to execute
COUNT(*)against the defining SQL. The banner shows row count and elapsed milliseconds. Dry run requires a target connection; the statement timeout is capped by the system settinggateway.router_client_timeout_xlong. - Switch to the Schedule tab. Turn the Schedule enabled switch on, pick a cron expression with the picker, and review the recent run history.
- Click Save. This saves the pocket and its schedule, and starts filling the pocket with data straight away. You do not need to press anything else. Keep the Pocket Tables list open: it updates by itself and shows Fresh when the pocket is ready, or Failed with the reason if something went wrong. After this first fill, the pocket is refreshed by its schedule. If a pocket with the same identity already exists, the drawer surfaces an error banner and no duplicate is created.
Closing the drawer with the X, Cancel, or a click outside after you have edited the target, SQL, cron, or enabled switch prompts for confirmation before discarding your changes.
When the checker cannot be reached
Every one of those steps — Validate, Dry run, and Save — asks the query service to read your SQL first. If that service is briefly unavailable (it is being upgraded, or the network hiccups), Tessallite will not guess. It stops and shows:
The query validator could not be reached, so your SQL could not be checked. It has not been rejected. Try again in a moment.
Read that message carefully, because it is saying something different from a normal failure:
- "Not checked" is not the same as "wrong". Your SQL has not been judged at all. Nothing is wrong with it as far as anyone knows.
- Nothing was saved. The pocket was not created and the old one was not changed.
- The fix is to wait and click again. These outages are usually seconds long. If it keeps happening for more than a few minutes, tell your administrator — the query service is down, not your model.
Why does Tessallite refuse instead of just saving it? Because a pocket table is a stored copy of some of your data, and the check is what proves the copy really matches the model. If Tessallite saved an unchecked pocket, the mistake would not appear now — it would appear later, as a report quietly showing the wrong numbers, with nothing on screen to say anything went wrong. A message you can see and retry is much cheaper than a wrong number nobody notices. This is the same reason Tessallite will not save an unchecked scratchpad measure.
A message that names an actual problem in your SQL — a misspelled column, a table that is not part of the model — is the other case entirely. That one is a real verdict, and re-clicking will not change it; fix the SQL.
Edit mode
Editing an existing pocket is scoped to scheduling. The target and defining SQL are read-only after creation — delete and recreate the pocket if the SQL needs to change. The drawer exposes a Refresh now button in the header to trigger an immediate full rebuild without waiting for the scheduled window. The header also carries an Expand panel button (double arrow, next to the close button) that widens the drawer to the full window; click it again to retract.
Drift handling
When the underlying model changes — a referenced dimension is removed, the slug is renamed, a JOIN is taken out — the next refresh re-runs the model-subset validator before touching the target. If the pocket no longer fits the model, it is flagged status='failed' with a failure_reason carrying the structured violation list. Failed pockets are no longer routed to. Once the model is fixed, the next refresh retries the pocket and rebuilds the materialised table. No manual intervention is required.
Each refresh runs under the creator's current persona, so its column access, row security and default filters determine which rows enter the stored table. A pocket without a human creator uses the technical persona. If the creator account is deleted or disabled, refresh fails and names the reason for an administrator. If the creator loses access to a column the pocket uses, the pocket is retired and its stored table is scheduled for removal.
If the query validator is temporarily unavailable during a refresh, the pocket stays Stale and is not used for queries. The failed run explains that validation was unavailable and can be retried when the service returns. This does not mean the SQL was rejected.
The Pocket Tables list shows the failed status alongside stale so you can see drifted pockets at a glance and either fix the model or delete the pocket. A pocket can also fail because it got too big. A model (or its project) can have a storage budget: the most space all its pockets may use together. Every time a pocket is refreshed, Tessallite checks the new size. If the pockets together would now use more than the budget, the new copy is thrown away and the pocket shows Failed, with the sizes in the reason. To fix it, make the pocket's SQL pick fewer rows, delete a pocket you no longer need, or ask an administrator to raise the budget.
If a pocket's storage connection changes during creation, cleanup refuses to drop a table on the replacement connection. When cleanup cannot be confirmed, the failed pocket stays listed and continues to count against the model's pocket limit. Restore the original storage connection, delete the failed pocket, then retry creation on the replacement target. A rebuild also waits for cleanup when it would otherwise lose the original table's location. For older pockets whose original storage identity was never recorded, refresh and deletion also wait for an administrator to reconcile that identity or confirm that the original table has been removed. Changing the connection alone cannot confirm this. An imported pocket with a new physical name has no stored table and can be deleted before its first refresh.
Schedule semantics
A pocket's measured storage can be Unknown. Its stored copy exists but its size is not recorded; this does not mean zero bytes. When the total is needed, Tessallite reads the size of such a copy from the target's own table information. Total storage and remaining budget stay unknown only when the target cannot report a stored copy's size. A saved definition that has never been filled uses no storage.
With a finite storage budget, creating pockets and refreshing them waits for those measurements. This waiting check leaves the current copy unchanged. If a new copy's size cannot be measured after a build, the new copy is removed and the refresh fails with a clear reason. Unlimited budgets keep allowing builds and refreshes when size information is unavailable. If waiting persists, an administrator can restore size reporting and use an unlimited budget for a refresh that records the measurements, then restore the finite budget.
The Scheduler evaluates enabled pockets on each tick. A pocket is due when the previous cron-scheduled fire time is newer than the pocket's last_refresh_at. Manual refreshes (via Refresh now or the API) do not interfere with the cron cadence — they rebuild immediately and update last_refresh_at.
| Preset | Cron | When it runs |
|---|---|---|
| Every hour | 0 * * * * | At the top of every hour |
| Every 6 hours | 0 */6 * * * | 00:00, 06:00, 12:00, 18:00 UTC |
| Daily at 02:00 | 0 2 * * * | Once per day at 02:00 UTC |
| Weekly (Sunday 03:00) | 0 3 * * 0 | Sundays at 03:00 UTC |
Pickers accept any valid five-field cron expression. All times are UTC.
How matching works
The Router tries aggregates first; when no aggregate serves the query, it uses a pocket that fits. A pocket fits a query when:
- Shape matches. Either the exact defining-SQL fingerprint, or the filter-only fingerprint — so a
SELECT *pocket can also serve aggregate queries (SELECT COUNT(*),SELECT SUM(amount)) and identity-derived-table queries (SELECT … FROM (SELECT * FROM model WHERE …) q) over the same filter slice. - Slice matches. The pocket's own filters and the creator's row security and default filters form its stored population. The caller's query, including the caller's own row security and default filters, must be contained in that population. The query may narrow further; if coverage cannot be proved, another pocket or the source answers. Each caller's own security still filters rows read from a pocket. Pockets built before creator population was recorded retain their original slice until the next refresh.
- Columns are all there. The pocket's table holds every column the query names. A pocket stores each source column once, under one field name, so a query that reads the same column through another measure (an average and a sum of one amount, for example) is computed from the source. A time comparison, a calculated measure and a composite measure are always computed from the source.
A pocket only changes how fast an answer comes back. A query that a pocket cannot answer exactly as the source does is answered from the source, with the same result as if the pocket did not exist.
When the Router passes over a pocket, the reason is written to the route log and shown in the Diagnostics panel. The reasons are:
| Reason | Meaning |
|---|---|
flag_disabled | pocket.enabled is off at the system level. |
model_disabled | pocket.model_enabled is off for this model. |
no_tenant_filter | pocket.require_tenant_filter is on and the query has no tenant-scope column. Set pocket.tenant_scope_from_context to accept the authenticated session's tenant in place of an explicit filter. |
no_candidates | No fresh pocket exists for this model. |
fingerprint_or_predicate_mismatch | A pocket exists but its shape or slice does not fit this query. |
population_unproven | The stored creator population cannot be proved to cover the caller's query. Another pocket or the source is used. |
rewrite_unsafe | A pocket matched the slice but cannot answer the query exactly as the source does: its table does not hold a column the query names, or the query asks for a time comparison, a calculated or composite measure, or a measure it does not aggregate itself. The source was used instead. |
complex_sql / unresolvable_where | The query could not be bound into an intermediate representation safely. |
from_outside_model | A defensive guard caught a pocket whose defining SQL points outside the model. With the model-subset contract enforced at create time this should not occur in practice. |
See Known limitations: Pocket tables for the current constraints.
Advanced tab
The Advanced tab (edit mode only) is read-only metadata: physical table name, status, created timestamp, last refresh, row count, storage bytes, and hit count. Use it to confirm the pocket is being consumed by the Router and to diagnose storage pressure.