Skip to content

refactor(vector): remove isBin from Vector (#33025) - #33034

Merged
fengttt merged 2 commits into
matrixorigin:mainfrom
fengttt:vector-isbin-out
Nov 22, 2026
Merged

fengttt merged 2 commits into
matrixorigin:mainfrom
fengttt:vector-isbin-out

Conversation

@fengttt

@fengttt fengttt commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • Code Refactoring

Which issue(s) this PR fixes:

issue #33025

What this PR does / why we need it:

Removes isBin from Vector. Whether a value was spelled as a hex/bit literal, or comes from a binary-flagged prepared parameter or user variable, is a fact about the expression that produced the value. It is not a property of the vector that holds it.

Stacked on #33033 (and #33027, #33024). Review only the last commit: d46b67a5ec.

  • Removed from Vector: the isBin field, GetIsBin/SetIsBin and CopyExpressionMetadataTo.
  • The producer owns the fact.
    • FixedVectorExpressionExecutor, ParamExpressionExecutor and VarExpressionExecutor record the flag for the vector they return.
    • FunctionExpressionExecutor works out, for each argument, whether the result it received is one of those leaves (isBinaryLiteralResult). The check looks through memo and dependent wrappers. It rejects placeholders the executor substitutes, such as NULLs for skipped branches or masked results.
    • The executor passes the flags to the kernel through the result wrapper (FunctionResultWrapper.SetArgumentIsBin / ArgumentIsBin). Kernels that read ivecs[i].GetIsBin() now call result.ArgumentIsBin(i).
    • IffConditionTruthyAt takes the flag as an argument.
  • Frontend: prepared SET and SELECT ... INTO @var get the flag from the bound plan expression (colexec.ExprIsBinLiteral), not from the result vector.
  • Copy, selection and scan paths (batch compaction, pSpool, borrowed views, blockio membership reads, table_scan gather) only passed the flag along, so they no longer touch it.

Tests

  • go build ./... and go vet are clean on the touched packages.
  • Unit tests pass: container/{vector,batch,pSpool}, sql/colexec/..., sql/plan/..., frontend, sql/compile, tae/blockio.
  • New tests: colexec/binary_literal_test.go and plan/binary_literal_argument_test.go.

🤖 Generated with Claude Code

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

Whether a value was spelled as a hex/bit literal (or comes from a
binary-flagged prepared parameter or user variable) is a fact about the
expression that produced it, not about the vector holding it. Drop
Vector.isBin, GetIsBin/SetIsBin and CopyExpressionMetadataTo.

The producer now owns the fact:
- FixedVectorExpressionExecutor, ParamExpressionExecutor and
  VarExpressionExecutor record it for the vector they return.
- FunctionExpressionExecutor resolves, per argument, whether the result it
  received is such a leaf (isBinaryLiteralResult, which sees through memo
  and dependent wrappers and rejects substituted placeholders) and
  publishes the flags to the kernel through the result wrapper
  (FunctionResultWrapper.SetArgumentIsBin / ArgumentIsBin).
- IFF condition truthiness takes the flag as an argument.
- The frontend derives it from the bound plan expression
  (colexec.ExprIsBinLiteral) for prepared SET and SELECT ... INTO @var.

Copy/selection/scan paths that only forwarded the flag drop it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@fengttt
fengttt merged commit da97e91 into matrixorigin:main Nov 22, 2026
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 22, 2026
This branch already carries matrixorigin#33034's commit; keep this branch's side.
fengttt added a commit that referenced this pull request Nov 23, 2026
…3019) (#33052)

## What type of PR is this?

- [x] Code Refactoring
- [x] BUG

## Which issue(s) this PR fixes:

issue #33019

## What this PR does / why we need it:

A `Vector` now has exactly one owner pool, and nothing else about
memory. `offHeap`, `cantFreeData` and `cantFreeArea` are gone, replaced
by one `mp *mpool.MPool` set when the vector is created.

**Stacked on #33034 and #33033.** Review commit `90b459f68c` (the
change), the merge commit `d6fc6630fc` (upstream sync) and the
follow-ups `95155a83ad`, `83a5ef6377`, `af929a9ece`, `3aa882ce19`,
`a6e0d0e4e3`, `24c5d57fbb`, `4773ebe65d` and `53b867de02`. Everything
below `90b459f68c` belongs to the earlier PRs.

### The memory model

The model is written down in `docs/ai-skills/sql-engine.md` ("Vector
内存管理模型"):

- **One pool per vector.** Every vector comes from a pool and is freed
with it. All vector memory is off-heap, so a vector that is never freed
is a leak.
- **Strict pool check.** A call that passes `mp` must pass exactly the
vector's own pool. A view of the same pool doesn't count. A mismatch is
an error, and a panic in `Free`.
- **Read-only vectors.** A nil pool means a read-only reference to
memory the vector does not own, such as FileService cache entries or
Arrow buffers. Allocating into it or mutating it fails. `Free` only
drops its references.
- **Operator pools.** Operators that buffer a lot of data own a pool
from `colexec.NewOperatorMPool`: order, top, mergetop, group, window and
hash build, plus the table scan. Other operators use `proc.Mp()`.
- **Batch lifetime.** A batch is valid until the next `Next`. Moving an
input vector into the output is fine. Modifying an input vector is not:
the operator must write into a vector it owns.
- **No new `Vector` fields** without human review.

### Main changes

- **Window and decode.**
- `Window` returns a read-only reference; `CloneWindow`/`CloneWindowTo`
copy.
- Decoding into a vector that has a pool copies into that pool; decoding
into a read-only vector keeps references.
- A read-only vector's null bitmap is always private, so writes through
`GetNulls()` can never reach cache memory.
- **Table scan.** The scan owns its output pool, so later operators
cannot modify scanned rows.
- **Transaction workspace.** It copies caller batches into its own pool
and never takes them over. Each caller frees its own batch.
- **Read-only checks.** In-place setters (`SetFixedAt*`, `SetNull`,
`UnsetNull`) reject read-only vectors.
- **Freeing.** Decode receivers that belong to another pool are
rejected. tae `Vectors.Free` is strict. Most `vec.Free(vec.MPool())`
call sites now free with the owner's pool; a few holders of several
pools still free each vector with its own pool. `batch.CleanOwned` is
only for tests.

- **Filtered scans publish a batch selection.** When the scan's parent
reads selected batches (filter, projection), a filtered block without
deletes keeps every column as a read-only reference to the cache, pinned
by the output batch until the next `Next`, and the kept rows become the
batch selection (#33021). Otherwise the reader still compacts while its
cache entries are pinned: publishing and compacting later made SF100
TPC-H, whose scans all feed joins or aggregations, about 10% slower.
- **Faster selection conversions.** Bitmap to row list, bitmap to bool
mask and row list to bitmap now work a word at a time, size their output
once and reuse storage; `CompactInto` takes a reusable row list. Per
8192-row block: rows 11.4 → 1.8 µs at 50% and 21.7 → 2.8 µs at 100%;
mask 11.7 → 4.5 µs and 22.5 → 1.8 µs.

### Bugs fixed along the way

- **INSERT/LOAD IGNORE.** The NOT NULL fill wrote implicit defaults into
the child's vectors in place. For a scan's read-only vectors that meant
cache memory. A NULL varchar into a NOT NULL column also failed the pool
check.
- Now `colexec.IgnoreFill` adjusts a copy it owns, one reusable vector
per column. PreInsert, the external insert and multi_update use it.
- multi_update's main-table leg publishes the adjusted batch to the
index legs, so index rows see the same values.
- **Lock op.** Refresh timestamps were appended to the child's vector.
Lock op now fills its own vector and publishes it through a view.
- **Arrow external reader.** It swapped its vectors into the operator's
batch, so two owners shared one batch. Now the reader owns the batch it
publishes (`BatchPublisher`).
- **C null-map over-read.**
- A null bitmap ends at its highest null, but the docfilter and
cbloomfilter C kernels test every row's bit, so they read past it.
- Before this change, read-only decodes shared the bitmap with the
encoded buffer, which hid the over-read.
  - Fix: callers now pass `Bitmap.WordsCovering(n)`.
- **SET descriptor cache.** It kept zero-copy strings over vector
memory, which are now reused off-heap memory. It now clones them first.
- **Low-precision float sort.** Sort-and-compact for BF16 and the other
low-precision floats appended without a pool.
- **Sort rollup.** It unioned aggregate results through the wrong pool.
- **HNSW sync writer.** The ISCP writer kept zero-copy views of
change-batch vectors in its CDC buffer across batches. After a copy
ALTER or TRUNCATE, an int8/uint8 index trained its range from freed
memory and returned wrong neighbours. It now copies the vectors
(`af929a9ece`).
- **`fault_inject`.** It handed zero-copy argument strings to the local
CN's fault map, so the CN running the statement stored a garbage point
name and every fault-injection BVT case on that CN failed. It now copies
them (`3aa882ce19`).
- **Collation test.** The cherry-picked `95155a83ad` carried a copy of
`collation_metadata_test.go` older than `main`'s that did not compile;
`a6e0d0e4e3` takes `main`'s file and adapts it.
- **Pool mismatches.** hashbuild runtime-filter runs and `Expr_Vec`
literals were freed through the wrong pool.

### Behavior changes

- **Copying.** Scan rows read from objects with deletes or selections
are copied into the scan's pool. Raw workspace input is copied and
charged to the workspace account.
- **No spill recovery class.** The buffered data of Order, Top and Group
no longer switches to the recovery capacity class.
- **Removed tests.** Tests of the old borrow/copy-on-write contract are
removed.

### Tests

- `go build ./...` and `go vet ./pkg/... ./cmd/...` are clean.
- **Unit tests on the merged tree:**
- 412 packages pass; the four packages that failed only because of the
merge were fixed in `83a5ef6377` and now pass.
- The squash merges of #33011, #33017 and #33024 included commits pushed
to those PR branches after this branch forked from them. Their
production changes came in through the merge. Three plan tests had been
resolved to this branch's side, so `83a5ef6377` restores their updates.
`95155a83ad` is one of those commits, cherry-picked.
- `tests/service` `TestTaskSchedulerExpiresLostRunnerWithoutReplay` is
flaky: 2 of 4 runs fail on plain upstream `main` too.
- `tests/txn` `TestWriteSkewIsAllowed` failed in the full run and passes
when run alone.
- `util/metric/mometric` fails while a local cluster holds port 7001.
`util/metric/v2/dashboard` needs Grafana.
- **BVT on a two-CN `make dev-up` cluster built from this branch:**
- `load_data` passes 99%; the only failures are `into outfile`
permission errors from the environment.
- `dml` passes 98%; the failures need `AUTO_ID_CACHE`, a CDC loopback to
6001, or ETL data.
- The full run found the sort-rollup, HNSW and `fault_inject` bugs
above, all fixed. The fault-injection and clone cases were compared
against an upstream `main` image on the same cluster and now pass.
- The remaining failures also fail on the `main` image or need what the
dev cluster lacks: `AUTO_ID_CACHE`, statement tracing (`disableTrace =
true`), `into outfile` permissions, external servers. Optimistic cases
are excluded, as in CI.
- **Manual INSERT IGNORE check.** `INSERT IGNORE ... SELECT` from a
flushed table turns NULLs into implicit defaults, with one warning per
cell. The source still reads its NULLs with a cold and a warm cache.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

This branch was previously deployed

1 inactive deployment
ci — 9bef8785 Deployed Nov 22, 2026 by fengttt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor Code refactor size/L Denotes a PR that changes [500,999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants