Repository navigation
Conversation
Table scans currently materialize every projected column before evaluating residual filters. On the workload from matrixorigin#26960, the scan read 11.45 million rows / 7.32 GB and spent 62.78 seconds even though the query returned no rows. The captured CPU profile was dominated by copying and constructing varlen output (`memmove`, `Vector.Union`, and varlena construction), rather than predicate evaluation. This PR adds block-local late materialization for output-only wide varlen columns: - predicate columns and fixed/small output columns are loaded first; - visibility and tombstones are applied before the residual filter; - surviving logical row positions are mapped back to physical block offsets; - deferred columns are loaded only for those surviving rows. The capability is optional on `engine.Reader`, so unsupported readers remain correct without changing the existing reader interface. In-memory data, storage TopN, sharding readers, transaction data tracing, reader summaries, and unsupported expression forms keep the eager path. The change also preserves exact-PK feedback and separates synchronous filter CPU time from filesystem wait accounting. Local A/B on the same persisted 200,000-row table with a 328 MiB text payload: | Query | Metric | Before | After | | --- | ---: | ---: | ---: | | zero survivors | Table Scan InputSize | 335.10 MiB | 2.29 MiB | | zero survivors | ReadSize | 4.32 MiB | 796.72 KiB | | zero survivors | MemorySize | 14.47 MiB | 291.31 KiB | | 200 survivors | Table Scan InputSize | 334.34 MiB | 1.86 MiB | | 200 survivors | OutputSize | 328.24 MiB | 341.19 KiB | | 200 survivors | MemorySize | 28.44 MiB | 275.27 KiB | The selective query still returns 200 rows with IDs 1000 through 200000 and 344576 payload bytes. An all-survivor warm-cache control still materializes 334.34 MiB and showed about 10 ms of additional local read-call overhead, so the optimization is deliberately limited to output-only wide varlen columns. Validation: - `go test -p 4 ./pkg/vm/process ./pkg/sql/compile ./pkg/sql/colexec/... ./pkg/vm/engine/... -count=1` - `go test -race -p 2 ./pkg/vm/process ./pkg/sql/colexec/table_scan ./pkg/vm/engine/readutil ./pkg/vm/engine/tae/blockio -count=1` - `go vet -p 4 ./pkg/vm/process ./pkg/sql/colexec/table_scan ./pkg/vm/engine/readutil ./pkg/vm/engine/tae/blockio ./pkg/sql/compile ./pkg/vm/engine/disttae` - `make build` - local persisted-table `EXPLAIN ANALYZE` checks for zero, selective, and all-survivor cases Approved by: @XuPeng-SH (cherry picked from commit c04df06)
aptend
requested review from
LeftHandCold,
XuPeng-SH and
aunjgr
as code owners
August 13, 2026 06:46
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
1 task done
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Which issue(s) this PR fixes:
issue #26960
What this PR does / why we need it:
Backport of #26969 to 4.2-dev.
Table scans currently materialize every projected column before evaluating residual filters. On the workload from #26960, the scan read 11.45 million rows / 7.32 GB and spent 62.78 seconds even though the query returned no rows. The captured CPU profile was dominated by copying and constructing varlen output rather than predicate evaluation.
This change adds block-local late materialization for output-only wide varlen columns:
The capability is optional on engine.Reader, so unsupported readers keep the eager path. In-memory data, storage TopN, sharding readers, transaction-data tracing, reader summaries, and unsupported expression forms also remain eager.
4.2-dev predates the merge-reader ownership fix present on main. This backport includes the required close-on-exhaustion/error behavior so the new ReadWithFilter path has the same exactly-once reader cleanup contract; focused tests cover both terminal paths.
Validation: