Repository navigation
Fix: Snowflake history mart performance - #587
Merged
Merged
Conversation
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.
…k window and package tests
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Breaking for 3.0.0 in two ways:
data_tests: dbt_artifacts: +enabled: trueto yourdbt_project.yml.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'senabledsetting 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
macros/marts/mart_lookback.sql:mart_lookback_days()reads and validatesdbt_artifacts_mart_lookback_days. The default is 30 andnullreads 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.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 readsdbt_artifacts_run_rate_daysextra 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 solag()sees the failure before the first flip.fct_dbt__consumption_daily_detail,fct_dbt__consumption_by_model: whole months, covering at leastdbt_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
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 testlists 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 fordim_dbt__lineage_edges,fct_dbt__dag_bottlenecks_detail,fct_dbt__flaky_tests_detail,fct_dbt__model_performance,fct_dbt__consumption_daily_detailandfct_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--sampleruns) passes../scripts/ci/fusion-parse.shand the Fusion build on DuckDB pass. Fusion reports the same threedbt1071warnings asmain.Var validation:
dbt_artifacts_mart_lookback_days: 0fails compilation with a clear message, and"7"(a string) works.Outstanding questions
dim_dbt__lineage_edgesis empty if no run has uploaded the manifest within the window (for example,dbt_artifacts_upload_manifest: falsewith rare deployments). The README says so.dbt build.What databases have you tested with?
Also: DuckDB (dbt Core and Fusion), where these marts are disabled; this confirms the test switch and macros don't affect other adapters.