Skip to content

fix(sql): honor empty scan decisions before constructing readers - #29650

Merged
XuPeng-SH merged 3 commits into
mainfrom
fix/odku-unique-dedup-29197
Oct 6, 2026
Merged

XuPeng-SH merged 3 commits into
mainfrom
fix/odku-unique-dedup-29197

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #29197
Related to #29196.

What this PR does / why we need it:

An update-only INSERT ... ON DUPLICATE KEY UPDATE with a secondary UNIQUE key resolved its target selectively, but still scanned the entire hidden UNIQUE index during final INSERT-only validation. At 100,000 rows that stage read 100,000 rows / 400,000 bytes on ordinary, KEY-partitioned and RANGE-partitioned tables.

HashBuild already publishes a valid DROP when the conditional validation keys are all NULL. Scope.buildReaders consumed DROP but merely skipped range collection, then constructed ordinary storage readers anyway. Nil relation data intentionally permits an in-memory scan, so this did not stop reading.

Return the existing empty readers before ordinary reader construction for DROP and constant-FALSE decisions, releasing unused assigned range metadata. Reuse the same helper for existing vector and star-count empty readers. Nonempty validation, optional PASS fallback, target resolution, locking and DEDUP finalization retain their existing owners.

Reader lifecycle tests previously used a dummy FALSE predicate while expecting storage readers to execute. Replace that shortcut with shared real range-collection setup, keeping reader ownership, ordering, close and cancellation assertions.

Validation

  • Whole pkg/sql/compile suite: normal and race, -count=1.
  • Two-CN public SQL regression: normal and race. Covers ordinary/KEY/RANGE/composite UNIQUE tables, physical zero-scan accounting, binary prepared DROP→INSERT→DROP reuse, mixed and ordered intra-statement conflicts, NULL keys, empty INSERT SELECT, duplicate rejection, outer and anti joins.
  • Owner controls cover local/remote PASS, DROP, FALSE, required-PASS rejection and canceled required waits, including parallel empty readers and no range/reader factory calls.
  • Negative control using the original scope fails the new SQL test with 33 scanned rows / 132 bytes.
  • Cross-CN QA: observe a waiter on the resolved main-table target via mo_locks(), commit its holder, then verify both increments on the single original row.
  • Final formatting, vet and configured incremental golangci-lint pass. Molint has no new diagnostics against the original-scope baseline (the same seven existing recover diagnostics).
  • Independent gpt-6.1-sol / xhigh design and complete-change review: no unresolved material blockers.

Performance

Same hot-data, single-client harness: 100 / 10,000 / 100,000 rows, three warmups and 20 direct/prepared samples per shape. All nine UNIQUE validation scans now read zero rows / zero bytes. At 100,000 rows, prepared medians were:

Shape Before After
Ordinary + UNIQUE 14.57 ms 5.38 ms
KEY + UNIQUE 15.21 ms 6.39 ms
RANGE + UNIQUE 14.44 ms 7.30 ms
Ordinary PK-only control 5.13 ms 5.10 ms

These are local latency observations, not a production throughput guarantee. Legitimate nonempty validation and PASS fallback can still scan; this change does not claim to resolve every full-scan case in #29196.

Implementation: +17/-17 lines. Tests: +212/-39 lines. Documentation: no tracked changes. CI is pending publication.

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

Deep review of commit 94a8e0598ccc2a1a50cceaf5961ba4aebe2c2424 against ffe8362614b8bde8fe0fa249ee472edc87bf256a: no blocking findings; code meets the approval bar. GitHub CI is still running.

The correction belongs in the existing scan-admission owner. It honors DROP/FALSE before storage reader construction, while preserving pipeline execution, JOIN finalization, cancellation and cleanup. Exact-empty proof remains the producer's responsibility; missing payload, spill, capacity fallback and build failure keep their existing PASS/error behavior. No duplicate validation, cache or execution path was added.

I reviewed every changed hunk and the producer → scan → join/cleanup/reuse closure. The old lifecycle tests now reach genuine range/reader setup and retain their original close, ordering and cancellation assertions. Implementation is +17/-17; tests are +212/-39; no documentation delta. The test increment covers distinct owner and public contracts and reuses the existing cluster fixture.

Additional independent two-CN QA in this review passed (normal, -count=1, exit 0):

  • Real RIGHT SINGLE + runtime filter with two all-NULL build keys: zero probe scan rows/bytes, both preserved NULL result rows retained.
  • Binary prepared SELECT reuse across NULL → matching → NULL.
  • FALSE aggregate identities, empty INNER and scalar comparison, preserved RIGHT/ANTI results.
  • Multi-row scalar subquery still errors, and the session executes the next statement successfully.

Verified and reused the exact-tree normal/race, SCA, old-code negative control, cross-CN target-lock and performance evidence. The performance conclusion is removal of the N-scaled validation scan; the local hot-data medians are not a production throughput promise.

There are currently no inline review comments or code-related discussion items left to address; the Qodo comment is a service notice. Linux UT/SCA/coverage and BVT checks remain pending.

This review is recorded as COMMENT because the authenticated account is also the PR author; it does not represent a GitHub APPROVE state.

This branch was previously deployed

1 inactive deployment
ci — 58d23522 Deployed Oct 6, 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/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ODKU with UNIQUE keys performs full hidden-index validation scan after selective target lookup

2 participants