Skip to content

Fix Cartesian DML memory planning and transient statistics reuse - #29527

Merged
XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue29497
Oct 1, 2026
Merged

XuPeng-SH merged 10 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue29497

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement
  • Test and CI

Which issue(s) this PR fixes:

Fixes #29497
Fixes #29533
Fixes #29534
Fixes #29529
Fixes #29530

What this PR does / why we need it:

Unconditioned INNER JOIN must multiply the already-filtered child cardinalities. The previous join-key selectivity formula underestimated Cartesian INSERT sources and could admit resident RIGHT DEDUP maps beyond the query memory budget. Correct multiplication also exposed severe small-write regressions when both sources used the default 1,000-row estimate.

Implementation and ownership

  • Preserve Cartesian multiplication, including empty inputs. Admit coexisting resident RIGHT DEDUP map estimates only within half of a positive query cap, regardless of automatic or explicit spill thresholds. Existing runtime allocation and shuffle/spill remain responsible for actual capacity.
  • Derive conservative transient observations at the existing relation owner from snapshot-visible partition memory/object metadata and target-table INSERT metadata. Published statistics, committed Rows/Size, compiler cache fences and ordinary/prepared rebuild paths retain their existing owners. Unknown observations fail conservatively; completed read-only statistics retain the fast path.
  • Keep row and byte estimates coherent: scale transient byte totals without modifying published maps, discard incomplete/overflowing combined totals after all merges, and reuse the same scaling owner for remote anonymous promotion. Fix directional RIGHT SEMI estimates after physical swap.
  • Saturate integer execution hints and bound speculative AUTO_INCREMENT reservation to one configured cache range. Actual batch demand retains its existing allocation path.
  • Correct BOOL maximum calculation and provide conservative private read views for ambiguous historical metadata while retaining precise raw writer serialization. Successful normalized vector AUTO/PREFILTER changes invalidate existing ordinary plans and mark prepared handles for their existing rebuild.
  • Consolidate eleven duplicate remote-expression placement checks into one discovery of the current expression generation and one strongest protocol requirement per selected worker. Delete the replaced methods; retain independent send-time destination checks, local legacy-interval rejection, cancellation and conservative fallback.
  • Check hidden-expression getter/rewriter method ownership before reflection boxing, avoiding copies of unrelated mutable runtime structs. Existing value/pointer expression owners and exported expression traversal remain supported.

No additional statistics cache, per-table counter, expression-generation state or alternate execution path is introduced. Remove obsolete compiler traversal and dead Cartesian/minimal-statistics branches.

Validation

Current reviewed head: c4d42883408cf4a62fc46046a7616857bdad81cc.
Current base/merge-base: 52eecb55bee9b55e776d09c64dfbaa55d5db8f1f (main).

Exact-head results

  • CI run 36831308751: Build, Ubuntu UT, UT Coverage, Coverage, Linux/arm64 SCA, PROXY multi-CN BVT, PESSIMISTIC multi-CN BVT and CI Required all succeeded. Skipped jobs are not counted as passes.
  • Direct review additionally ran four focused compile tests with -race -v -count=1: worker/expression-generation changes, local rebind/errors, private shared-state traversal, and hidden-expression private copies. All four passed (1.207s). Complete-diff whitespace check passed.
  • Direct latest-head review found no newly verified blocking correctness or design defect. The prior combined/remote byte-coverage comment is fixed in source; its GitHub review thread remains unresolved. Earlier GPT-6.1-sol/xhigh design and independent QA evidence is scoped to the revisions documented below; the latest direct review used no subagents.

Retained integration evidence

The linked validation record identifies source/binary provenance for earlier package/race/incremental-SCA checks and real SQL/JDBC tests. These cover own-write growth and unrelated-write isolation, ordinary/prepared reuse, duplicate-key atomicity, rollback/follow-up, durable AUTO_INCREMENT offsets and restart, wide-row planner consumption, and snapshot visibility.

Earlier real 1.2M-row tests at a 64MiB query cap pass with/without PK and default/accurate statistics, with automatic spill and full content/error oracles. Thirteen affected BVT scripts pass twice locally (2,508 statements per round); publication completes before fixture statistics are patched, and range, REUSE and nonzero-spill assertions remain. These historical results retain their recorded revision/topology scope.

Performance and remaining limits

The placement-consolidation binary was compared with main and its pre-optimization head in three matched, counterbalanced rounds: one CN/local NVMe, 64MiB query cap, max_dop=2, 5-by-8 source rows, 63 scenario-phases and 8,280 timed statements. Pooled medians:

Scenario Main (ms) Optimized (ms) Optimized/main
Accurate CROSS GROUP 0.399 0.409 1.026x
Accurate INSERT 9.268 8.922 0.963x
Accurate REPLACE 7.748 8.340 1.076x
Default CROSS GROUP 0.462 0.429 0.929x
Default REPLACE 9.943 9.876 0.993x
Stale-high CROSS GROUP 0.406 0.493 1.214x
Stale-high scan 0.232 0.250 1.078x
  • Stale-high CROSS GROUP improves 46.4% against the pre-optimization head; repeated feature discovery falls from 40.7% to 6.47% of sampled CPU. It remains 21.4% / 0.087ms above main with corrected estimates and existing AP_MULTICN placement.
  • Accurate REPLACE remains 7.6% / 0.592ms above main, with a positive delta in all three rounds; its cause is not established. These results do not justify a zero-regression claim.
  • The final reflection-race repair has focused race, actual consumer and rebuilt-binary SQL/profile evidence, but no refreshed complete matched write matrix. The table remains scoped to the placement-consolidation binary before that repair. The latest direct review did not independently rerun this performance matrix.
  • Writing-workspace observation is linear in existing metadata entries (previously measured at approximately 1.093ms for 100k entries). Legacy all-false BOOL metadata can require extra reads because old mixed/all-false writer provenance is indistinguishable.
  • GPU validation, original 300M-row reproduction, cold-S3 and high-concurrency/multi-CN performance remain unverified. Iceberg CI is outside the requested scope.

Complete branch increment

Relative to the current merge-base:

Category Added Removed Net
Production implementation 586 472 +114
Unit tests 1,350 42 +1,308
BVT and expected results 298 74 +224
Documentation 647 0 +647
Total (84 files) 2,881 588 +2,293

Implementation, tests and documentation were reviewed separately. Tests retain distinct real-consumer, boundary and unhappy-path oracles; documentation still offers room to reduce historical narrative.

Current v11 contract · Validation, provenance and measured limits

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added kind/bug Something isn't working kind/test-ci labels Sep 30, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Sep 30, 2026
@XuPeng-SH XuPeng-SH changed the title fix(plan): preserve Cartesian join cardinality for insert planning fix(plan): correct Cartesian estimates and bound resident dedup maps Sep 30, 2026
@XuPeng-SH

XuPeng-SH commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor Author

更新:CI 根因修复已提交到 8bd0b30a2c732bd78d5c67c17772ecd7c7dea328,取代此前 91e413 的失败提交。

  • 修正 BOOL min/max 最大值误用 AND 导致的错误持久化范围,并在现有 objectio 读取职责兼容旧范围;clean-main 对照证明原始 producer 缺陷已存在。
  • 修正 AUTO/PREFILTER SET 后普通及 prepared 计划未失效;保留 mode-off 空结果,覆盖同 SQL 和同参数化 handle 连续切换。
  • 修复统计异步发布覆盖 shuffle/spill 注入值的测试前置条件;保留 range、REUSE、非零 spill 和内容断言。补全 Adaptive Top 发布统计条件、明确 window frame 排序,仅更新审查过的 EXPLAIN 成本预期。

最终生产构建和增量 lint(0 issues)通过,CPU owning packages、cache race、vet 通过。13 个受影响 BVT 脚本在正常本地拓扑连续两轮各 2,508/2,508,通过后 catalog 清理及服务退出正常。这不代表完整 PROXY/PESSIMISTIC CI 拓扑通过。GPT-6.1-sol / xhigh 完整源码及 CPU 证据评审无未解决代码 blocker。

GPU 整套验证 NOT VERIFIED:当前无 CUDA/GPU;用户明确要求立即推送,覆盖本次技能前置门禁,不把该项记作 PASS。按要求不等待新 CI,Iceberg 不在范围。

版本化设计和根因 · 验证、性能及未验证范围

@XuPeng-SH

Copy link
Copy Markdown
Contributor Author

Latest-head deep review

Reviewed head c4d42883408cf4a62fc46046a7616857bdad81cc against base/merge-base 52eecb55bee9b55e776d09c64dfbaa55d5db8f1f.

Conclusion: the current code is approvable. No newly verified blocking correctness or design defect was found. This does not mean all performance concerns are closed. This was a direct read-only review without subagents.

Design and previous-comment closure

  • Statistics remain owned by the relation; publication, compiler cache fences, ordinary/prepared rebuild, runtime allocation/spill and durable auto-ID allocation retain their existing owners. No second statistics cache, persistent counter or execution state machine was introduced.
  • Eleven repeated expression-placement methods were removed in favor of the existing feature-discovery/protocol-probe owner. Independent send-time destination validation remains, including mixed-version, cancellation and conservative fallback boundaries.
  • The previous combined/remote byte-coverage finding is fixed in source: incomplete coverage remains invalid after later merges, remote promotion reuses the same scaling helper, published maps remain immutable, and tests reach the real planner width consumer. The original review thread is still not marked resolved.
  • Tests retain actual result, duplicate-key atomicity, rollback/follow-up, spill, durable-ID and concurrency/error oracles. The inspected BVT repairs do not weaken those assertions.

Nonblocking follow-ups and qualifications

  1. Accurate REPLACE regression remains unexplained. The documented three-round matrix reports 7.748ms on main versus 8.340ms after optimization (+7.6%, +0.592ms), with a positive delta in every round. Stale-high CROSS GROUP improves 46.4% against the pre-optimization head but remains +21.4% / +0.087ms above main. These are author-recorded measurements, not an independently rerun matrix in this review. The final reflection-race repair has no refreshed complete matched write matrix. Retain these limits and investigate the REPLACE cause rather than claiming zero regression.
  2. Presentation needed synchronization and can be reduced further. The old PR body referenced an earlier head, growth, performance figures and CI status; it has now been updated to this reviewed head. The implementation contract can still trim approval/CI history while retaining current behavior, provenance and limitations.

Complete branch growth was examined separately:

Category Net lines
Production +114
Unit tests +1,308
BVT / expected results +224
Documentation +647
Total +2,293

Validation

  • Exact-head CI run 36831308751 succeeded for Build, Ubuntu UT, UT Coverage, Coverage, Linux/arm64 SCA, PROXY and PESSIMISTIC multi-CN BVT, and CI Required. Skipped jobs are not passes.
  • This review independently ran four focused compile tests using -race -v -count=1: TestRemoteExpressionPlacementRechecksGenerationAndWorkers, TestRemoteExpressionPlacementLocalRebindAndErrors, TestVarExprTraversalDoesNotCopySharedPrivateState, and TestFoldVarExprsInHiddenExpressionsUsePrivateCopies. All four passed (1.207s).
  • Complete-diff whitespace check passed. Earlier integration/capacity/persistence evidence remains scoped to the revisions and environments recorded in the validation document.
  • GPU, the original 300M-row reproduction, cold-S3 and high-concurrency/multi-CN performance are not established by this review.

This publication only updates PR metadata and records the completed review. It adds no commit and requests no CI or test rerun.

This branch was previously deployed

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

Labels

kind/bug Something isn't working kind/enhancement kind/test-ci size/L Denotes a PR that changes [500,999] lines

Projects

None yet

3 participants