Repository navigation
Fix statistics-driven plan churn and predicate-aware join ordering - #29567
Conversation
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? |
XuPeng-SH
left a comment
There was a problem hiding this comment.
Review result
当前 HEAD 24528f7f682c6b826d2d177a932ba94772c01e04 的本地深度复核未发现剩余阻断问题。上一轮报告的 P1(复用 prepared UPDATE 后可能提交重复 UNIQUE 值)已在整数哈希迭代器的编码入口修复;真实 COM_STMT 测试覆盖 int、bigint、string 和 composite UNIQUE 冲突,均返回 MySQL 1062,并验证事务状态、提交/回滚及后续复用。
其余设计沿用已有职责:计划重建仍由已安装 generation 的统计准入控制;join 构建在估算前消费现有 pending predicate;没有新增并行状态机或约束校验路径。新增的错误/空批次/预览失效/重试白盒检查通过,普通和 nullable 整数键均由 fresh iterator 读回正确分组,mpool 归零。
代码评审无阻断项。完整 TPCC 吞吐、TPCH 1T 与多 CN 耗时尚无 A/B 结果;当前 CI 仍在运行,因此本评论不宣称这些性能目标已实测完成或 CI 已通过。
GitHub review state: COMMENT. 当前登录账号是 PR 作者,不能对自己的 PR 提交 APPROVE。
## What type of PR is this? - [ ] API-change - [x] BUG - [x] Improvement - [x] Documentation - [ ] Feature - [x] Test and CI - [ ] Code Refactoring ## Which issue(s) this PR fixes: Fixes #29399 on `main`; forward-ports the remaining fixes from #29431 (`4.2-dev`). ## What this PR does / why we need it: Repeated restore can mistake CLONE provenance or a view definition for legacy CHECK metadata, lose ownership/current grants, or preserve revoked authorization in an existing connection. Partial restore also treated a role name as identity: renaming an owner blocked restore, while reusing its old name could transfer DROP authority to a different role. - Preserve structured CHECK recovery; recognize CLONE provenance and exclude view definitions from legacy table CHECK parsing. - Recreate objects under historical creator/owner IDs. Partial restore validates and pins required live principals within their physical catalog generation. Role renames preserve identity; name reuse cannot acquire ownership. Table restore locks and retains an existing database without requiring its historical creator/owner. - Resolve partial restore's historical logical source once, including existing view dependency planning, before ownership checks and destructive DDL. Ownership lookup intersects that source after existing external-table and unservable-view omissions. Execution reuses the same objects and classifications; FK/master/publication guards can still reject or omit candidates. This prevents an irrelevant deleted view principal from blocking ordinary data restoration, without exempting servable views. Explicit external-table restore still rejects; skipped single-view restore preserves the live view. - Full account restore rebuilds principal catalogs and can rewind their auto-increment IDs. **Partial restore across rebuilt catalogs rejects ordinary custom principals before DROP, even if IDs/names match or full restore legitimately reconstructed them.** Only reserved bootstrap identities with verified IDs/names and required direct admin grants can cross that boundary. Use a point in the current catalog generation or full restore; documented in `docs/ai-skills/backup-restore.md`. - Keep principal pins and current scoped grant capture/rebinding in the existing restore transaction. DROP USER/ROLE use private pessimistic RC transactions to honor those locks even under ordinary optimistic SI. Partial restore preserves current grants; full/cross-account catalog rebuilding retains its mapping. - Apply existing DATA BRANCH authorization to ordinary-user CLONE, preserving administrator historical/cross-account behavior, subscription errors and recreated publisher identity mapping. - Recheck authorization in existing and text/binary prepared connections across CNs. Within one privilege evaluation, deduplicate only identical SQL misses while retaining ordered errors, early hits and role/view scope. An enum-bounded stack buffer satisfies SCA preallocation without suppression or extra persistent authorization state. The upstream merge at `54af0d38290c66b61ac78a46aa07a363eb576aae` is preserved, including #29563 ESQL and #29568 FULLTEXT2/HNSW coordinator placement. No force push, workflow change or merge-policy bypass. ### Validation Go 1.26.4 / macOS ARM64, verified native provenance. Latest source-selection correction (`93405cdc0ea`): - Authenticated public SQL regression covers snapshot/PITR, independently deleted view creator/owner, ordinary-table data recovery, skipped live-view ID/definition/result preservation, and servable-view missing-principal rejection before DROP. Existing external rejection, retained/recreated DB and unchanged principal-generation controls remain. - Ownership tests cover excluded raw physical metadata, required servable views/sequences and fail-closed missing ownership. FK lookup tests verify shared pointers and scope without fresh enumeration. - After preserving the upstream merge: full frontend **26.886 s**, all six `TestIssue29399*` public tests **31.475 s**, and configured incremental golangci-lint **0 issues**. The byte-identical correction also passed all six tests under race detection before the merge (**69.920 s**). Go vet and repository molint completed with exit 0; existing molint recover diagnostics outside changed code are retained. No linter suppression/configuration weakening. Unchanged evidence from the whole-PR review is retained: planner/compiler and V406 maintenance tests; prepared/cache/active-role controls; normal BVT comparisons including metadata (ownership/CLONE 125/125, builtin full-then-partial 213/213, cache 37/37, revoked-role 39/39). The inherited target merge separately passed compiler/index owning packages and two-CN FULLTEXT2/HNSW rebuild integration. Its initial `TestConnMeasuresDelayedBufferedFlush` timing failure remains recorded; isolated repetitions and subsequent full frontend passed without weakening assertions. ### Performance and limitations Partial source selection adds bounded name maps, uses existing view planning once and avoids repeated partial source enumeration. It adds no persistent state, catalog format, principal query per object or new lock. Current-dependent runtime guards can conservatively omit a prevalidated candidate; this change does not claim exact prediction of every dynamic FK skip. Existing matched public microbenchmark: reader p50 median **1.617 → 1.333 ms (~17.6% lower)**; admin **243.5 → 244.3 µs**, with comparable controls. These local measurements do not recover the old stale-cache roughly 80 µs latency or establish production throughput. Authorization code is unchanged by the latest source-selection correction. The latest correction's design and final overall review use actual **gpt-6.1-sol / xhigh**, reconciling the whole-PR evidence with the changed paths. The source-selection correction's remote CI remains distinct from the target synchronization below; skipped jobs are not passes. ### Prior target synchronization and CI Prior synchronization head: `b190162ef097987a71e9252a49266caaee810451`; target `main`: `401d153150d9076f84aaaf2a32cdcf880b478395`. Normal merge parents are the preserved live `93405cdc0eafd1d2ce15a65d75d5afe2d531b36a` and the new target. This closes the observed strict-baseline BEHIND condition without rebasing, force-pushing or changing Ready/base state. Only #29570's two prepared-DECIMAL SQL/result files change relative to the first parent, byte-identically to the target; every other tracked file is unchanged. The existing source selection, ownership, current-grant transaction, authorization implementation and disclosed performance limits are preserved. Fresh monitor-local exact-merge binary build passes. The new upstream prepared-DECIMAL case passes strict JDBC metadata validation **213/213**, with named database cleanup zero (macOS ARM64 / Go 1.26.4 / Java 20). Independent read-only mechanical merge review approves and whitespace/worktree checks are clean. The prior `93405cdc` frontend/public/race proof above is external local unchanged-Go evidence, not a fresh whole-suite execution or current-head remote CI pass. No source-branch cache-certificate or internal-executor fix is blindly copied to main. XuPeng-SH approved `93405cdc` at 14:21 UTC after whole-PR follow-up; this is an actual submitted review, not the local mechanical approval. Prior-head Connector/J run [37015828472](https://github.com/matrixorigin/matrixone/actions/runs/37015828472) attempt 1 fails during ONNX Runtime download (HTTP 504), before the server/test. Exactly one failed-job rerun request was accepted. Attempt 2 / [110870725085](https://github.com/matrixorigin/matrixone/actions/runs/37015828472/job/110870725085) downloads the dependency and actually passes pool-reset tests for all four Connector/J versions at 14:07:46 UTC. That success belongs to `93405cdc`, not this new merge head. No healthy jobs or whole ALL CI run were rerun/cancelled and no build/workflow/tester/business workaround was added. That head's Connector/J [37023553819](https://github.com/matrixorigin/matrixone/actions/runs/37023553819) actually succeeds at 15:01:50 UTC; ALL CI remains unfinished when it is superseded by the next target merge. This is historical evidence, not a result for the current head. ### Prior target synchronization and validation Prior head: `380bbce20601196b9c9b09ea48089bb666985857`; target `main`: `5a09e1ffbf40a59f50c55fe89e6f0c23eba143a3`. After main merges #29567, strict protection marks the previous head BEHIND again. A normal merge preserves parents `b190162ef097987a71e9252a49266caaee810451` and the new target, without conflicts, manual overwrites, rebasing or force push. Its 15-file delta matches the upstream commit exactly, including modes and blob IDs. All existing PR changes from the approved implementation remain intact. Inherited prepared runtime-plan statistics admission does not bypass schema invalidation or text/binary EXECUTE reauthorization; shared restore source selection, ownership preflight and current-grant transactions are unchanged. Fresh monitor-local exact-head proof (macOS ARM64 / Go 1.26.4): - Full frontend/plan/hashmap **-race passes: 34.982 s / 36.546 s / 3.344 s**. - All six authenticated `TestIssue29399*` tests pass (**29.908 s**), including the eight optimistic-SI privilege-removal arms, snapshot/PITR ownership and source-selection boundaries, principal pins and invalid-grant rollback. Upstream reordered-join semantics and prepared workspace visibility tests pass (**13.031 s**), including integer/bigint/string/composite unique controls. The test-only atomic output `[no statements]` is not production coverage. - Exact binary build and version `380bbce206` pass. Configured incremental lint across all five upstream changed package roots reports **0 issues**. Worktree and whitespace checks are clean. Independent read-only merge/integration review approves; it checks inheritance and interaction, not the general upstream statistics policy. A fresh OPEN/Ready/head guard was awaited and read before the accepted normal push. Latest current-head CI is newly triggered and not complete; no BVT, full coverage, required-context or merge-gate pass is claimed. Prior-head successes are not substituted for current-head results. No workflow, tester or source cache-certificate/internal-executor framework is copied into main. Existing performance limitations and the separate constant-view issue #29572 remain unchanged. ### Current target synchronization and validation Current head: `ae4460f455bafa98a5beb301906adbd0abc522b6`; target `main`: `9078a8bd87af49ea06f52e09d64e7740122aea61` (#29573 vector UnionOne/marshal). Strict-baseline BEHIND is addressed by a normal merge with first parent `380bbce20601196b9c9b09ea48089bb666985857`, without conflict, manual overwrite, rebasing or force push. The four-file delta is byte/mode-identical to the upstream delta; the original 43-file PR patch remains identical against the new target. Restore source selection, ownership/current-grant transactions, principal-generation restriction, protocol/DAG and authorization implementation are preserved. Independent exact-merge local proof (macOS ARM64 / Go 1.26.4, verified inherited native inputs and absolute CGo paths): - Complete vector/batch/mergeutil **-race passes (6.392 s / 3.393 s / 3.712 s)**; complete frontend/plan **-race passes (34.427 s / 34.374 s)**. - All six authenticated `TestIssue29399*` plus authenticated fixture configuration pass **under race (65.232 s)**, including all eight optimistic-SI privilege-removal arms. Another 28 objectio/hashbuild marshal, recovery/area and runtime-filter consumer tests pass **under race (2.722 s / 2.297 s)**. - Configured incremental lint in the two upstream changed package roots: **0 issues**. Exact-head binary build/version, gofmt, whitespace and worktree checks pass. Native/packaged binary artifacts are preserved; the exact-head validation binary is separate. - Independent read-only integration/mechanical review **APPROVE**, covering ownership/aliasing, NULL reuse, errors, marshal and restore/clone consumers. This is local correctness evidence for this merge, not a GitHub approval, full BVT/BigData, Linux/GPU proof or performance comparison. Test-only atomic `[no statements]` is not production coverage. A fresh OPEN/Ready/head/body guard is awaited and read before the accepted normal push. The source-only SQL-task principal follow-up is not blindly copied into main's unchanged adapter/authorization path. Existing performance limitations and separate constant-view issue #29572 remain. Current exact-head [ALL CI run 37034311275](https://github.com/matrixorigin/matrixone/actions/runs/37034311275), attempt 1, completes **SUCCESS** at **2026-10-02 17:51:19 UTC**. Actual Ubuntu UT, arm64 SCA, shared build, UT Coverage, PROXY/PESSIMISTIC multi-CN BVT, Coverage and CI Required all succeed. The [CI Required log](https://github.com/matrixorigin/matrixone/actions/runs/37034311275/job/110959138144) confirms `full` scope, generation `37034311275-1`, all five dependency groups successful and `coverage_ready=true` / `coverage_status=passed`. The [Coverage log](https://github.com/matrixorigin/matrixone/actions/runs/37034311275/job/110952754024) selects UT and both complementary BVT profiles from that same generation and publishes the merged result. Current-head Connector/J succeeds; Iceberg is **SKIPPED**, not a functional test pass. No failed-job or whole-run rerun/cancellation is performed this round. The PR remains **OPEN / Ready / MERGEABLE / BLOCKED / APPROVED**. The retained approval was submitted on the earlier `93405cdc` implementation; it is not a new review of this target-merge head. All four discussion threads remain unresolved, with no new human findings. Completed CI Required and test jobs do not establish that every review/protection requirement has been satisfied; no Ready/base/approval/merge or protection policy is changed. --------- Co-authored-by: XuPeng-SH <[email protected]>
What type of PR is this?
Which issue(s) this PR fixes:
Fixes #29564
Fixes #29565
What this PR does / why we need it:
Conservative workspace estimates can change after ordinary UPDATEs even when the business row count is unchanged. Exact equality invalidated otherwise reusable plans, repeatedly rebuilding logical plans, parameter metadata and compiled state. Join ordering independently estimated intermediate nodes before attaching their crossing predicates, causing Q9 to join unfiltered lineitem/orders too early.
Generation-anchored reoptimization
Ordinary positive finite observations may drift by less than a factor of two relative to the installed generation. Doubling or halving requires rebuilding; intermediate observations never slide the baseline. Prepared admission checks the installed specialization rather than its template. Existing schema, source-domain, diagnostic, snapshot and replacement-publication owners retain precedence.
Executable Cartesian and RIGHT DEDUP plans, background plans, zero/unavailable observations and conservative-maximum transitions retain exact admission. Factor two is a reoptimization tradeoff, not a memory guarantee or a measured optimum. Existing allocation limits and spill paths remain responsible for runtime capacity.
Safe reusable physical execution
Broader reuse exposed a latent integer hash-iterator bug.
Findleaves encoded keys and byte offsets populated, butInsertpreviously cleared them only on exit. A following insert could encode a new key at the previous lookup's offset. UPDATE hashbuild looks up old unique keys and retains its iterator across executions, so a conflicting prepared UPDATE could miss the matching DEDUP bucket and commit duplicate UNIQUE values.Move the existing integer insertion initialization from exit to entry, at the encoding owner. This covers both same-map read/write transitions and cached-owner reuse without disabling DML reuse, adding special admission exceptions, or introducing another cache/state machine. It adds no allocation or storage format; the bounded initialization work remains one pass per insertion.
Predicate-aware join construction
Transfer applicable crossing predicates from the existing pending pool before estimating each intermediate join. Preserve composite/non-equality/multi-table scope and genuine Cartesian multiplication. Remove the superseded singleton-admission proof rather than maintaining a parallel execution path.
Validation
Find(21) -> Insert(11) -> fresh Find(11)misses the inserted key. The correction passes real read/write, owner-change, retained-capacity regrowth, integer-width/composite, NULL andDetectDupcases; full hashmap tests and focused hashbuild reuse/DEDUP/IGNORE/REPLACE/resource-cleanup tests pass.FailNowafter a transactional write proves the next subscenario observes the restored value before any DDL; the injected run intentionally exits nonzero, while remaining scenarios pass.96196b4a9cpassed; CI for this follow-up commit is pending, not awaited or claimed green.Performance and limits
Preserve the admission and physical-plan reuse improvements; do not recompile every DML to hide stale state. Matched three-sample first-insert microbenchmarks retain identical bytes and allocation counts. These are bounded mechanism checks, not proof of full TPCC throughput, reused-transition elapsed time, TPCH 1T or multi-CN recovery; those remain unmeasured. Fresh workspace observation still scans existing metadata, and strict RIGHT DEDUP plans can still invalidate on small changes.
QA rationale
Successful updates and stable plan identities do not establish constraint integrity. Reuse validation must include the actual constraint rejection, the state left after a failed statement, committed contents, and recovery. The complementary internal regression checks read-to-write encoding transitions with an independent fresh lookup rather than asserting scratch flags or relying on coverage counts.