Skip to content

fix(external): honor parquet batch byte budget - #27901

Merged
XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27895
Sep 2, 2026
Merged

XuPeng-SH merged 8 commits into
matrixorigin:mainfrom
iamlinjunhong:m-27895

Conversation

@iamlinjunhong

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:

issue #27895

What this PR does / why we need it:

fix(external): honor parquet batch byte budget

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

@aunjgr aunjgr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed exact head edd5a1a against base 89740fa. I read the complete four-file change. The page-mode path advances every physical column only after the accepted prefix is known, rolls all vectors back to checkpoints before remapping a smaller prefix, and guarantees at least one-row progress at the byte boundary. Row mode bounds lookahead and seeks back to the accepted offset, so unread rows are not lost. Batch count and byte admission remain bounded, error cleanup retains the existing page/row-reader owners, and the new tests cover fixed, variable, dictionary, nested, rollback, oversized-row, and repeated-call cases. Exact-head CI is fully green. I found no merge-blocking issue.

@mergify

mergify Bot commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Queued — the merge queue status continues in this comment ↓.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed exact head edd5a1abc326f0e786f198be651d75680cc7b144 against its declared base 89740fae15dbba2cbe104348659694283cb160a6.

The byte-boundary implementation itself has coherent forward-progress and ownership rules: page mode advances all physical columns only after choosing the accepted prefix; rollback/remap preserves page offsets; dictionary-backed varlena accounting handles shared area ranges; and row mode bounds lookahead then seeks back to the accepted offset. I did not find a separate correctness, deadlock, or cleanup blocker in that exact diff.

However, this head can no longer be approved or merged as reviewed. PR #27902 (baa78c2a76cc6907836ceefea99710e930bc21e6) has since landed on main and changes the same prepare() path to prune nested Parquet projections and to make page iterators versus the projected row reader mutually exclusive. GitHub currently reports this PR as CONFLICTING, with a content conflict in pkg/sql/colexec/external/parquet.go. Exact-head CI therefore proves only the pre-#27902 implementation; it does not prove that byte budgeting and nested projection pruning coexist.

Please rebase onto latest main and resolve this semantically, preserving both invariants:

  1. Nested mode must construct the projected row group/row reader from only projected columns and must not open unused page iterators.
  2. Page mode must still initialize and advance every projected physical leaf together, while retaining the variable-width budget-column tracking introduced here.

After resolving, run the Parquet batch-budget tests together with the nested projection tests on the rebased head. This is a required integration change, not a cosmetic conflict resolution.

@XuPeng-SH XuPeng-SH left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[P1] Stale generated-column state causes deterministic batch-size collapse

External.Call reuses the same batch and calls:

ReadBatch -> CleanOnlyData -> ReadBatch

A Hive default partition column can be represented by a const-NULL vector whose data buffer is nil. CleanOnlyData clears the data buffer but can leave the previous logical length in that vector.

estimatedBatchSize starts from bat.Size(), so the stale generated-column length is counted as existing data. generatedBatchBytes then counts the same generated column again for the next candidate rows.

I reproduced this on exact head adf52a1 with one INT32 physical column, one Hive default TEXT partition column, 100 rows, and a 1 KiB budget:

  • First batch: 34 rows
  • Stale const-NULL logical length after cleanup: 34
  • Second batch: 5 rows

This does not lose rows, but when the byte budget is active it can repeatedly shrink batches and increase downstream scan/dispatch overhead for identical input.

Please fix the admission calculation so it is independent of generated-vector state left by the previous batch, and add a regression test that reuses one batch with CleanOnlyData and a Hive default const-NULL partition column. Keep the fix scoped; a global Vector cleanup semantic change needs broader compatibility evidence.

Other review dimensions passed:

  • Page progress and rollback: no lost or duplicated rows found
  • Resource lifecycle: no new leak or double-close found
  • Cancellation/waiting: no new hang path found
  • Bounds: lookahead and batch admission remain bounded
  • Count-only path: O(1)/O(log n) behavior preserved
  • Exact-head substantive CI: green

The current tests allocate a fresh batch for each ReadBatch, so they do not cover this production reuse path.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-reviewed exact head 701060891904ca23e18320a6fab5b85b1ef852e7 against base c46d897e9645b80178568ef0783dd8e99e527222, including issue #27895, the complete four-file diff, every earlier review finding, the latest stale-vector delta, page and nested modes, generated columns, row-count-only performance, resource ownership, and exact-head CI.

The latest commit closes the remaining deterministic batch-reuse regression without changing global vector cleanup semantics. physicalBatchSize now counts only vectors backed by projected Parquet columns, while generatedBatchBytes reserves virtual, partition, Iceberg metadata, and schema-evolution output separately. The same source-only baseline is used both for admission and precise prefix rollback. Therefore a const-NULL Hive partition vector whose logical length survives CleanOnlyData is neither treated as new physical input nor double-counted on the next call. The added production-shape regression reuses one batch and confirms stable row counts and correct source progress.

I also rechecked the broader implementation:

  • page mode advances every projected physical leaf only after a common accepted prefix, and rollback/remap does not publish source progress early;
  • nested mode bounds decoder lookahead, rolls back the first rejected row, and seeks to the accepted source offset on the next call;
  • virtual-only, mixed physical and generated, Iceberg DML, and missing-column NULL output are admitted before publication;
  • one oversize row still guarantees forward progress, while later rows wait for the next batch;
  • row-count-only with no generated output remains constant time, and generated-only admission is logarithmic;
  • page and row-reader error paths retain their existing owners and cleanup. No new goroutine, wait edge, leak, double close, unbounded retained collection, or log loop is introduced.

Exact-head substantive CI is terminal green and git diff --check passes. I found no remaining correctness, performance, Q1/Q2/Q3 unhappy-path, or merge blocker. APPROVE.

@mergify mergify Bot added the queued label Sep 2, 2026
@mergify

mergify Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-02 07:59 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-02 07:59 UTC · at 01fdec9aeb20107aadd13691dcaab590d3b32e86

This pull request spent 31 seconds in the queue, with no time running CI.

Reason

The pull request can't be updated

This pull request seems to come from a fork, and Mergify needs the author's permission to update its branch.
The author needs to enable "Allow edits from maintainers" on this pull request, or update the branch manually.

Hint

You should update or rebase your pull request manually. If you do, this pull request will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
ci — 01fdec9a Deployed Sep 2, 2026 by mergify[bot] via Matrixone Utils CI / Coverage #50094
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants