Skip to content

[Feature Request]: Enhance data branch diff with fallback, delta output, and summary statistics #23751

Description

@XuPeng-SH

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

Currently data branch diff has limitations that make it less flexible than Git's diff:

  1. Only works with branched tables: Requires LCA (Lowest Common Ancestor) relationship, cannot compare arbitrary tables
  2. Limited output modes: Only supports full output and output count, lacks incremental change tracking
  3. No detailed statistics: output count only returns total rows, not breakdown of changes

Describe the feature you'd like

1. Fallback to EXCEPT for non-branched tables

Current behavior:

-- Only works if t2 was created from t1
data branch create table t2 from t1{snapshot="sp1"};
data branch diff t2 against t1;  -- ✅ Works (has LCA)

-- Fails if no branch relationship
data branch diff t3 against t4;  -- ❌ Error: no LCA

Proposed behavior:

-- Automatically fallback to EXCEPT-like behavior
data branch diff t3 against t4;  -- ✅ Works (uses set difference)

2. Delta output mode

Proposed syntax:

data branch diff t1 against t2 output delta;

Expected result:

operation | a | b
----------|---|---
+         | 3 | 3  -- Added in t1
-         | 4 | 4  -- Deleted from t1 (exists in t2)

Similar to Git's +/- notation for added/removed lines.

3. Summary statistics output

Proposed syntax:

data branch diff t1 against t2 output summary;

Expected result:

metric    | count
----------|------
added     | 10
deleted   | 5
modified  | 3
unchanged | 100

Provides quick overview without scanning all rows.

Describe implementation you've considered

Fallback mechanism

  • Check if tables have LCA relationship
  • If no LCA: use EXCEPT-based comparison
  • Maintain same output format for consistency

Delta output

  • Add operation column: + (added), - (deleted), ~ (modified)
  • Use primary key to match rows for modification detection
  • If no PK: treat as add/delete only

Summary statistics

  • Leverage existing diff computation
  • Aggregate results into statistics
  • Minimal performance overhead (single pass)

Documentation, Adoption, Use Case, Migration Strategy

Use Cases

  1. Data validation: Compare staging vs production tables without branch relationship
  2. Change tracking: Quickly see what changed between snapshots
  3. Monitoring: Track data drift with summary statistics
  4. Debugging: Identify specific rows added/deleted with delta output

Adoption

  • Backward compatible: existing queries work unchanged
  • New output modes are opt-in via output clause
  • Fallback behavior is transparent to users

Activity

  1. added this to the MO-202602 milestone on Feb 15, 2026
  2. added
    priority/p0
    on Feb 15, 2026
  3. gouhongshen commented on Mar 2, 2026

    @gouhongshen
    Contributor

    Sync note:

    1. output delta and output limit have the same behavior, so no separate implementation is needed.
    2. The output summary format spec is updated to match the current implementation.
  4. gouhongshen commented on Mar 2, 2026

    @gouhongshen
    Contributor

    Clarification with current implemented OUTPUT SUMMARY format:

    data branch diff <target> against <base> output summary; returns 3 columns and 3 rows:

    Columns:

    1. metric
    2. <target table expr> (BIGINT count)
    3. <base table expr> (BIGINT count)

    Rows (fixed metric values):

    • INSERTED
    • DELETED
    • UPDATED

    Equivalent shape:

    metric
    INSERTED n1 n2
    DELETED n3 n4
    UPDATED n5 n6

    So the spec for output summary should match this current shape.

  5. added
    ai-heavy
    on Jul 1, 2026
  6. Ariznawlll commented on Sep 18, 2026

    @Ariznawlll
    Collaborator

    测试版本

    • 实际执行分支:main
    • 实际执行 commit:4ff27bb9b35c43c1b0961bb9a01bf8fc0b6a2171
    • 最新官方 main:780ef933f2479aa1679faf13d08850ce6c8f7c2f
    • 新鲜度核对:两者之间没有 Data Branch DIFF、fallback 或 OUTPUT 相关代码/回归资产变更。
    • 部署方式:本地隔离 standalone 黑盒验证,补充 MatrixOne distributed BVT。
    • 测试日期:2026-09-18

    原问题验证

    围绕 DATA BRANCH DIFF 的 fallback、OUTPUT DELTA/LIMIT 和 OUTPUT SUMMARY 执行原语法与结果验证。OUTPUT DELTA 与 OUTPUT LIMIT 按研发说明采用同一行为;OUTPUT SUMMARY 固定返回 INSERTED、DELETED、UPDATED 三行,以及 metric、target count、base count 三列。

    Happy Path 覆盖

    1. 标准 LCA 链路的 DIFF COUNT、DELTA/LIMIT 与 SUMMARY 结果正确,SUMMARY 的三项统计与变更行集合一致。
    2. 无可用 LCA 时走 fallback,结果可执行且与显式对照数据一致。
    3. 反向比较时 INSERTED/DELETED 方向正确翻转,UPDATED 数量保持正确。
    4. 无主键表的重复行按多重集语义比较,不丢失、也不重复计数。
    5. embedded DML 中使用 DIFF 输出的路径与普通 SQL 返回结果一致。

    Unhappy Path 覆盖

    1. 非法 OUTPUT 形态及不支持的组合由 parser 按预期拒绝。
    2. 不满足普通 LCA 读取条件时不伪造普通链路结果,而是进入受支持的 fallback 比较。
    3. 重复行、反向方向和无主键边界均未出现重复 replay、漏行或统计方向错误。

    白盒验证

    • parser 与 embedded-DML focused 测试分别以 -count=3 执行通过。
    • 公开 SQL 回归以 MatrixOne BVT 执行:主集 1250/1250 通过,补充集 39/39 通过。
    • 本次能力为确定性 SQL 结果与统计语义,不涉及节点故障、后台恢复或规模阈值;Chaos 与 big-data 不适用。

    回归测试

    • 实现及 BVT 回归已合入 matrixorigin/matrixone#23789,合入 commit:72ff591183d0f24bc2401e77ea5803ac56ec8d39。
    • 回归资产位于 test/distributed/cases/git4data/branch/diff/ 与 test/distributed/cases/git4data/branch/merge/,覆盖 diff/merge 的输出与边界用例。

    测试证据

    • #23789 Files changed 可核对实现与对应 distributed SQL/golden。
    • issue 中关于 SUMMARY 固定结果形态的研发说明:comment。

    测试结论

    测试通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-heavykind/featurepriority/p0

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions