Skip to content

Fix: Snowflake history mart performance - #587

Merged
mtcarlone merged 4 commits into
mainfrom
fix/mart-performance
Nov 6, 2026
Merged

mtcarlone merged 4 commits into
mainfrom
fix/mart-performance

Conversation

@mtcarlone

Copy link
Copy Markdown
Contributor

Overview

Fixes the 2.11.x performance regression on the Snowflake consumption and observability marts. The package's generic tests now ship disabled, and the marts read a lookback window (dbt_artifacts_mart_lookback_days, default 30 days) instead of all uploaded history.

Update type - breaking / non-breaking

  • Minor bug fix
  • Documentation improvements
  • Quality of Life improvements
  • New features (non-breaking change)
  • New features (breaking change)
  • Other (non-breaking change)
  • Other (breaking change)
  • Release preparation

Breaking for 3.0.0 in two ways:

  • The package's tests no longer run in consumer projects. To get them back, add data_tests: dbt_artifacts: +enabled: true to your dbt_project.yml.
  • The marts now show the last 30 days by default. Monthly marts start on the first of a month. Consumers who rely on full history set dbt_artifacts_mart_lookback_days: null.

Tentatively closes #583.

Changes

Project config

  • dbt_project.yml: data_tests: dbt_artifacts: +enabled: false. This has to be a literal: dbt doesn't render Jinja in a package's enabled setting for tests, and any templated value (even "{{ true }}") disables them.
  • integration_test_project/dbt_project.yml: turns the package's tests back on, so CI still runs all 60.

Macros

  • New macros/marts/mart_lookback.sql:
    • mart_lookback_days() reads and validates dbt_artifacts_mart_lookback_days. The default is 30 and null reads all history. 0, negative numbers and non-numbers raise a compiler error.
    • mart_lookback_start(align_to_month, min_days) returns the window's first UTC day.
    • mart_lookback_filter(column_expr, lookback_start, pad_days) returns the date predicate.
    • All three are documented in macros/_macros.yml.

Models (all Snowflake-only, as before)

  • dim_dbt__lineage_edges: reads only manifest uploads inside the window, on a fixed date so Snowflake can prune. It's the current graph, not lineage history. Nodes removed from the project now drop out after the window; before, their edges stayed forever.
  • fct_dbt__run_health_daily, _detail: invocations and executions in the window.
  • fct_dbt__model_performance: reports days in the window and reads dbt_artifacts_run_rate_days extra days, so the first reported day has a full baseline.
  • fct_dbt__dag_bottlenecks_detail: child executions in the window. Parents are read one day earlier, so an invocation that spans the window's start keeps its binding parent.
  • fct_dbt__flaky_tests_detail, fct_dbt__flaky_tests: whole months, starting from the month that contains the window's start. Executions are read one day earlier so lag() sees the failure before the first flip.
  • fct_dbt__consumption_daily_detail, fct_dbt__consumption_by_model: whole months, covering at least dbt_artifacts_run_rate_days. Both use the same start, so they still reconcile.
  • fct_dbt__consumption_forecast: drops any month whose run-rate window starts before the data does. The current month is always kept.

Docs

  • README: a table of what each mart answers, the lookback setting, how to disable marts by name, and how to turn the package's tests on.

Validation

  • Ran changed models and downstream assets locally: Snowflake sandbox, the CI sequence (build excluding tests, then two full builds).

  • All tests passed locally: 60/60, 134/134, 134/134 on Snowflake.

  • Test switch: with the integration project's override, dbt ls --resource-type test lists 60 package tests; without it, 0.

  • Row-count check on production data: checked against a production artifacts schema with 31 days of history. With the window set to null, the patched SQL returns the same row counts as the previous SQL for dim_dbt__lineage_edges, fct_dbt__dag_bottlenecks_detail, fct_dbt__flaky_tests_detail, fct_dbt__model_performance, fct_dbt__consumption_daily_detail and fct_dbt__run_health_daily. At 30 days, only the oldest day drops out.

  • Other engines: the DuckDB suite (./scripts/ci/test.sh duckdb, including the --sample runs) passes. ./scripts/ci/fusion-parse.sh and the Fusion build on DuckDB pass. Fusion reports the same three dbt1071 warnings as main.

  • Var validation: dbt_artifacts_mart_lookback_days: 0 fails compilation with a clear message, and "7" (a string) works.

Outstanding questions

  • Query speed at scale isn't measured. The build-time fix (tests off) removes the queries that caused the slowdown. The query-time gain depends on Snowflake skipping micro-partitions outside the window, which hasn't been measured on years of history; the production check above had only one month. A synthetic multi-year test is planned.
  • Lineage edges can come back empty. dim_dbt__lineage_edges is empty if no run has uploaded the manifest within the window (for example, dbt_artifacts_upload_manifest: false with rare deployments). The README says so.
  • Long windows still mean full recompute. A long window (for example a year) still recomputes on every query, because the marts are views. Making the heavy detail marts incremental, and possibly opt-in, is follow-up work. Plain tables wouldn't help: they rebuild on every consumer dbt build.
  • The marts remain Snowflake-only, as in 2.11.x.

What databases have you tested with?

  • Snowflake
  • Google BigQuery
  • Databricks
  • Spark
  • N/A

Also: DuckDB (dbt Core and Fusion), where these marts are disabled; this confirms the test switch and macros don't affect other adapters.

2.11.0 added 60 generic tests to the consumption and observability marts.
dbt build runs a package's tests by default, and each test re-reads the
views it checks over all uploaded history, so projects with long history
saw builds go from minutes to hours.

The tests check the package's own SQL, not the consumer's data, so they
now ship disabled. A project turns them on with
`data_tests: dbt_artifacts: +enabled: true` in its own dbt_project.yml;
the integration test project does, so CI still runs them. The package's
setting has to be a literal: dbt doesn't render Jinja in a package's
`enabled` config for tests, and a templated value disables them even
when it renders true.
Every one of these views read all uploaded history on every query.
dim_dbt__lineage_edges ranked every manifest row ever uploaded (one row
per node per invocation), and the bottleneck and flaky-test marts join
through it.

dbt_artifacts_mart_lookback_days (default 30, null for all history)
now bounds them:
- daily marts report the last N days;
- monthly marts start on the first of the month containing the window
  start, so no month is partial;
- the consumption marts read at least dbt_artifacts_run_rate_days, and
  consumption_by_model and consumption_daily share a start so they
  still reconcile; the forecast drops months whose run-rate window
  falls before the start (never the current month);
- model_performance reads run-rate days earlier so its first day has a
  full baseline;
- lineage_edges reads N days before each manifest table's latest
  upload, not before today, so projects that upload the manifest
  rarely still get the whole graph;
- window functions and invocation joins read one day early so rows at
  the edge of the window keep their neighbors.

With the window set to null, row counts match the previous SQL exactly
on a month of real production history.
dim_dbt__lineage_edges filtered each manifest table against a scalar
subquery (max(run_started_at) minus the window). Snowflake can't use a
subquery's result to skip micro-partitions when it plans the query, so
the model still read every manifest row ever uploaded, including the
depends_on_nodes JSON.

The model is the current graph, not a history of lineage changes, and
every manifest upload carries the whole graph, so it only needs recent
uploads. It now uses the same fixed-date window as the other marts
(today minus dbt_artifacts_mart_lookback_days). A side effect: nodes
deleted from the project drop out once their last upload is older than
the window; before, their edges stayed forever. The cost: a project
that hasn't uploaded the manifest within the window
(dbt_artifacts_upload_manifest: false) gets no edges; the README says
so.
@mtcarlone mtcarlone added this to the 3.0.0 milestone Nov 6, 2026
@mtcarlone
mtcarlone merged commit a37f340 into main Nov 6, 2026
6 checks passed
@mtcarlone
mtcarlone deleted the fix/mart-performance branch November 6, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Optimize or remove new FCT_DBT_* models

1 participant