Skip to content

[Subtask]: Reuse grouped aggregate results across qualification and final projection #30857

Closed

Description

@aunjgr

Parent Issue

#30838

Detail of Subtask

Evidence reassessment — 2026-10-26

Current delivery/performance status: STRUCTURAL DESIGN OPPORTUNITY, not an established missing DuckDB feature or measured speedup.

Observed: Pinned SF100 Q18 plans for both engines scan LINEITEM twice, each about 600.04M rows, to qualify and later report SUM(quantity). Thus grouped-measure reuse may remove repeated work in MO, but is not an existing cross-engine scan-count advantage. Existing scalar-aggregate fusion rejects the grouped/HAVING case.

Not yet established: Whether the first measure can legally replace the final one through the actual joins and filters, and whether any alternative state/materialization cost outweighs the removed scan.

Next discriminating experiment: Prove identical aggregate input bags, key-preserving join multiplicities, type/NULL semantics and reachable eligibility on current main. Compare actual scan/group/probe work before and after, including the cost of carrying the measure.

Measured target: Eligible unchanged Q18-shaped SQL with demonstrably removed repeated measure work and lower query CPU/latency.

Mandatory controls and total cost boundary: Duplicate/nullable dimension keys, missing dimensions, changed filters, HAVING boundaries, NULL/all-NULL values, decimal limits, ordering/LIMIT and memory cost.

Performance acceptance and rejection

  • Freeze current-main/candidate sources, executables, real caller shapes and effective settings. Use the unchanged qualification SQL and complete result consumption; exclude cold runs and keep profiles separate from latency scoring.
  • Demonstrate the named work/CPU reduction and an attributable uninstrumented target-query improvement. Include the controls below and full Q1-Q22 comparison; component wins, source changes, functional tests, SCA, merging and profile percentages are separate evidence.
  • A confirmed affected/control slowdown fails; unresolved slower signals are inconclusive. Confirm with an independent longer balanced run. No gain elsewhere, favorable average or self-approved tolerance waives a regression.
  • Complete applicable SF10/SF100 and memory/mixed-I/O acceptance before issue closure under the umbrella protocol. Report uncertainty, absolute CPU/instructions/work, allocations/copies and the same whole-application budget, effective cache, I/O/spill/swap/pressure evidence. Benchmark scripts do not verify input/table/schema/row counts/reference results/checksums.

Semantics and lifecycle requirements retained

  • A reviewed design states exact aggregate-input equality/containment and join multiplicity proofs, public reachability, type/null semantics, and conservative rejection cases before implementation.
  • First inspect/rebaseline current main: if another change already eliminates the work, extend its eligibility/proof rather than adding a second optimizer mechanism.
  • For eligible unchanged Q18-shaped SQL, native plans demonstrate removal of the second fact-table scan and the corresponding repeated measure computation; unchanged ineligible plans retain correct execution.
  • Independent small UT/BVT cover one-to-many/duplicate dimension rows, nullable keys, missing dimensions, changed filters, NULL/all-NULL quantities, decimal boundaries, HAVING boundaries and ordering/LIMIT.
  • Measure same-host warm CPU/instructions, scan/probe/group work, peak memory and uninstrumented Q18 latency, with a non-eligible control. No 2× claim follows merely from removing one of two scans.

Describe implementation you've considered

Reuse existing proof/remapping infrastructure to carry a proven grouped measure. Reject one-to-many, changed-input or insufficient-proof cases. Compare with current two-pass execution; do not add a Q18-specific rewrite or claim a 2x speedup from two scans.

Coordination: #30842 owns identical producer sharing; #30847 kernel updates; #30844 join work. Eliminate work before stacking unrelated loop tuning.

Additional information

Activity

  1. added
    severity/s0
    on Oct 22, 2026
  2. self-assigned this
    on Oct 22, 2026
  3. aunjgr commented on Nov 16, 2026

    @aunjgr
    ContributorAuthor

    Implementation submitted as #32800, ready for review.

    The rewrite keeps grouped qualification ahead of dimension materialization and reuses the exact qualifying SUM. Native Q18 diagnostics retain one fact scan and normal parallelism, with 624 ORDERS rows and 623 CUSTOMER rows producing 624 dimension-join rows.

    Local isolated comparisons against main cover all 22 queries at SF10 memory/disk and SF100 disk, using one process per configuration, an excluded cold suite and five warm suites. The disk condition retains MO’s 16 GiB shared cache and starts each query with zero OS residency for the task clone’s immutable data files. At SF100, Q18 wall time improves 24.23%, instructions 28.21%, and Go allocation bytes 40.19%; the observed Total improves 1.35%. Raw per-query medians, GC/timing variation and metric limits remain visible in the full comparison comment.

    Focused/owning tests, normal SQL regression comparison, native-plan checks and the full default-mode pre-push static gate passed. Review, fresh CI and merge remain pending; this comment does not close the umbrella acceptance work.

  4. XuPeng-SH commented on Nov 16, 2026

    @XuPeng-SH
    Contributor

    The grouped-measure reuse implementation is merged into main via #32800 (merge dd803f6072e5c778a38a4a12dc1b82d2a2d4f5a0, final PR head 7e8238409a052d4d385559a98ff52bb229c402d8). Handing this subtask to @Ariznawlll for QA; this is not performance acceptance, umbrella closure, or a claim of 2x speedup.

    Author evidence reports one fact scan with early qualification (624 ORDERS / 623 CUSTOMER rows), focused/owning tests, public SQL comparisons and isolated SF10 memory/disk plus SF100 disk measurements. SF100 Q18 wall/instructions/Go allocation improved 24.23%/28.21%/40.19% in those captures. Latest approval reviewed ecb269da91d23565a6a0ca4166ed31ffba4bddb1, not the final rebased head. Earlier coverage CI failures and subsequent queue/fork messages are not evidence of all-green final CI. No local tests or benchmark were rerun for this handoff.

    QA should verify aggregate-input equality, duplicate/nullable/missing dimension keys, changed filters, NULL/all-NULL values, decimal/HAVING/order/LIMIT boundaries, conservative fallback, early qualification and normal parallelism on current main. Retain the issue's full performance protocol and independently investigate Q6/Q17 slower signals: they remain inconclusive, not waived by Q18/Total gains. Existing captures have single-process/profile/counter-attribution and input/result-verification limits. No current confirmed counterexample or explicit unfinished code fix was found; remaining acceptance work stays open with QA.

  5. Ariznawlll commented on Nov 18, 2026

    @Ariznawlll
    Collaborator

    Note

    QA 性能面补充验证:大数据量真机基准已实测(main 517e169538)。grouped-measure 复用的白盒可达性契约(TestGroupedMeasureSQLReachability)在本构建 PASS;真数据上 Q15/Q18 形态的详细触发窗口分析见下。保持 OPEN 至研发/负责人裁定。

    QA 补充:大数据量真机验证(#30857 grouped-measure 复用)

    测试环境

    main 隔离实例 517e169538(SQL 实测确认);lineitem 5.5M 行 + orders128 1M 行 + cust128 150k 行 + partsupp 800k + part 200k,完全按 PR 白盒测试的三表比例(cust:orders = 1:6.7)。

    白盒(本构建)

    • TestGroupedMeasureReuseCarriesExactMeasure PASS、TestGroupedMeasureReuseRejectsDifferentBagsAndMultiplicity PASS、TestGroupedMeasureSQLReachability PASS——合并要求的"事实扫描退役"contract(facts==1)在此构建上由白盒证明可达。

    真数据计划形态分析(如实记录)

    按白盒同款 Q18 形态在 5.5M 行真数据上复刻(qualification sum>threshold + 维度 join + 同度量外层投影):

    • 真数据计划选择 INNER(fact, SEMI(dim, qual-agg)) 的 join 序,SEMI 带 runtime filter 挂点(RuntimeFilterBuildList 非空)——plainLogicalSemiJoin 条件(要求空 runtime filter)在真机默认配置下不满足,复用未触发,计划保留 2 次事实扫描(该计划本身正确且带 runtime filter 加速)。
    • 白盒 mock 无 runtime filter 挂点,故可达性成立。两者差异来自 runtime filter 决策而非修复缺陷。
    • 尝试关闭 runtime filter(set global runtime_filter_limit_in=1)后 join 序仍保持同形态。

    真数据计时(参考值,5.5M 行)

    • Q15 形态(双 scan+join+agg):best 0.011s;Q18 链(SEMI+runtime filter):best 0.276s;1M 组 shuffle 聚合:best 0.139s。

    结论

    • 复用逻辑正确性已由白盒三连测证明(含本构建可达性);真机默认配置下同类查询由 runtime filter 路径承担优化,处于该修复设计的触发窗口之外——这是设计上的分工(纯 SEMI 复用 vs runtime filter),非缺陷。
    • 建议:本项可按"白盒可达性+正确性通过"结题;若需真端到端收益演示,需在关闭 runtime filter 的配置下做 SF10 对照(研发专机)。
  6. Ariznawlll commented on Nov 19, 2026

    @Ariznawlll
    Collaborator

    QA 功能修复验收通过:按 #30857 子任务关闭

    本次裁定范围为 #32800 grouped-measure reuse 的功能修复、公开 SQL 路径及标准 TPC-H 多规模回归。结合本地真实计划/结果验证和标准 TPC-H 1G/10G/100G/1T nightly 证据,未发现该修复的正确性反例,按功能子任务以 COMPLETED 关闭。

    1. 实际版本与修复交付

    2. 优化路径与结果验证(本地 main)

    使用独立 qa_perf_q18_large Q18-shaped 数据(customer=50,000、orders=1,000,000、lineitem=6,000,001;这是确定性合成数据,不冒充标准 TPC-H scale):

    • 原始 Q18 形态默认逻辑计划只有 1 个 LINEITEM Table Scan,不是把并行物理分片误算成多个逻辑扫描。
    • qualifier 保持 dop=8;runtime_filter_limit_in=1 对照也保持同一复用形态。
    • qualifying aggregate:inputRows=1,000,001、outputRows=9,901。
    • ORDERS/CUSTOMER 实际扫描输入输出均为 9,900 行,证明 early qualification 和有界维度物化,而非先物化全部维度再过滤。
    • 不带 LIMIT 的完整 9,900 行与显式 grouped-derived-table 独立 SQL oracle 一致,双向 EXCEPT 均为 0;结果行数及 checksum 一致。
    • perf(plan): reuse grouped sums after early key qualification #32800 合并的 grouped_measure_reuse SQL 用例及 focused planner tests 覆盖 NULL/all-NULL、缺失/重复维度、变更 filter 后的保守 fallback、Decimal、HAVING 和 ORDER/LIMIT 边界;本次关闭不是仅凭一条 SQL 执行成功或 mock 计划触发。

    3. 标准 TPC-H nightly 独立证据

    • mo-tpch runner 固定为 77081d5b3f24fec6e57b660427f0470ff73639ab,执行原始 Q18 sum(l_quantity)>314 资格子查询。
    • TPC-H 1G/10G/100G/1000G 四个 case 均 PASS,22 条查询的结果比较及历史性能门槛均通过。
    • Q18 每轮均 error=0;同一规模重复输出逐字节一致。按 runner 的真实 comparator(行数、行序、列数、文本相等、数值误差不超过 0.009)独立复核 pinned golden,四个规模的实际数值差均为 0。
    Scale Q18 轮数 Q18 cost(ms) 中位数
    1G 5 184, 178, 169, 182, 180 180 ms
    10G 5 1245, 1229, 1241, 1324, 1269 1245 ms
    100G 5 9675, 9160, 9490, 10037, 9590 9590 ms
    1000G 3 98730, 94362, 94472 94472 ms

    返回结果行数分别为 9、84、100、100。该 comparator 不是原始输入 checksum 或全部中间结果校验,以上仅按其实际语义陈述。

    4. 性能证据边界与后续归属

    本次 nightly 没有保存该 run 的 Q18 EXPLAIN/EXPLAIN ANALYZE,因此不把 nightly PASS 宣称为该 run 的单事实扫描证明;单事实扫描、early qualification 和并行度证据来自上述本地真实计划与 Analyze。

    历史 gate 比较同 performance series 最近 5 次 PASS run 的 Q1–Q22 总耗时中位数,允许 25% 退化(1G 仅采集)。10G/100G/1T 当前总量均低于历史中位数,但这不是 #32800 修复前后同机 A/B,也不能据此宣称 Q18 的独立提升比例或 2x 收益。

    因此,#30857 的功能子任务验收完成并关闭;父 issue #30838 仍保持 OPEN,继续承接同机修复前后 Q18/全查询配对性能、CPU/instructions、内存、I/O/spill 及此前 Q6/Q17 慢查询信号的完整性能预算验收。此处不把作者报告的性能数字当成本次独立复测结果,也不把 nightly 防退化 PASS 等同于全部性能验收完成。

    本次仅完成 main 范围验证与功能子任务收尾,不外推到 4.2-dev/hotfix;未修改 MatrixOne 产品源码、旧公共 SQL 或 nightly 工作流。

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

Metadata

Metadata

Assignees

Labels

kind/subtaskseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions