Repository navigation
[4.2] fix(top): order floating NaNs deterministically - #27532
Conversation
- [ ] API-change - [x] BUG - [x] Improvement - [ ] Documentation - [ ] Feature - [x] Test and CI - [x] Code Refactoring issue matrixorigin#26941 Defines one explicit SQL ordering relation for scalar `FLOAT` and `DOUBLE`: - ASC: `-Infinity < finite values < +Infinity < NaN` - DESC: `+Infinity > finite values > -Infinity`, with NaN still last - all NaN payloads are ordering peers, so later ORDER BY keys break their ties - `-0` and `+0` are ordering peers - NULL placement remains controlled independently by the existing NULLS FIRST/LAST flags NaN and infinities remain stored values. This change does not convert NaN to NULL, change scalar predicate semantics, or migrate physical/storage ordering. The SQL full-sort, Top, MergeTop, MergeOrder, and window peer-partition paths now share this relation. Generic comparison and storage sorting retain their existing contracts through separate entry points. Regular secondary-index hidden keys are not proven to have the same ordering at NaN boundaries. For a logical float sort key, the optimizer therefore keeps the logical Sort and suppresses hidden-key ORDER BY substitution, cursor-range rewrite, reader-side LIMIT, and TopValue messaging. The index can still be used as an access path. - focused named regressions for both float widths, infinities, signed zero, multiple NaN payloads, NULL placement, secondary-key tie breaking, Top/MergeTop/MergeOrder, window rank peers, and planner typed state - public SQL regression: `test/distributed/cases/optimizer/float_nan_order.sql` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=240s ./pkg/container/types ./pkg/compare ./pkg/partition ./pkg/sort ./pkg/sql/colexec/order ./pkg/sql/colexec/top ./pkg/sql/colexec/mergetop ./pkg/sql/colexec/mergeorder ./pkg/sql/colexec/window` - `.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -timeout=300s ./pkg/sql/colexec/aggexec ./pkg/sql/plan` --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: XuPeng-SH <[email protected]> (cherry picked from commit 99f4da5)
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
iamlinjunhong
left a comment
There was a problem hiding this comment.
已基于 4.2-dev 的当前 base 05f8a29 审查 head 1bdf8a6 的完整 diff、相关执行/优化调用链和测试。未发现 P0/P1/P2/P3 问题。
重点核对了:
- FLOAT/DOUBLE 的 SQL 排序关系在 full Sort、Top、MergeTop、MergeOrder、ordered aggregate 与 window peer/RANGE 路径中的一致性;
- 通用比较与物理/存储排序仍保留原有契约;
- 二级索引隐藏键、reader LIMIT、cursor range 与 TopValue 在 float 排序键上的保守禁用;
- 4.2 分支独立 PARTITION 节点下的 window backport 适配;
- NaN payload、±Inf、signed zero、NULL、次级排序键及索引访问回归覆盖。
当前 27 个 checks 均已结束,无失败项。隔离 worktree 未重新生成本机缺失的 libmo/third-party native artifacts,因此没有把本机非代表性的 CGo 编译作为额外通过证据。
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep review completed against exact head 1bdf8a624fdcf8e4003d2118c3fe44e050f677e6 (base 05f8a2938df56e8911701fe0276a37a0b2832f22). No blocking correctness, completeness, unhappy-path, or performance issue found.
Verified the explicit scalar FLOAT/DOUBLE SQL order is a transitive total preorder with NaNs last in both directions, all NaN payloads and signed zero as ordering peers, and NULL placement remaining independent. The relation is consistently wired through full Sort, Top, MergeTop, MergeOrder, multi-key peer partitioning, window rank/RANGE boundaries, and the 4.2-specific window shape. Generic/storage ordering remains unchanged. Planner handling conservatively keeps the logical float sort and disables hidden-key substitution, cursor/reader early LIMIT, and TopValue messaging while retaining secondary indexes as access paths.
Validation at this exact head:
git diff --check: pass- full affected package tests:
pkg/container/types,pkg/compare,pkg/partition,pkg/sort,order,top,mergetop,mergeorder,window,aggexec, andpkg/sql/plan: pass - focused NaN/float-order tests under
-race -count=5: pass go vetfor all affected packages: pass
Hot-path impact is bounded to scalar float SQL ordering comparisons (no allocation or unbounded state); integer/non-SQL/storage sort paths are unchanged.
Merge Queue Status
This pull request spent 41 seconds in the queue, including 3 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #26941
Backport of #26956 to
4.2-dev.What this PR does / why we need it:
Backports the explicit SQL ordering relation for scalar
FLOATandDOUBLE:-Infinity < finite values < +Infinity < NaN+Infinity > finite values > -Infinity, with NaN still last-0and+0are ordering peersThe 4.2 full-sort, Top, MergeTop, MergeOrder, and window/range paths use this SQL relation. Generic comparison and storage sorting keep their existing contracts. Regular secondary indexes remain access paths for float keys, but cannot replace the logical sort or drive early LIMIT because their encoded NaN ordering is not SQL-equivalent.
Release-branch adaptation:
4.2-devdoes not contain main's PartitionTopN reducer/operator contract, so those two source/test files and their PartitionTopN-only window cases are intentionally omitted rather than resurrecting a removed subsystem.Validation:
pkg/container/types,pkg/compare,pkg/partition,pkg/sort,pkg/sql/colexec/order,top,mergetop,mergeorder,window,aggexec, andpkg/sql/plango buildandgo vetagainst 4.2's locally built CGo/third-party artifactsgit diff --checkpasses(cherry picked from commit
99f4da5a092895fad6123a1862cf5e067e89a397)