Skip to content

fix(external): preserve saved result scan projections - #33045

Merged
XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/31625-zonemap-result-scan
Nov 21, 2026
Merged

XuPeng-SH merged 3 commits into
matrixorigin:mainfrom
XuPeng-SH:codex/31625-zonemap-result-scan

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

What this PR does / why we need it:

A saved result with a column named __mo_filepath returned the result file's path in place of the saved value. When that column was followed by another projected column, the per-block temporary vector also leaked. An absent leading column could make the batch report zero rows.

Read saved values by physical column ordinal and use block metadata for row count. Append missing-column NULLs directly to the output and copy loaded columns by contiguous range. A single loaded batch owns the decoded vectors until copying has finished. Metadata-only projections skip column data reads.

On 57 with Go 1.27.1, reproduced the original 4,608-byte and two-object leak on main. In-memory object tests cover reordered and missing columns, two differently sized blocks, cancellation, and allocation failure after partial output. A single-CN SQL round trip preserved the saved alias in a predicate and returned the expected total and non-NULL counts.

The whole external package passed both regular and race runs. Incremental golangci-lint reported zero issues. The SQL probe also round-tripped typed and untyped NULLs, an aggregate, and SHOW ACCOUNTS through RESULT_SCAN. The distributed regression case is included in the patch. The SQL probe used a private single-CN service.

Cancellation is tested after metadata has loaded. Cache-buffer lifetime assertions cover successful reads, append failure after an earlier column has been copied, and failure decoding the second column. Mutation checks confirmed the tests detect ignored cancellation, a missing release, and a double release.

@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 21, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 3d6b47201529ca72f8733c40353199a18e6cf823

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: 3d6b47201529ca72f8733c40353199a18e6cf823

Assessment: request_changes

The patch fixes the reported vector leak and preserves explicitly projected saved aliases. The new type check rejects valid saved CHAR results.

Model: gpt-6.2-sol / xhigh

Session: 01a1f0a0-5126-78f3-9ab8-ef4e87f2f119 · slot 0 · generation 3

  • P2 pkg/sql/colexec/external/reader_zonemap.go:219: With saved results enabled, run /* save_result */ SELECT CAST('a' AS CHAR(2)) AS s and then SELECT * FROM result_scan(last_query_id()) AS saved.
    Impact: The scan returns an invalid-input error for a valid saved result. A CHAR column also causes the scan to fail when other projected columns are valid.
    Evidence: The baseline reader returned a. The candidate returned error 20301. The diagnostic run confirmed stored VARCHAR and projected CHAR. The existing executor materializes folded CHAR literals in a VARCHAR container at pkg/sql/colexec/evalExpression.go:2139. Preserve this supported representation and add the CHAR round trip to the SQL regression.

Validation:

  • The issue reproduction retained 4,608 bytes and two objects with the baseline reader. Both projection orders passed on the candidate.

  • The full external package passed under race detection. In normal mode, the suite passed with the MinIO case excluded, and that case passed separately after an initial startup failure.

  • The affected SQL fixture sections matched all 28 result sets on each of two same-instance runs. The saved-result rewrite suite passed.

  • The baseline and candidate CHAR results, exact commands, and terminal receipts are indexed in review-evidence.md.

Limitations:

  • SQL validation used an embedded single CN through the MySQL frontend. The frozen evidence contained no completed mo-tester comparison.

  • The pre-existing wildcard expansion rule still omits __mo_filepath by name.

@XuPeng-SH

XuPeng-SH commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor Author

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

Commit: 30f5dd2f1cb023ef943eb40f3d2e382f0adb8c63

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: 30f5dd2f1cb023ef943eb40f3d2e382f0adb8c63

Assessment: approve

The saved-result reader uses physical column ordinals and block row counts, preserving saved aliases and returning NULL for missing columns. It reuses the existing reader and vector APIs while removing the temporary vectors that caused the leak. The prior CHAR projection regression is resolved.

Model: gpt-6.2-sol / xhigh

Session: 01a1feb0-0427-7772-9d89-786820ec84a5 · slot 1 · generation 2

Validation:

  • The focused reader and filter-mapping tests passed, including allocation and decode failure cleanup. Receipt 1795280484261690120-2.

  • A single-CN MySQL probe passed two rounds of filtered alias, reordered projection, NULL, and saved CHAR checks. Receipt 1795280461635351758-2.

  • The external package run reported one MinIO startup failure in an unrelated Arrow test. That test passed on isolated retry. Receipts 1795280453390868104-2 and 1795280586390646820-2.

  • Isolation preflight, native build, and git diff --check passed. validation-index.json maps the checks to retained logs and matching receipts.

Limitations:

  • Local SQL validation covered the changed regression on a single CN. The complete distributed BVT suite remained pending in the frozen CI snapshot.

@XuPeng-SH
XuPeng-SH merged commit afd0dae into matrixorigin:main Nov 21, 2026
@XuPeng-SH
XuPeng-SH deleted the codex/31625-zonemap-result-scan branch November 21, 2026 17:30
XuPeng-SH added a commit that referenced this pull request Nov 21, 2026
…ils (#33046)

## What this PR does

Related to #31625. After rebasing onto main, #33045 already removes the
temporary vectors this PR originally fixed. This follow-up adds a
missing error-path test to the upstream saved-result reader fixture.

The test reads a real saved column, then forces the allocation for a
missing column's NULL fill to fail. It checks that the original
allocation error reaches the caller, the block offset and published row
count do not advance, and the loaded column and caller-owned buffers are
released.

## Validation

- Existing and new saved-result projection subtests pass under race.
- With only the new subtest omitted, the missing-column append error
branch has zero hits. Enabling the subtest covers that branch in the
same fixture.
- Go vet and incremental golangci-lint passed.
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 21, 2026
main now carries the squashed forms of the PRs this branch was stacked on,
through matrixorigin#33027. The merged tree is this branch's own commits
(4de8e4e..1cc5610) replayed onto main, with three conflicts and one
semantic follow-up resolved:

- top: processBatchResident takes main's ordering specs (matrixorigin#33042) and keeps
  this branch's retained-pool prologue.
- external/reader_zonemap: main's rewritten saved-result reader (matrixorigin#33045)
  writes output vectors, including filled missing columns, through the
  operator's output pool; the loaded block stays on proc's pool.
- group/collation_metadata_test: main's form of the same offset fix.
- external/reader_zonemap_test (matrixorigin#33046): the capacity-failure cases bind
  an accounted output view instead of a per-vector allocation account, and
  pre-size the first column so the failure still lands on the second.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

No deployments
ci — 2d9e1f35 Deployed Nov 21, 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 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.

[Bug]: result scan zonemap reader leaks the per-block __mo_filepath vector when it is not the last projected column

2 participants