Skip to content

refactor(batch): remove Attrs from Batch - #33199

Merged
fengttt merged 9 commits into
matrixorigin:mainfrom
fengttt:batch-remove-attrs
Nov 25, 2026
Merged

fengttt merged 9 commits into
matrixorigin:mainfrom
fengttt:batch-remove-attrs

Conversation

@fengttt

@fengttt fengttt commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • Refactoring

Which issue(s) this PR fixes:

Part of #33182 (batch cleanup, #32921).

What this PR does / why we need it:

Removes Attrs from batch.Batch. Column names belong to whoever defines the columns: the plan, a table definition, or a workspace entry. They now travel beside the batch wherever an API needs them.

Batch API

  • These are removed: the Attrs field, New(attrs), SetAttributes and GetSchema.
  • NewWithTypes(typs, mp) replaces NewWithSchema, and Types() replaces GetSchema().
  • SelectColumns, CloneSelectedColumns and InsertVector no longer take names.
  • BatchToProtoBatch(bat, attrs) takes names explicitly.
  • The stable codec keeps its column-name section but writes it empty by default.
    • MarshalBinaryWithNames and MarshalBinaryWithBufferAndNames write names for messages whose receiver identifies columns by name.
    • WireNames(data) reads those names back without decoding the vectors. Only tests call it, to pin what this version writes for older CNs.

Engine

  • Relation.Write(ctx, bat, attrs) and Relation.Delete(ctx, bat, attrs, name) now take the column names.
  • disttae workspace entries own their names, and CN→TN api.Batch carries exactly the names it carried before (TN keys columns by name).
  • On TN, cmd_util.WriteReq and the catalog request structs carry the api.Batch names. AppendDataToTable and containers.ToTNBatch take them as arguments.
  • logtailreplay keeps the logtail names in ReplayBatch. An empty name still marks a dropped column.
  • Readers get their column lists from the code that defines them, for example the ckputil/GC schema constants and OneSchemaBatchBuffer.Attrs().

Mixed-version CN compatibility (the wire format is unchanged)

  • Decode, never use. Every decoder parses and skips the name section, whatever its count, so a new CN reads an older CN's batches. No production code reads names from the wire. Each consumer takes them from its plan or from its producer's fixed layout:
    • multi_update flush and mergedelete: a delete blob with a leading rowid column is a row delete, otherwise tombstone object stats (colexec.RelayedDeleteAttrs). Inserts are always the S3 block-info layout.
    • The deletion and multi_update relay recognizers find the object-stats column by its position in the producer's fixed layout.
    • mergeblock's legacy in-memory data batches are named from the plan's table definition (MergeBlock.Attrs, the same rule insert uses).
  • Write for older CNs. Serialized metadata batches inside relay rows (deletion, multi_update) are still written with their names, because older consumers read them.
  • The remote-run sender writes the insert-S3 and remote-delete producers' fixed names on matching relay batches. This only happens when its scope runs that producer, and it means older coordinators still recognize them. Everything else is sent without names.
  • New receivers recognize relay layouts by vector count and types, still behind the scope-admission gate.

Behaviour changes for reviewers

  • Iceberg DML/append: these now trust the plan's column positions. The name-based re-matching was defensive code from the connector's introduction (feat(iceberg): add external Iceberg connector #25368); there was no observed case it fixed.
  • Data-branch hashdiff: main used the batch's names to skip projecting base batches already in the target layout (those from relations before an ALTER). The projection to the target layout now wraps only the current base relation's change handle (currentBaseChangesHandle). Historical handles already yield the target layout, so the decision comes from which relation a handle reads, not from the batch. This fixes the BVT diff_output_as_altered_columns failure.
  • Bug fixed while testing: the legacy checkDup duplicate-key message read names from a batch that had none, which could panic. It now uses the entry's names.

Validation

  • go build ./..., go vet ./pkg/... ./cmd/... and gofmt are clean.
  • mo-cgo-test -count=1 passes on all 88 changed packages (86 ok, 2 with no tests). After the decode-never-use follow-up, it passes again on pkg/sql/colexec/..., pkg/sql/compile/... and pkg/container/batch (72 packages).
  • New tests:
    • WireNames round-trip, and empty names by default.
    • Relay sender naming: producer layout vs. other batches.
    • Inner blobs carry names for older CNs, but consumers ignore them: blobs with no names, or misleading ones, produce the same result.
    • Extractors recognize relay batches that carry no names.

🤖 Generated with Claude Code

A batch carries no column names. Names belong to whoever defines the
columns (the plan, a table definition, a workspace entry) and travel
beside the batch where an API needs them.

- batch: drop the field, New, SetAttributes and GetSchema; add
  NewWithTypes and Types; SelectColumns, CloneSelectedColumns and
  InsertVector lose their name arguments; BatchToProtoBatch takes attrs.
- codec: the stable format keeps its column-name section, written empty
  by default. MarshalBinaryWithNames / MarshalBinaryWithBufferAndNames
  write names for self-describing messages; WireNames reads them back.
- engine: Relation.Write(ctx, bat, attrs) and Delete(ctx, bat, attrs,
  name). disttae workspace entries own their names and send TN exactly
  the names they sent before; TN WriteReq and catalog requests carry
  the api.Batch names; logtailreplay keeps them in ReplayBatch.
- mixed-version CNs: relay inner blobs are written with their names; the
  remote-run sender writes the insert-S3 and remote-delete producers'
  fixed names on matching relay batches, so older coordinators still
  recognize them. New receivers recognize relay layouts by vector types.

Refs matrixorigin#33182

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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 →

@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Nov 25, 2026
@mergify

mergify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

fengttt and others added 2 commits November 24, 2026 21:17
A new CN decodes the column-name section an older CN writes, but no
production code uses it. Consumers that read names back with WireNames now
take them from what they already know:

- multi_update flush and mergedelete name a relayed delete batch by its
  layout (colexec.RelayedDeleteAttrs: leading rowid is a row delete,
  otherwise tombstone object stats); inserts are always CNS3ResultAttrs.
- The deletion and multi_update relay recognizers locate the object-stats
  column from the producer's fixed layout.
- mergeblock names legacy in-memory data batches from the plan's table def
  (MergeBlock.Attrs).

Producers still write names into relay blobs so older CNs keep working.
WireNames remains for tests that pin that output. Tests now show wire names
are ignored: blobs with no names or misleading ones give the same result.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve conflicts with the squashed matrixorigin#33184 (private extraBuf, lender-owned
pins): take main's side and drop the batch Attrs uses this branch removes.
Port the new ivfflat flush-ownership test to explicit proto names.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fengttt added a commit to fengttt/matrixone that referenced this pull request Nov 25, 2026
Brings PR matrixorigin#33199 onto this branch as one commit. Its commits:

--- refactor(batch): remove Attrs from Batch

A batch carries no column names. Names belong to whoever defines the
columns (the plan, a table definition, a workspace entry) and travel
beside the batch where an API needs them.

- batch: drop the field, New, SetAttributes and GetSchema; add
  NewWithTypes and Types; SelectColumns, CloneSelectedColumns and
  InsertVector lose their name arguments; BatchToProtoBatch takes attrs.
- codec: the stable format keeps its column-name section, written empty
  by default. MarshalBinaryWithNames / MarshalBinaryWithBufferAndNames
  write names for self-describing messages; WireNames reads them back.
- engine: Relation.Write(ctx, bat, attrs) and Delete(ctx, bat, attrs,
  name). disttae workspace entries own their names and send TN exactly
  the names they sent before; TN WriteReq and catalog requests carry
  the api.Batch names; logtailreplay keeps them in ReplayBatch.
- mixed-version CNs: relay inner blobs are written with their names; the
  remote-run sender writes the insert-S3 and remote-delete producers'
  fixed names on matching relay batches, so older coordinators still
  recognize them. New receivers recognize relay layouts by vector types.

Refs matrixorigin#33182

--- refactor(batch): never read column names from the wire

A new CN decodes the column-name section an older CN writes, but no
production code uses it. Consumers that read names back with WireNames now
take them from what they already know:

- multi_update flush and mergedelete name a relayed delete batch by its
  layout (colexec.RelayedDeleteAttrs: leading rowid is a row delete,
  otherwise tombstone object stats); inserts are always CNS3ResultAttrs.
- The deletion and multi_update relay recognizers locate the object-stats
  column from the producer's fixed layout.
- mergeblock names legacy in-memory data batches from the plan's table def
  (MergeBlock.Attrs).

Producers still write names into relay blobs so older CNs keep working.
WireNames remains for tests that pin that output. Tests now show wire names
are ignored: blobs with no names or misleading ones give the same result.

--- fix(data branch): project only the current base relation's batches

Base-side change batches come from several relations: the current base
table (base layout, projected to the target layout with baseColToTarIdx)
and historical relations from before an ALTER, whose handles already yield
the target layout (projected by historicalDataBranchChangesHandle, or
identical to it and left unwrapped). The hashdiff loop projected every
base batch; main skipped the second projection by the target-layout names
the batch carried. Without batch names, historical batches were projected
again with the current base mapping, so after `alter table ... drop
column` a diff read `amount` from the wrong column (BVT
diff_output_as_altered_columns: "Column 'amount' cannot be null").

Move the projection onto a currentBaseChangesHandle that wraps only the
current base relation's handle, so the decision comes from which relation
a handle reads, not from the batch.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The upstream merge brought code that appended these names to
ctr.buf.Attrs. With Attrs gone from Batch those appends were removed,
leaving the constants unused and failing SCA. Consumers locate the
columns by index (AutoIncrementGeneratedColumn), not by name.

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

XuPeng-SH commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · superseded

Commit: 6e9a7981ccbc89f4c5ac9f87aa01a467b191caaa

"interrupted"

This branch was successfully deployed

No deployments
ci — e63215dd Deployed Nov 25, 2026 by fengttt
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.

3 participants