Skip to content

[Bug]: Group capacity recovery reevaluates partially committed input batches #32369

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

89ca3dbbf6d594d7614b8e1ca80f6b0300ed3cd2

Other Environment Information

Linux/amd64, Go 1.27.1, accounted Group execution with local spill enabled. The deterministic reproduction below exercises the real Group operator, allocation account, and spill/reload path; it does not claim a separately reproduced public SQL failure.

Actual Behavior

When a retryable allocation-capacity error occurs after Group has committed a prefix of an input batch, it spills the resident groups and evaluates the entire batch again. The already committed prefix still reflects the first evaluation, while the remaining rows use the second evaluation. Volatile or side-effecting group expressions or aggregate arguments can therefore return incorrect results and perform extra side effects.

In a deterministic 512-row test, a real account allocation is rejected after the first 256 groups have been committed. An incrementing group expression is evaluated twice, performs 1,024 side effects, and the output keys are 1..256 and 769..1024 instead of 1..512. A capacity error during initial expression evaluation can also cause previously evaluated expressions to be replayed.

Expected Behavior

A successfully evaluated input batch should keep the same group and aggregate argument values throughout pre-publication capacity recovery. A partially evaluated batch must not be replayed when the engine cannot prove that doing so is safe.

Steps to Reproduce

Use a separate worktree so the reproducer does not modify an existing checkout. The test file from the linked PR can be run against the affected base:

git fetch origin pull/32368/head
git worktree add --detach /tmp/mo-group-capacity-repro 89ca3dbbf6d594d7614b8e1ca80f6b0300ed3cd2
cd /tmp/mo-group-capacity-repro
git restore --source=FETCH_HEAD -- pkg/sql/colexec/group/capacity_retry_evaluation_test.go
.agents/skills/mo-dev/scripts/mo-cgo-test -count=1 -run '^TestGroupCapacityRecoveryRetainsEvaluatedInput$' ./pkg/sql/colexec/group

With the project's normal CGo prerequisites available, the base test fails because expressions are evaluated twice; the linked PR passes the same regression. The test uses the existing allocation controller to reject a real allocation and verifies actual spill/reload.

Additional information

The failure was discovered while investigating #32060, but it is separate from that issue's integer DISTINCT performance report. Proposed fix: #32368. The PAD SPACE grouping and primary-key/functional-dependency issues discussed during the investigation are separate as well.

Activity

  1. added
    kind/bug
    on Nov 8, 2026
  2. XuPeng-SH commented on Nov 9, 2026

    @XuPeng-SH
    ContributorAuthor

    QA 交接(不代表验收通过)

    关联修复 #32368 已于 2026-11-09T00:29:13Z 合入 main,merge SHA:692b50a3614720e57d13d6521891d2d802bcf6b7。修复 Group 在已发布输入前缀后发生容量拒绝时重新求值整批输入的问题:保留已成功求值的输入向量和 grouping-set 标记,从尚未发布部分恢复;求值中途失败返回原错误,不重放可能有副作用的表达式。

    验证证据:作者报告当前 rebased tree 的完整 Group、共享资源预算包 normal/race(matrixone_test)及 Group/compile 静态检查通过;真实分配拒绝、adaptive spill、H0 DISTINCT、发布后终止错误和失败恢复后的 Reset/Prepare 复用控制覆盖结果与账户、spill 磁盘、文件描述符清理。原实现的重放回归及 adaptive 回归失败、修复后通过。评审在 c0c5455 的结论为 approve,未提出待完成开发项;评审未运行成功的 Go 测试,原始作者日志也未提供。本次仅核对远端记录,未本地实测。

    验证限制:旧头的 HAKeeper/CDC 与 CN heartbeat CI 超时本地未复现,未完全归因,不能宣称 CI 全量通过;评审记录时新头核心 CI 仍 pending。较早的双 CN(同一进程)SQL/性能样本未全部在 rebase 后重跑,SpillRows 不能单独证明触发容量恢复,微基准不是生产性能保证。

    建议 QA 优先用真实账户容量拒绝复核部分发布后 volatile/副作用表达式只求值一次、精确键和聚合值;覆盖 ROLLUP、partial Group/MergeGroup、DISTINCT、borrowed vectors、二次拒绝、求值失败及资源释放/复用。保留输入会占用内存到批结束,极端压力下原来重放纯表达式可完成的查询可能改为容量错误,这是明确边界。普通 spill/merge/reload 生命周期及多 CN 压力可补充回归。#32060 性能、PAD SPACE 和主键/函数依赖问题不在本修复范围,不据此判定完成。

  3. MatrixAdventurer commented on Nov 9, 2026

    @MatrixAdventurer
    Contributor

    分级建议:
    severity/s2 —— 容量恢复路径曾对已发布批次重复求值,带副作用/非幂等表达式时结果不确定,正确性缺陷,但需容量误差与该类表达式同时出现,面窄;修复 #32368 已入 main,剩验证收尾。
    模块:pkg/sql/colexec/group。
    疑似重复:未发现。
    建议负责人(/pkg/sql/colexec CODEOWNERS):XuPeng-SH/aunjgr/aptend;验证由 assignee Ariznawlll 跟进。
    本操作由LW授权的MOI智能体提交

  4. slyunnn commented on Nov 9, 2026

    @slyunnn

    Regression and extended verification for #32369 (2026-11-09)

    Verification Environment

    • Frozen MatrixOne origin/main at test start, 6a2b29954749d5a47820ed429cfa8a6c4793682f — fix(parser): allow native PREPARE of DESC/DESCRIBE (#32399). A fresh native build, binary metadata and SQL git_version() agreed.
    • Go 1.27.1, macOS arm64 and Linux amd64 component execution with matching native dependencies and matrixone_test for the Group/resource-budget tests.
    • Native SQL topology 2 CN / 1 TN / 1 Log service / Proxy. Both CNs shared the native launcher process. Proxy 127.0.0.1:6001, CN1 127.0.0.1:16001 and CN2 127.0.0.1:16002 were connectable and each executed regression SQL. PyMySQL used TCP COM_QUERY, existing BVT used JDBC.

    What Was Covered

    • OK — Original real-account rejection after a committed prefix of 256 groups in a 512-row batch. Actual spill/reload completed with one group-root evaluation, one aggregate-argument evaluation, exactly 512 row effects per expression, all keys 1..512 and exact aggregate values.
    • OK — ROLLUP, partial Group/MergeGroup, DISTINCT drain, borrowed input, adaptive spill and a second capacity rejection. Checked failed-recovery Reset/Prepare reuse and account, mpool, spill-disk and file-descriptor cleanup.
    • OK — Initial group/argument evaluation errors, post-publication errors and grouping-sentinel allocation failure remained terminal without expression replay. All 14 focused test/subtest results passed on both platforms.
    • OK — Complete Group and process packages passed normal and race execution, with 488 and 422 test/subtest passes respectively per mode, no failures or skips.
    • OK — On each SQL endpoint, compared all 513 group results over 16,385 rows against an independent oracle with max_dop=1 and 4, resident and spilling thresholds. Checked ROLLUP, empty/all-NULL inputs, invalid-column error 1054 and connection health.
    • OK — Existing Group BVT golden comparisons passed 46/46 statements on each endpoint. A temporary pre-fix production overlay failed the same direct regression with expression-call count 2 instead of 1.
    • Not covered — A separately demonstrated public SQL trigger for the exact allocation rejection, a TKE pressure campaign or production throughput SLA. Ordinary SQL spill evidence is supplemental to the direct account-controller reproduction.

    Findings

    Fix 692b50a3614720e57d13d6521891d2d802bcf6b7, fix(group): preserve evaluated inputs across spill retries, retains evaluated input during pre-publication recovery and returns partial-evaluation errors without replay. Retained input may reduce recovery headroom under extreme pressure, as documented by the accepted design. Fix PR #32368

    An independent native-build guard issue encountered during setup is tracked separately. Using an environment-variable cache setting allowed the unchanged target source to build successfully. Build issue #32420

    MOTR / BVT Coverage

    Reused capacity_retry_evaluation_test.go, the complete owning packages, qexec/group_h0_spill.sql and qexec/group_spill_max_depth.sql. Existing coverage directly detects the original defect, so no duplicate MOTR commit was added. SQL extensions ran concurrently in endpoint-specific databases. BVT ran serially because its runner performs shared database cleanup. All source worktrees remained unchanged and the owned topology was stopped.

    Final Conclusion

    Fixed on the tested main build.

    A capacity-boundary regression is required and completed using the minimum original 512-row fixture with deterministic rejection after 256 committed groups. The supplemental SQL fixture crossed batch boundaries. Further arbitrary data enlargement or a TKE big-data run is unnecessary for this defect.

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

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions