Skip to content

fix(plan): prune correlated composite primary-key points - #32377

Merged
XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-32365-composite-points-main
Nov 9, 2026
Merged

XuPeng-SH merged 7 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue-32365-composite-points-main

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG
  • Improvement

Which issue(s) this PR fixes:

issue #32365

Related 4.2-dev implementation: #32371.

What this PR does / why we need it:

A predicate like tenant = ? AND ((session = ? AND request = ?) OR ...) describes a small set of complete composite primary keys, but previously scanned the entire tenant prefix. Derive a bounded set of correlated keys as a necessary scan filter and retain the full original predicates.

  • Reuse existing composite-key encoding, index and join selection, and reader filtering. Publish points only if the same scan, key, snapshot and predicate witnesses survive the existing rewrites. Unsafe comparisons or residuals, unsupported shapes, and exhausted query-wide admission budgets keep the existing access path.
  • Defer execution-value inspection until a point candidate actually survives access selection. This preserves the existing prepared-plan cache for index plans that discard the candidate; surviving or value-dependently rejected candidates use the existing value-dependent replanning policy. A reused ordinary plan can miss an optimization that a fresh plan might find; it remains correct under the existing cache policy.
  • Avoid temporary numeric-prefix bookkeeping for functions that the existing shared binder already rejects, without bypassing their normal conversions or diagnostics. Prefer exact point membership over a compatible prefix in the existing reader; redact serialized key lists in text EXPLAIN.

The versioned design covers ownership, cache semantics, bounded resource charges, cancellation and performance. Its amended revision received an independent gpt-6.1-terra / max design PASS (session 01a1bc7a-177e-7950-b176-bd33aabe982f). The original implementation preceded the versioned document; the deferred-admission correction was designed and approved before implementation.

Validation

  • Full planner package normal and race tests; existing full plan/explain and readutil normal/race results remain applicable to their unchanged code. Focused frontend cache/retry and binary prepared SELECT/UPDATE tests under race, including index cache reuse, large/small/NULL rebinding, error/warning and rollback controls.
  • Two runs each on the same isolated instance: composite-point BVT 64/64 and existing block-filter BVT 56/56. Existing prepared numeric and warning BVT 299/299; SQL and binary common-value tests include numeric overflow.
  • Incremental gofmt, go vet, repository-pinned molint and golangci-lint for the changed packages and affected consumers, license headers, and git diff --check.

Local performance

On a Ryzen 9 7900X with Go 1.27.1, one local CN and a persisted 100,001-row table, three fresh-cluster samples of ten warmed binary-prepared COUNT executions over 50 scattered keys had medians of 615.7 ms on the main baseline and 78.2 ms with this change. Scan input was 100,001 versus 50 rows; blocks touched were 14 versus 13. The two-point case read two rows, and binary SELECT and UPDATE returned or changed the expected rows. These separate local batches are illustrative, not a general latency guarantee or evidence of proportional block-I/O savings.

The planning work is not free. In three paired local microbenchmark samples, 50-point planning went from 1.27 to 1.53 ms, 831 KB to 1,038 KB, and 16,209 to 18,096 allocations per plan; value-dependent point plans are replanned. The shared numeric-prefix change reduced the updated 50-point case by 22.4 KB and 400 allocations compared with the same deferred-admission code before that change; these short timing samples do not establish a CPU speedup from that particular reduction.

@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 →

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: ca6358cdfa0903c0aaa45bb1e5370a386da33e7c

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: ca6358cdfa0903c0aaa45bb1e5370a386da33e7c

Assessment: request_changes

The new correlated-point access strategy requires a reviewed versioned design. It reuses existing encoding/filter owners, but adds a proposal lifecycle, query-wide resource policy and value-dependent prepared replanning that the existing primary-prefix design does not cover.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/sql/plan/composite_key_points.go:515: This introduces a cross-phase correlated-point access strategy, including proposal capture/revalidation/publication, query-wide budgeting and execution-value-dependent prepared-plan admission. This materially expands the planning architecture; its 815 changed production lines also exceed the repository's feature/refactor design threshold.
    Impact: The mandatory design-first gate remains unmet: the frozen PR/evidence links no reviewed versioned design covering these policies. Implementation approval must wait for that design decision. This is a design-review gap, not a demonstrated runtime failure.
    Evidence: The unchanged base contract in .agents/skills/mo-dev/references/feature-design-review.md:11-95 requires a versioned design and traceable approval before implementation review for this architectural scope. The added state starts here; prepared admission changes at composite_key_points.go:171 and late publication is wired through query_builder.go:4571-4598. docs/design/20261024-secondary-index-primary-prefix.md covers existing lowering/index selection, not these new policies. Add or link the exact reviewed revision addressing the ownership, cache, resource and performance decisions, and record design approval; extending the existing design is sufficient.

Validation:

  • Read the complete 16-file delta, linked issue #32365 and both indexed discussion entries; retained review-plan.md, change-map.json, source-closure.md and discussion-assessment.json.

  • Assigned check-run static probe passed at the frozen head: clean source, unchanged base design policy, gofmt for 13 changed Go files, four display-only blockfilter result substitutions, and matching 56-statement SQL/result fixtures. Receipt and output are retained under checks/ and static-review-v2.log.

  • Independently traced reader AND preference, vector cleanup ownership and EXPLAIN redaction. Author-reported owning-package normal/race and two 56/56 BVT runs were considered as attributed reports.

Limitations:

  • Dependent tuple derivation, proposal publication and prepared-cache correctness review stopped at the mandatory design gate; no local Go or SQL tests were compiled or executed.

  • Raw author validation artifacts were not supplied, and core CI jobs were still in progress in the frozen snapshot. Reported performance measurements used one CN alongside a race run and do not establish general latency or multi-CN costs.

@XuPeng-SH

XuPeng-SH commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 20fe5447c749a96c567c98667037060871660279

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 20fe5447c749a96c567c98667037060871660279

Assessment: approve

The prior design gap is resolved. Bounded proposal capture is justified by intervening access rewrites and reuses existing encoding, prepared-cache and reader owners. No actionable correctness or design issue remains.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed all 20 changed files, affected consumers, linked issue and four discussion entries; saved the change map and discussion assessment.

  • Full planner, EXPLAIN and readutil normal tests passed. Fourteen focused tests across four packages and the public binary-prepared SELECT/UPDATE test passed.

  • Static checks passed for source/patch identity, formatting, reviewed design, discussion coverage and SQL/result alignment. Twelve receipts and retained logs are reconciled in validation-ledger.json.

Limitations:

  • The full frontend run failed at unchanged Test_openNewFile_nilCtx because its fixture writes beneath the read-only checkout; affected frontend tests passed separately.

  • Core CI was pending in the supplied snapshot. Local race, mo-tester and performance runs were not repeated; author reports remain attributed.

This branch was successfully deployed

No deployments
ci — 1e639858 Deployed Nov 9, 2026 by XuPeng-SH
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 size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants