Skip to content

Feature Request: sqlmesh render loads and processes the entire project context for a single model #5905

Description

@fresioAS

Summary

When running sqlmesh render <model>, the full project context is initialized and
all snapshots are passed into the renderer, even though only the target model and
its transitive upstream dependencies are relevant to the operation.

Current Behavior

sqlmesh render takes a single model as its argument:
Usage: sqlmesh render [OPTIONS] MODEL
Render a model's query, optionally expanding referenced models.

Despite targeting one model, the following happens:

  1. The entire Context is initialized — all models, macros, audits, and snapshots
    across the project are parsed and loaded.
  2. QueryRenderer.render() (in sqlmesh/core/renderer.py) receives the full
    snapshot dictionary (documented as "All upstream snapshots by model name").
  3. _to_table_mapping() iterates over every snapshot in the project to build a
    table mapping, regardless of whether those models are reachable from the target.
  4. _resolve_tables() applies this full mapping while walking the query AST.

Expected Behavior

For sqlmesh render <model>, only the target model and its transitive upstream
dependencies need to be resolved. The context initialization and snapshot
resolution should be scoped to the subgraph rooted at the target model, rather
than the full project DAG.

Why This Matters

  • Performance: In large projects with hundreds or thousands of models, loading
    the full context and building a full snapshot mapping is expensive. A user
    rendering a single leaf model should not pay the cost of loading models in
    unrelated parts of the DAG.
  • Unnecessary work: _to_table_mapping and _resolve_tables process snapshots
    that can never appear in the target model's query, making the work provably
    wasteful.
  • Scalability: As projects grow, the overhead of sqlmesh render grows with
    the total number of models rather than with the depth/breadth of the target
    model's upstream graph.

Proposed Direction

  • When sqlmesh render <model> is invoked, compute the set of transitive upstream
    dependencies of the target model from the DAG.
  • Restrict context loading (or at minimum snapshot resolution) to that subgraph.
  • Pass only the relevant subset of snapshots to QueryRenderer.render() instead
    of the full project snapshot dictionary.

This is analogous to how graph-aware tools scope work to the relevant subgraph
rather than the full graph when a specific node is targeted.

References

  • CLI command definition: sqlmesh/cli/main.py (lines 253–305)
  • Renderer snapshot handling: sqlmesh/core/renderer.py_render(),
    _to_table_mapping(), _resolve_tables()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions