You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: DATA BRANCH DIFF OUTPUT LIMIT is applied before final primary-key sorting #26056
DATA BRANCH DIFF ... OUTPUT LIMIT N applies the limit before the final primary-key sort. With diff rows produced by both sides, the selected rows depend on batch arrival order instead of being the first N rows of the statement's final sorted result.
Version
Branch: main
Commit: 2eb7f523e5a10f352d3e258183ed8440510388de
Reproduction
DROPDATABASE IF EXISTS g4d_limit_order;
CREATEDATABASEg4d_limit_order;
USE g4d_limit_order;
CREATETABLEbase(id INTPRIMARY KEY, v VARCHAR(20));
INSERT INTO base VALUES (50, 'root');
DATA BRANCH CREATE TABLE child FROM base;
INSERT INTO base VALUES (1, 'base-low');
INSERT INTO child VALUES (100, 'child-high');
DATA BRANCH DIFF child AGAINST base;
DATA BRANCH DIFF child AGAINST base OUTPUT LIMIT1;
The complete result is sorted by primary key:
base INSERT 1 base-low
child INSERT 100 child-high
However, OUTPUT LIMIT 1 returns:
child INSERT 100 child-high
The limited result reproduced in 3 out of 3 runs.
Expected behavior
The limit should be applied to the statement's final primary-key ordered result. For this example, OUTPUT LIMIT 1 should return the row with id = 1.
Actual behavior
The limit is applied to rows as they arrive from parallel diff producers. The retained subset is sorted only afterward, so the row with id = 100 is returned.
Code observation
In satisfyDiffOutputOpt, rows are appended and the producers are stopped as soon as len(rows) reaches the limit. slices.SortFunc(rows, ...) is called only after the channel has been drained. Therefore the final sort cannot recover rows that were discarded before sorting.
This is separate from the existing OUTPUT LIMIT 0 issue: positive limits return the requested row count, but may select the wrong subset.
Activity
fix(frontend): apply data branch diff limit after PK ordering (#26570)
gouhongshen commentedon Aug 3, 2026
fixed
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc58cd292d3e6e039a8882654d3b20ad345171e87原问题验证
构造物理扫描顺序与主键顺序不同的数据,重跑
DATA BRANCH DIFF ... OUTPUT LIMIT。LIMIT 现在在最终主键排序之后应用,连续 3 轮均返回预期的最小主键集合。Happy Path 覆盖
LIMIT 1、n-1、n、n+1,每次均先按最终主键排序再截断。Unhappy Path 覆盖
LIMIT 0返回空集,不会因为排序阶段而输出数据。白盒验证
执行
TestDataBranchOutputLimitUsesFinalPKOrder,验证 limit 使用最终 PK 排序结果;连续执行 3 轮通过。回归测试
test/distributed/cases/git4data/branch/edge/branch_output_limit_order.sql测试证据
测试结论
测试通过。
Ariznawlll commentedon Aug 4, 2026
测试版本
mainc726a6199094184a2e6ebc7504c3e011982b8976原问题验证
构造物理写入顺序与最终主键顺序不同的双侧差异,执行
DATA BRANCH DIFF ... OUTPUT LIMIT。LIMIT 现在稳定返回最终 PK 排序后的前缀;完整 motr 用例连续执行 3 轮通过。Happy Path 覆盖
Unhappy Path 覆盖
白盒验证
不适用:本次补充通过真实 DIFF 输出验证最终排序、边界和读失败原子性。
回归测试
测试证据
12_git4data.issue_26034_26056_output_limit:26 条语句全部成功,连续 3 轮 baseline 一致。测试结论
测试通过。
fix(frontend): apply data branch diff limit after PK ordering (matrix…
fix(frontend): apply data branch diff limit after PK ordering (matrix…
fix(frontend): apply data branch diff limit after PK ordering (matrix…