Feature Request: `sqlmesh plan` performs full project loading for every non-prod environment plan
Maintainer antworten meist innerhalb von 4 Tagen
@Ajay-Satish-01 arbeitet bereits daran.
Seit 29.8.2026.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Ruhig
- Tech-Stack
- python
- Bereich
- data-engineering
Rechercherichtung
Start by reading sqlmesh/core/context.py around GenericContext.load(), plan_builder(), and _snapshots(), then trace the related ContextDiff.create() and PlanBuilder paths in sqlmesh/core/context_diff.py and sqlmesh/core/plan/builder.py. The issue calls for scoping non-prod planning to the changed subgraph across loading, state reads, linting, tests, snapshots, and DAG work. Done means dev plans avoid full-project work while preserving correct plans for changed models and their dependencies.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Summary
Every sqlmesh plan <env> where <env> is not prod loads, parses, and processes the entire project — all models, macros, audits, tests, and snapshots — regardless of how many models actually changed. Dev workflows, where engineers iterate on a small subset of models, pay a cost that scales with total project size rather than with the size of the change.
Where this happens
1. Full filesystem load is unconditional
GenericContext.__init__ always calls self.load():
sqlmesh/core/context.py ~L473:
if load:
self.load()
load() parses every model, macro, audit, test, and metric across all project paths, then runs update_model_schemas() on the full DAG and model.validate_definition() on every model (context.py ~L629–728). There's no way to load only the changed subgraph.
2. Full prod state read during load()
Before plan() is even called, all prod snapshots are fetched from the state backend to populate remote-only models:
sqlmesh/core/context.py ~L687–699:
prod = self.state_reader.get_environment(c.PROD)
if prod:
for snapshot in self.state_reader.get_snapshots(prod.snapshots).values():
...
3. Linting and tests run on all models
lint_models() and _run_plan_tests() run against the full model set before the plan is built, with no scoping to changed models:
sqlmesh/core/context.py ~L1579–1582.
4. Full snapshot creation with a state round-trip
_snapshots() creates snapshots for every model/standalone audit, then bulk-fetches all of them from state:
sqlmesh/core/context.py ~L2814–2842:
nodes = {**(models_override or self._models), **self._standalone_audits}
snapshots = self._nodes_to_snapshots(nodes)
stored_snapshots = self.state_reader.get_snapshots(snapshots.values())
Even with models_override (e.g. via --select-model), it still contains every model — selected ones from local state, the rest sourced from remote.
5. Full context diff against remote state
ContextDiff.create() fetches the entire target environment and bulk-reads all local + all modified remote snapshots:
sqlmesh/core/context_diff.py ~L180–182:
stored = state_reader.get_snapshots(
[*snapshots.values(), *modified_snapshot_name_to_snapshot_info.values()]
)
6. Full DAG construction and traversal
PlanBuilder._build_dag() iterates every snapshot in the context diff, not just the changed subgraph:
sqlmesh/core/plan/builder.py ~L363–367:
for s_id, context_snapshot in self._context_diff.snapshots.items():
dag.add(s_id, context_snapshot.parents)
This full DAG is then traversed by _build_directly_and_indirectly_modified, _build_restatements, _build_models_to_backfill (dag.subdag(...) only runs after the full DAG exists), and earliest_interval_start (iterates all snapshots).
7. Dev pays more than prod for DeployabilityIndex
Prod uses the constant-time DeployabilityIndex.all_deployable(); dev iterates every snapshot via DeployabilityIndex.create():
sqlmesh/core/plan/builder.py ~L298–306:
deployability_index = (
DeployabilityIndex.create(
self._context_diff.snapshots.values(), # ALL snapshots
start=self._start,
start_override_per_model=self._start_override_per_model,
)
if self._is_dev
else DeployabilityIndex.all_deployable()
)
Dev — the most frequent workflow — is disproportionately penalized.
What dev plans actually need
Only the changed models, their upstream dependencies, and their downstream dependents matter. Everything else in the project is irrelevant, but the current implementation has no concept of this subgraph.
The one scoping that does exist: in dev without --include-unmodified, backfill_models is limited to modified/added model names (context.py ~L1659–1667). This only limits what gets backfilled — it does not reduce the work done to produce the plan.
Impact
- Large projects:
sqlmesh plan devafter a one-model change still parses every model, validates every definition, creates every snapshot, and issues multiple full-project state reads. Cost scales with project size, not change size. - Dev iteration is disproportionately penalized: dev is the most frequent workflow, yet pays more per-plan than prod due to
DeployabilityIndex.createiterating all snapshots. - State backend load: multiple full
get_snapshots()calls per plan (duringload()for prod state, in_snapshots(), and inContextDiff.create()) — expensive for networked/DB-backed state stores. - Linting/tests unscoped: run over the full project even when only one model changed.
Suggested direction
For non-prod environments, determine the changed subgraph first, then scope all subsequent work to it:
- Change detection before full load — identify changed files (e.g. via mtimes or git diff) to determine the minimal subgraph to load.
- Lazy/partial context loading — let the
Loaderload only a specified subgraph, representing unrelated models as lightweight stubs sourced from remote state. - Scoped snapshot creation —
_snapshots()should only build snapshots for the changed subgraph; unrelated models reuse their stored fingerprints from state. - Scoped context diff —
ContextDiff.createshould operate on a subgraph snapshot dict and fetch only the relevant remote snapshots. - Scoped DAG —
PlanBuilder._build_dag()should build a DAG scoped to the changed subgraph in dev, not always the full project DAG. - Scoped linting/tests —
lint_models()and_run_plan_tests()should be scoped to the changed subgraph for dev plans. - Scoped
DeployabilityIndex— scopeDeployabilityIndex.createin dev to the modified subgraph to close the gap with prod'sall_deployable().
References
- Context init/unconditional load:
sqlmesh/core/context.py~L473–474 load()full parse + schema update:sqlmesh/core/context.py~L629–753- Prod state read during
load():sqlmesh/core/context.py~L687–699 plan_builder()linting/tests/snapshots:sqlmesh/core/context.py~L1564–1667_snapshots()full creation + state read:sqlmesh/core/context.py~L2814–2842ContextDiff.create()full state diff:sqlmesh/core/context_diff.py~L92–230PlanBuilder.build()full DAG construction:sqlmesh/core/plan/builder.py~L280–367DeployabilityIndexdev vs prod branching:sqlmesh/core/plan/builder.py~L298–306
- Vorherrschende Sprache
- Python
- Sterne
- 3.3k
- Forks
- 471
- Ø Merge
- 6 T. 7 Std.
- Gemergte PRs (30 T.)
- 35
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SQLMesh/sqlmesh
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
Maintainer antworten meist innerhalb von 4 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
SQLMesh/sqlmesh#6008 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 4 Tagen
-
VSCode Extension: SQLMesh LSP crashes on startup: ImportError: cannot import name 'WorkspaceDiagnosticRefreshRequest' with lsprotocol 2025.xEvtl. vergeben @boomesh11 hat das vor 15 Tagen übernommen. OffenBug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 4 Tagen
-
Improvement
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
SQLMesh/sqlmesh#5696 · 6 Kommentare ·
Maintainer antworten meist innerhalb von 4 Tagen
Alle Issues in SQLMesh/sqlmesh
Ähnliche Issues
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%Evtl. vergeben @sumitkhond111-del hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
open-mmlab/mmcv#3352 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
OpenGithubs/weekly#263 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
Maintainer antworten meist innerhalb von 1 Tag
-
comp/cli P3 type/feature
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
NousResearch/hermes-agent#162784 ·
Maintainer antworten meist innerhalb von 1 Tag