RFC: Improve Plan Algorithm With Column Level Lineage
維護者通常 4 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
研究方向
Start with sqlmesh/core/model/definition.py and its is_breaking_change / _is_only_projection_additions logic, then read sqlmesh/core/snapshot/categorizer.py, sqlmesh/core/plan/builder.py, and sqlmesh/core/lineage.py to understand the proposed flow. The issue describes column diffs, downstream lineage checks, and selective rebuilds, but says initial steps are still to be determined and warns that this changes core logic. Done means unaffected descendants can be skipped safely while affected descendants rebuild; the issue does not name tests to run.
由索引模型根據 Issue 內容生成。
描述
Summary
SQLMesh OSS's plan algorithm is not as efficient as Tobiko Cloud. There are numerous efficiency improvements that can be introduced into the plan logic by introducing column level lineage.
Plan Algorithm Comparison
Parent users has id, email, username. Child A selects id, email. Child B selects only id. Grandchild C selects id from A.
users
(id, email, username)
/ \
/ \
A B
(id, email) (id)
|
C
(id)
| Change (to users) | OSS today | Tobiko Cloud (inferred) |
|---|---|---|
Add phone |
A, B, C skip | Same |
Change email expression |
A, B, C rebuild | A rebuilds; B, C skip |
Drop unused username |
A, B, C rebuild | A, B, C skip (users still rebuilds) |
Change WHERE statement |
A, B, C rebuild | A, B, C rebuild |
Current Pseudo-Code
plan (DAG order)
│
├─ new model ──────────────────────── BREAKING
│
├─ directly modified
│ ├─ kind change / SELECT * ───── BREAKING
│ └─ compare old vs new query
│ ├─ only added columns ─── NON_BREAKING
│ └─ anything else ──────── BREAKING
│
└─ indirectly modified
├─ parent NON_BREAKING ──────── SKIP
└─ parent BREAKING ──────────── REBUILD
Future Pseudo-Code
plan (DAG order)
│
├─ new model ──────────────────────── BREAKING
│
├─ directly modified
│ ├─ kind change / SELECT * /
│ │ can't render / Python ────── BREAKING (same as today)
│ └─ column diff (old vs new)
│ ├─ only added columns ─── NON_BREAKING
│ ├─ whole row set changed ─ BREAKING (WHERE / JOIN / …)
│ └─ some columns dirty ─── rebuild self
│ (descendants decided below)
│
└─ indirectly modified
ask lineage: do I depend on a dirty column?
├─ no ─────────────────────── SKIP
└─ yes ────────────────────── REBUILD
(and mark my outputs dirty
so grandchildren can ask the same)
Logic Simplified
- Directly Modified - Model's own query/data changed. Fingerprint data hash changed. It will rebuild itself (unless forward-only, ignore)
- Indirectly Modified - Model's SQL did not change. A parent did. Current logic copies parent's "category". Future logic will use column-level to determine "category"
| Category | This model | Meaning |
|---|---|---|
BREAKING / NON_BREAKING |
Direct | Always rebuild self. Difference is only what descendants do today. |
INDIRECT_BREAKING |
Indirect | Rebuild this model |
INDIRECT_NON_BREAKING |
Indirect | Skip — reuse the old physical table |
For children descendants, we can improve the logic to determine categories INDIRECT_BREAKING or INDIRECT_NON_BREAKING by looking at the column level changes. We would traverse the table lineage and for each model that has children, we would determine for each column:
| This column | Means | If the child reads it |
|---|---|---|
| Clean | Same as before | Does not force a rebuild. INDIRECT_NON_BREAKING |
| Dirty | Not the same (rewritten, from a dirty parent column, or row set changed) | Forces INDIRECT_BREAKING |
| Added | New column | Does not force a rebuild. INDIRECT_NON_BREAKING |
| Removed | Column is gone | Forces INDIRECT_BREAKING |
Then:
- Any dirty/removed column the child reads → model is
INDIRECT_BREAKING→ keep labeling that model’s outputs for its children. - Child reads only clean/added → model is
INDIRECT_NON_BREAKING→ all of its outputs are clean (this parent won’t force descendants to rebuild). - Can’t prove →
INDIRECT_BREAKING(same as today).
Goal: more models correctly land on INDIRECT_NON_BREAKING and are not rebuilt.
High Level Pieces
We need three major pieces here:
-
Column diff on the changed model
Did this change only some columns, or the whole row set (WHERE / JOIN / etc.)? Listclean,dirty,added,removed. -
Ask who reads those columns
Using lineage (and filters/joins, not just SELECT): which downstream models/columns actually depend on thedirtycolumns? -
Rebuild only that cone
The changed model still rebuilds. Descendants that lineage says are untouched skip. That’s B skipping whenemailchanged, and C skipping when it only uses A’sidand A’s rows didn’t move.
Right now OSS does some of piece 1. It answers "did we only add columns to the model?" -- It does not list columns. Current logic treats "additive" as non-breaking. Anything else that isn't just a pure add ends with a "not sure" conclusion -> rebuild everyone.
Only comparison happens in sqlmesh/core/definition.py in is_breaking_change function right now. Current logic determines breaking or non_breaking. Then that affects descendants.
Starting Pieces
| Already there | Role today | What it becomes |
|---|---|---|
sqlmesh/core/model/definition.py — is_breaking_change / _is_only_projection_additions |
Additive or not (False / None) | Piece 1: column diff: clean, dirty, added, removed |
sqlmesh/core/snapshot/categorizer.py — categorize_change |
Maps that to NON_BREAKING / BREAKING on the direct model |
Same job, richer input |
sqlmesh/core/plan/builder.py — _categorize_snapshot |
Direct path calls categorizer; indirect path copies the "category" of the parent | Piece 3: indirect path asks lineage instead of copying "category" from parent |
sqlmesh/core/lineage.py |
UI/LSP column graph | Piece 2: “does this descendant depend on a dirty column?” |
Initial Steps
To be determined. We have to be very careful about this because we're modifying core logic. This also introduces a much bigger layer of checks. How do we keep this performant?
References
Tobiko Cloud claims:
- "Tobiko Cloud comes with even more change categorization capabilities than open-source SQLMesh, such as advanced column-level impact analysis." -- https://sqlmesh.readthedocs.io/en/stable/cloud/features/costs_savings/#where-to-find-cost-and-savings-information
- "Unaffected Downstream: SQLMesh understands SQL, so we skip re-execution if a downstream model is not affected by an upstream change." -- https://sqlmesh.readthedocs.io/en/stable/cloud/features/costs_savings/#where-to-find-cost-and-savings-information
- "While this study focuses on benchmarking SQLMesh against dbt Core, we also evaluated Tobiko Cloud, the hosted version of SQLMesh, to examine its handling of breaking changes. SQLMesh uses column-level lineage to differentiate between breaking and non-breaking changes — and Tobiko Cloud extends this capability with more surgical change categorization, refining how downstream updates are processed when a column is modified. This further reduces time and compute spent on backfills, making Tobiko Cloud even more performant than its counterpart — by a factor of seven." -- https://medium.com/dbsql-sme-engineering/databricks-benchmark-study-shows-sqlmesh-outperforms-dbt-core-by-orders-of-magnitude-on-speed-and-0f3b6f281888
- 主要語言
- Python
- 星號
- 3.3k
- 分支
- 471
- 平均合併
- 6 天 7 小時
- 30 天內合併 PR
- 35
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SQLMesh/sqlmesh 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 86/100
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
維護者通常 4 天內回覆
-
難度 2/5 1-3 小時 新手友好度 67/100
SQLMesh/sqlmesh#6008 · 1 則留言 ·
維護者通常 4 天內回覆
-
VSCode Extension: SQLMesh LSP crashes on startup: ImportError: cannot import name 'WorkspaceDiagnosticRefreshRequest' with lsprotocol 2025.x可能已有人在做 @boomesh11 於 15 天前認領。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 4 天內回覆
-
Improvement
難度 1/5 1 小時以內 新手友好度 85/100
SQLMesh/sqlmesh#5696 · 6 則留言 ·
維護者通常 4 天內回覆
相似的 Issue
-
[BUG][Low–Medium] founder_numbers.py silently reads a SAFE discount or pool target given as a fraction (0.2) as 0.2%可能已有人在做 @sumitkhond111-del 今天認領。 未關閉bug
難度 2/5 1-3 小時 新手友好度 72/100
bmad-code-org/BMAD-METHOD#3358 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 86/100
open-mmlab/mmcv#3352 ·
-
難度 1/5 1 小時以內 新手友好度 68/100
OpenGithubs/weekly#263 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
comp/cli P3 type/feature
難度 2/5 1-3 小時 新手友好度 76/100
NousResearch/hermes-agent#162784 ·
維護者通常 1 天內回覆