Repository navigation
perf(colexec,vector): gather and scatter varlena by mask without copying the area (#33457) - #33459
Conversation
…PR 6) Vector.Shrink(sels, negate), Batch.Shrink and the negate form of nulls.FilterInPlaceOrdered are removed. Callers that built a delete list or a selection one row at a time now fill a bitmap and use ShrinkByMask: TAE containers (Compact, sorted dedup), the GC executor, logtail backup, disttae deleteBatch / workspace shrink / object rewrite (CopyBlockData takes a mask), logtail replay filters, readutil PK IN normalization, IVF-FLAT relation filters (now return ReaderFilterResult.Mask) and data_branch_hashdiff (one list-to-mask conversion; the LCA probe no longer relies on ORDER BY). A keep-only Vector.ShrinkByRows remains for rows that arrive as a list (storage search, membership, TopN); PR 7 folds it into the RemapList gather. The nulls Gobra proof re-verifies with the narrower contract. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since PR 4 the expression executor calls a kernel only when every row is selected, passing one constant all-rows list. The kernels' masking paths were dead. Remove them, the FunctionSelectList type and the kernel parameter: a function implementation is now func(parameters, result, proc, length) error. The change was made mechanically: every check was folded with the value the executor passes (non-nil, nothing masked), then the parameter and its call arguments were dropped. Row-skip helpers that became constant were inlined and deleted. Constant folding and zone-map evaluation passed a nil list; folding the original both ways finds one kernel that differed for nil (string equality's compareVarlenaEqual header path), which is deleted so folding takes the same path as execution. Tests whose subject was masked or all-NULL selections are removed with the code they tested; mixed tests keep their unmasked cases, and tests whose mask hid an invalid row now use a NULL row instead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ing the area (matrixorigin#33457) A selected-row evaluation gathers the selected rows of each argument, calls the kernel on them, and scatters the compact result back. For variable-length values both steps copied the out-of-line payload and rewrote its offset, and the scatter went a row at a time. Neither copy is needed there. A compact argument lives for one kernel call while its source is unchanged, and the compact result is dead once scattered: - vector.AreaBorrowingGather copies the selected descriptors unchanged and returns a read-only view over them and the source's area. - Vector.ScatterByMaskTakingArea scatters only the descriptors and moves the compact result's area into the result (same pool, both owned); it falls back to ScatterByMask otherwise. Both are used only by FunctionExpressionExecutor.evalSelectedRows. UnionByMask and ScatterByMask, which other callers rely on for owned copies, are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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? |
|
This pull request is merged. |
|
mo-bot review · Commit: PR head changed during fetch |
The array-view loops now start at 8 selected rows per word, not 16, with the cutoff in one constant (maskViewMinRows). A word of 8 to 15 rows uses a check-free single loop; the run and two-chain paths still start at 16. The sparsest test comes first, so a word of fewer than 8 rows still costs one comparison. Against cutoff 16 (medians of 5 alternating runs): int64 gather at 14% -10%, 1024 scattered int64 rows -10%, int32 at 14% -5%; every sparse, run and dense case within noise. Cutoffs of 8 and 4 measured the same on the dense side; 4 cost more on the sparsest gathers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-area # Conflicts: # pkg/sql/plan/function/func_cast_integer_assignment.go
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? |
|
mo-bot review · Commit: "interrupted" |
What type of PR is this?
Which issue(s) this PR fixes:
issue #33457 (subtask of #33181)
Follows #33272, now merged. The diff against
mainholds only this PR's three commits:db22ed69a0(area borrowing),5f484ee0ccand8113b054f8(bounds-check elimination), across 8 files inpkg/container/vectorandpkg/sql/colexec.What this PR does / why we need it:
When a selection covers only some rows, the expression executor (
FunctionExpressionExecutor.evalSelectedRows) evaluates a function in three steps:A variable-length value longer than 23 bytes lives in the vector's
area, and its 24-byte descriptor holds the value's offset there. Before this PR:UnionOneper selected row and a NULL append per unselected row. It decoded and re-encoded every descriptor, even for short inline strings.Neither copy is needed in this one place:
Changes
vector.AreaBorrowingGathermp == nil) over those descriptors and the source'sarea.Vector.ScatterByMaskTakingAreaareainto the result.ScatterByMask.evalSelectedRowsuses the gather for variable-length, non-constant arguments, and the scatter for the result. The gathers are freed in the executor'sFree.unionVarlenByMaskis extracted asgatherVarlenaDescriptorsByMaskand shared.Ownership
evalSelectedRows.UnionByMaskandScatterByMaskare unchanged. Their other callers (batch, filter, table_scan, blockio) still get independently owned copies.Vectorstruct is unchanged. The view is an ordinary read-only vector.pkg/sql/plan/functionkeeps or returns its argument vector; there is noSetResultVectorthere. The kernels that readGetArea()directly (builtInHash,tryReserveAssignedText, cast overlap checks) only read through descriptors, so a borrowed area that also holds unselected rows is correct. At worst they size a buffer from the larger area.Benchmark
BenchmarkEvalSelectionVarlen(new): one 8192-row varchar batch, every 7th row NULL, 16/64/256-byte values. Medians of 6 alternating runs, base = #33272 head, Apple M2 Max, spread ≤ 8%. Times in µs.length(s)w16length(s)w64length(s)w256upper(s)w16upper(s)w64upper(s)w256concat(s, s)w16concat(s, s)w64concat(s, s)w256allis unchanged by design. A full selection never gathers or scatters.lengthat w16 has a fixed-width result, and its inline-only source already took the header-only gather path, so it is unchanged.upperandconcatat w16 gain 24–71% because of the scatter: the old one re-encoded every row even when all values were inline.Bounds-check elimination in the mask gather and scatter (
5f484ee0cc,8113b054f8)Go doesn't vectorize these loops. On arm64 the per-row gather and scatter compiled to scalar moves plus a bounds check on every row copied.
(*[64]T)) indexed byTrailingZeros & 63, and range over a destination slice of exactly the selected rows.-d=ssa/check_bceshows no per-row checks left in these loops, only per-word slicing and the partial last word. Words of 8–15 rows use one check-free loop; the run and two-chain paths still start at 16 rows.maskViewMinRows.The table compares against
db22ed69a0, usingBenchmarkMaskScatter(new) and the existing gather and selection benchmarks. Times are ns/op, medians of 5 alternating runs. It lists every case that moved at least 4%; across all the mask cases, none is more than 2% slower.MaskGatherint64 14% / 50%MaskGatherint32 14%MaskGathervarchar10 14% / 50% / 90%MaskGatherByCountint64, 1024 / 4096 scatteredMaskGatherByCountvarchar, 4096 scatteredMaskScatterint64 50% / 90%MaskScattervarchar 50% / 90%UnionByMaskEvalSelectionCOALESCE, half selectedTestMaskGatherScatterWordShapes(new) checks gather and scatter for 1-, 2-, 4-, 8-, 16- and 24-byte elements against a row-at-a-time oracle. It covers empty, full, sparse, run and dense scattered words, with a full or partial last word.l last word.
End to end
This PR's head was compared with
mainat3d3f579edf. The PR build also contained #33272, which has since merged. Builds ran alternately, on one Apple M2 Max.mainand 7,178 ms with the PR (−0.7%), with identical results for every query. Only Q11 (−5.8%) and Q18 (−2.9%) moved beyond the run-to-run range; no query is reliably slower. TPC-H filters mostly feed joins and aggregations over fixed-width columns, so this shows the change is neutral there; it doesn't measure the gains.oltp_update_indexat +5–6% in both pairs. A single run per pair can't resolve differences that small.Tests
TestAreaBorrowingGatherMatchesUnionByMaskUnionByMaskover random lengths, NULL rates and densities, with inline and out-of-line values.TestAreaBorrowingGatherRejectsConstAndFixed.TestScatterByMaskTakingAreaMatchesScatterByMaskScatterByMask, using a reused result vector.TestEvalSelectionVarlenMatchesFullEvaluationlength,upper,concatand a nestedconcat(upper(b), lower(concat(a, a))), under random selections.Validation:
main(with refactor(vector,function): remove the row-list Shrink and FunctionSelectList (#33181 PR 6 + 6b) #33272): unit tests pass forpkg/container/vector/...,pkg/sql/colexec/...,pkg/sql/plan/function/...andpkg/container/batch/...(77 packages).vectorandcolexec.golangci-lintreports 0 issues;molint,go vet -tags matrixone_testandgofmtare clean.🤖 Generated with Claude Code