Skip to content

perf(sql): reduce exact integer IN and NOT IN evaluation cost - #31257

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue31140-exact-membership
Oct 26, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/issue31140-exact-membership

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:

Related to #31140

What this PR does / why we need it:

Reduce per-row hashing and per-batch allocation in exact integer IN/NOT IN evaluation. Sorted non-NULL integer lists with at least 16 members use an exact bitmap only when rounded backing fits both 64 KiB and eight bytes per input member; other sets reuse the existing map construction. Readiness and query-generation ownership remain with the existing expression executor.

Write preallocated boolean results directly, evaluate constant probes once, and skip membership work for NULL rows. Other type overloads and persisted formats are unchanged. Regression coverage includes all eight integer types, signed/unsigned extrema, NULL truth semantics, allocation bounds, selection masks, constants, and prepared-value refresh.

Validation against main b466f4ae9b74:

  • Full ordinary UT for pkg/sql/plan/function and pkg/sql/colexec: PASS.
  • Focused race UT for integer membership and executor lifecycle/selection: PASS.
  • Incremental repository-configured SCA for both packages: PASS, zero issues.
  • Independent native SQL checks for boundaries, NULL/empty sets, prepared RHS changes, correlated lists, casts, decimal/float/string controls: PASS.
  • Design and implementation reviewed with gpt-6.1-sol, xhigh.

Local performance, serial runs on a shared machine, 262144 rows and three threads; paired warm medians for prepared filtering:

IN members Main This change DuckDB
16 3.65 ms 1.52 ms 1.48 ms
256 3.80 ms 1.50 ms 2.83 ms
4096 4.39 ms 1.88 ms 23.27 ms

These minimal workloads improve by about 57–61%. The 4096-member/8192-probe operator benchmark reduces reused lookup time from about 87 to 12.5 microseconds and construction-plus-probe allocation from about 76 KB to 1.1 KB. Tiny fresh-set and sparse fallback controls were measured; a sparse all-NULL candidate regression was corrected and retained as regression coverage. No repeatable significant slowdown was found in tested controls; shared-host noise limits small-percentage conclusions.

DuckDB is v2.1.0-dev1 (cc9648d736), using its C API versus MO over TCP and different physical plans. These results cover minimal exact-membership workloads, not complete TPC-H or general engine superiority. Full TPC-H, mixed-I/O and concurrent-load performance acceptance remain outside this PR's measured scope.

Use a bounded exact bitmap for dense sorted integer lists, retain the existing map construction for other sets, and avoid per-batch parameter wrappers. Skip membership work for NULL probes and preserve executor reset and selection semantics.

Related to matrixorigin#31140.
@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 Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: fae1c51c99d187e09e279418501025b3728d5163

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: fae1c51c99d187e09e279418501025b3728d5163

Assessment: approve

Reviewed the complete delta and caller lifecycle. The bounded bitmap and direct result writes preserve existing NULL, selection, fallback and query-reset contracts. The measured benefit justifies the added complexity; no actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a1773b-d8e9-7ae1-9813-eff1ff7e3cab · slot 5 · generation 1

Validation:

  • Verified frozen HEAD, clean source and matching patch. Receipt/log reconciliation is retained in /home/xupeng/.local/state/mo-bot/jobs/b65f1bb8766f83a03d102660/attempt-4/validation-audit.json; design and coverage analysis is in review-record.json.

  • Isolation preflight passed. Rebuilt native prerequisites through repository make cgo using exact exported inputs; retained input/artifact hashes. Initial setup failures were resolved before tests.

  • Focused regressions and full pkg/sql/plan/function and pkg/sql/colexec tests passed. See focused-tests.log and package-tests.log with matching check receipts.

  • Native frontend SQL diagnostic passed dense/sparse/nullable membership, conditional selection, prepared-value refresh and UPDATE filtering. Diagnostic source, overlay, sql-probe.log and receipt are retained.

  • Repository-configured incremental lint passed with zero issues; formatting and diff checks passed.

  • Three-sample operator comparison against the frozen base registry: reused 4096-member/8192-row lookup median improved from 55.0 to 8.0 microseconds; construction-plus-probe allocation decreased from 76,368 to 1,120 bytes. Sparse controls improved overall; approximately 2% fresh one-row differences remain within shared-host measurement uncertainty.

Limitations:

  • The frozen bundle lacks linked issue #31140 text and traceable author validation artifacts. Approval covers the stated PR contract, without claiming closure of that broader issue.

  • SQL validation used one CN. Performance comparison isolates the operator; full TPC-H, mixed-I/O and concurrent-load performance remain outside the measured scope.

  • No new race run was required by the unchanged per-executor ownership model; author race-test claims were not counted as verified evidence.

@XuPeng-SH
XuPeng-SH merged commit f4450f2 into matrixorigin:main Oct 26, 2026
29 checks passed
@XuPeng-SH
XuPeng-SH deleted the codex/issue31140-exact-membership branch October 26, 2026 09:40

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/enhancement size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants