Skip to content

fix(colexec): preserve the COALESCE selection row domain - #33441

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/coalesce-selection-row-domain
Nov 29, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:fix/coalesce-selection-row-domain

Conversation

@XuPeng-SH

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

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 #33181

What this PR does / why we need it:

Follow-up to the review of #33266. A reused nullable vector can retain a NULL bitmap longer than the current batch. Intersecting it with the remaining rows in COALESCE grew the selection and caused a later typed Python routine to reject the batch.

Use a read-only prefix view for the longer NULL bitmap. This keeps the current selection length and avoids an allocation. Shorter and equal-length bitmaps use the existing word-wise intersection. The external routine keeps checking its input row domain.

The Decimal mul/sub and OR-LIKE reuse benchmarks now construct their partial mask once before timing and release it at subbenchmark teardown. The expression selection benchmark also releases its existing hoisted mask.

Validation

  • The new bound expression regression fails on the base with a 128-row selection on a 3-row batch. On the fix, it returns the expected values before and after a 128-row batch, with only the selected NULL rows reaching the mock routine runtime.
  • Off-heap allocation checks for the three targeted 8,192-row benchmark cases show zero bytes retained in the selection pool after teardown. The same base cases retained 66,560, 68,608, and 2,048 bytes.
  • Incremental formatting, vet, molint and golangci-lint passed. The unit suites for colexec, filter, projection, and table_scan passed with -race -short.
  • Five alternating local runs of the 8,192-row COALESCE benchmark showed median changes of +1.5% for all rows and -0.1% at both partial densities. Allocations per operation matched the base in each case.
  • The checked-in udf_python/control_flow BVT covers the 8,192-row batch and 3-row tail. Normal mo-tester comparison passed all 26 statements twice on the same worker-enabled instance, with database cleanup confirmed after each run. The same case failed only the new statement on the base with external routine selection has 8192 rows, expected 3; the candidate returns 33,738,797.

@XuPeng-SH
XuPeng-SH requested a review from aptend as a code owner November 29, 2026 01:29
@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 commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 92efa7f48f6a440ecaae64050527def5e7833de7

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: 92efa7f48f6a440ecaae64050527def5e7833de7

Assessment: request_changes

The prefix view correctly preserves the selection domain and reuses the existing bitmap implementation. Focused tests and a real-worker SQL probe pass, but the repository's required maintained public SQL regression is missing.

Model: gpt-6.1-terra / max

Session: 01a2230f-39de-7f00-bf9a-e19ded95bd85 · slot 0 · generation 39

  • P2 pkg/sql/colexec/external_routine_eval_test.go:240: A SQL query evaluates COALESCE with a Python-routine fallback across a full batch followed by a smaller batch containing NULLs.
    Impact: The required public-path regression gate remains open. The new test invokes the expression executor with a mocked runtime, so the tracked suite does not retain coverage of the SQL planner, batch transition, and real worker together.
    Evidence: The pinned mo-dev testing contract requires BVT coverage for SQL-visible behavior and defines BVT under test/distributed/cases using mo-tester. The existing udf_python/control_flow.sql case covers CASE selection but has no COALESCE shrinking-batch case. A review-only SQL probe using generate_series(1,8195) and a real Python worker fails with 'external routine selection has 8192 rows, expected 3' when the base evaluator is overlaid, and passes on the candidate. Retain an equivalent SQL and expected-result case in the existing worker-enabled BVT and run it in normal comparison mode.

Validation:

  • Private /tmp and loopback preflight passed: preflight.log and checks/1795915944119726077-3.json.

  • Focused evaluator and bitmap tests passed: focused-tests.log and checks/1795916176590204578-3.json. The colexec short suite also passed: colexec-short.log and checks/1795916557227417478-3.json.

  • The added evaluator regression failed with the frozen base evaluator overlaid, producing the reported 128-versus-3 selection error: base-unit-control.log and checks/1795916266962749386-3.json.

  • A real-worker embedded SQL probe failed with the base evaluator overlaid and passed on the candidate: public-sql-base.log, public-sql-candidate.log and checks/1795916364768038027-3.json, checks/1795916417215816688-3.json.

  • A partial-selection probe passed at 0, 1, 3, 63, 64, 65 and 129 rows after a 130-row batch: partial-boundary.log and checks/1795916472434391686-3.json.

  • All 52 selected benchmark cases completed in a one-iteration smoke run: bench-smoke.log and checks/1795916258636619336-3.json.

Limitations:

  • The public SQL probe is retained as review evidence, not as a maintained mo-tester BVT case.

  • The benchmark smoke run did not independently verify the reported performance or off-heap retention measurements.

@XuPeng-SH

XuPeng-SH commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 067ae8e9759a46f0ef760302431d4ecea72f54b5

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: 067ae8e9759a46f0ef760302431d4ecea72f54b5

Assessment: approve

The COALESCE fix keeps the existing selection within the current batch by reusing the bitmap prefix view, without adding persistent state or an owned bitmap allocation. The previously requested worker-enabled SQL regression is now included. No actionable defects were found.

Model: gpt-6.1-terra / max

Session: 01a22477-91d1-7a10-9060-414db378340e · slot 1 · generation 35

Validation:

  • Preflight, frozen-source and patch checks, and discussion coverage reconciliation passed; receipts and logs are retained in the diagnostic directory.

  • An exact-head embedded SQL probe ran the new query twice with a real Python worker and returned the independently calculated aggregate. Receipt: checks/1795917748305960653-5.json; log: exact-bvt-query.log.

  • Reused earlier same-PR focused evaluator, bitmap, colexec short-suite, partial-selection boundary, and real-worker evidence after verifying that the production code and relevant inputs were unchanged. Baseline controls reproduced the oversized-selection error.

Limitations:

  • The complete mo-tester case was not rerun independently. The author reports two successful normal-comparison runs with cleanup, but their logs were not supplied.

  • CI status and the author's race, performance, and off-heap measurement logs were not supplied. The retained benchmark run is a smoke check, not a performance measurement.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants