Workload: {{NUM_SLOW}} slow queries, {{HOURS}} hours wasted
Owner: role {{OWNER_ROLE}} · last DDL by {{LAST_DDL_USER}} ({{LAST_DDL_TYPE}} on {{LAST_DDL_TIME}})
· dbt node: {{DBT_NODE_ID}}
Candidate: {{CANDIDATE_NAME}}
Covers {{NUM_COVERED}} queries, ~{{HOURS_SAVED}}h saved
Dimensions: {{DIMS}}
Metrics: {{METRICS}}
IMMUTABLE WHERE proposal (refresh-cost optimization):
{{IMMUTABLE_WHERE_PREDICATE}} — {{IMMUTABLE_WHERE_RATIONALE}}
This tells the engine that source rows matching the predicate are frozen (no updates, deletes, or late-arriving inserts). Refresh skips those rows, making both full and incremental refresh substantially cheaper.
Before keeping this clause, confirm: "Will any rows matching {{IMMUTABLE_WHERE_PREDICATE}} ever be updated, deleted, or joined by new rows that change their aggregated values?" If yes → remove the IMMUTABLE WHERE line.
DDL
-- If MAX_STALENESS is missing, run first:
-- ALTER SEMANTIC VIEW {{SV_FQN}} SET MAX_STALENESS = '1 hour';
ALTER SEMANTIC VIEW {{SV_FQN}} ADD MATERIALIZATION {{CANDIDATE_NAME}}
WAREHOUSE = {{WAREHOUSE}}
IMMUTABLE WHERE ({{IMMUTABLE_WHERE_PREDICATE}}) -- REMOVE IF CANNOT CONFIRM
AS
DIMENSIONS {{DIMS}}
METRICS {{METRICS}};
How to test this materialization
- Set
MAX_STALENESS if not already set:
ALTER SEMANTIC VIEW {{SV_FQN}} SET MAX_STALENESS = '1 hour';
- Run the
ADD MATERIALIZATION DDL above.
- Wait for the initial refresh to complete. Monitor via:
SELECT * FROM TABLE(INFORMATION_SCHEMA.SEMANTIC_VIEW_MATERIALIZATION_REFRESH_HISTORY(
NAME => '{{CANDIDATE_NAME}}'
));
- Re-run one of the slow queries and compare execution time:
-- Sample covered query (was {{SAMPLE_DURATION}}s):
{{SAMPLE_QUERY}}
- Verify the materialization was used via the query profile — look for
SemanticViewMaterializationScan in the plan.
- If performance is satisfactory, keep it. If not, drop:
ALTER SEMANTIC VIEW {{SV_FQN}} DROP MATERIALIZATION {{CANDIDATE_NAME}};
Covered queries (sample)
| Query ID | Duration | User | Dims | Metrics |
{{QUERY_ID}} | {{DURATION}}s | {{USER}} | {{QUERY_DIMS}} | {{QUERY_METRICS}} |