#53898·milvus

[Enhancement]: Arrow transport and reduce for the retrieve path

Author: tedxuCreated Sep 28, 2026Updated Sep 28, 2026

Is there an existing issue for this?

  • I have searched the existing issues

Description

PR #52973 introduced Arrow at one CGO boundary in the retrieve path — FillRetrieveFieldsOrdered, serving phase 2 of the two-phase "IgnoreNonPk" pipeline. It measured a 5.6x improvement at that boundary. Two things remain open.

1. There are two CGO boundaries in retrieve, and the one on every path is still protobuf.

Boundary Used by Carries Status
AsyncRetrieve -> CreateLeakedCRetrieveResultFromProto -> unmarshalCProto every retrieve path IgnoreNonPk: PK + offset + timestamp. Standard: the entire payload protobuf
FillRetrieveFieldsOrdered -> arrow.Record IgnoreNonPk phase 2 only payload Arrow, gated off

CreateLeakedCRetrieveResultFromProto (segment_c.cpp:569) does a full SerializePartialToArray; unmarshalCProto (cgo_util.go:74) does a full proto.Unmarshal onto the Go heap. This boundary has never been optimized.

2. The Arrow record never escapes one function. fetchFieldsArrow (ignore_non_pk_ops.go:225) imports the record at line 233, converts it at line 239, and releases it at line 237. Its entire lifetime is six lines. The queryutil pipeline framework is Arrow-unaware, so the QueryNode reduce still gathers proto row by row in queryutil/helpers.go.

Why this matters most for the standard pipeline

shouldEnableIgnoreNonPk (retrieve.go:128) requires segmentNum > 1 && limit != Unlimited && !hasGroupBy && planShouldIgnoreNonPk. Everything else takes the standard pipeline, which moves the full payload through protobuf. That includes:

  • Search requery — search_pipeline.go:1308 builds its QueryRequest with no QueryParams, so Limit is always Unlimited. Requery fires by default whenever a search requests any vector or TEXT output field (any output field, for hybrid search), which is the most common Milvus workload shape.
  • Query without an explicit limit (Go SDK and REST both omit it by default)
  • Upsert retrieveByPKs (task_upsert.go:189) and getVectorByIDs (impl.go:3511) — both always Unlimited
  • Single-segment queries, and ORDER BY

All of these bottom out in the same AsyncRetrieve call, so moving that one boundary to Arrow covers every one of them at once.

Proposed change

This mirrors what the search path already did in #48986, applied to retrieve.

Stage 0 — validate and enable what exists. common.interface.zeroCopy is still default-false, undocumented and unexported. Validate, benchmark, flip it. No new code before this.

Stage 1 — phase-1 Arrow export. New AsyncRetrieveAsArrow, a sibling of AsyncRetrieve that reuses segment->Retrieve() verbatim and replaces only the serialization step. Because Retrieve() already takes its own shared_lock, this needs no new virtual method — avoiding the vtable/SIGSEGV constraint documented at SegmentInterface.cpp:506.

Stage 2 — gather into Arrow buffers. SegmentInterface.h:918 already declares a bulk_subscript overload that gathers into a caller-supplied raw buffer (in use at Utils.cpp:1573). Passing an arrow::Buffer pointer fuses two copies into one, again with no new virtual method. Also: stop discarding the arrow::Table that TryTakeForRetrieve already produces (ChunkedSegmentSealedImpl.cpp:10052).

Stage 3 — Go-side Arrow reduce. Carry chain.DataFrame through the queryutil pipeline and reduce on Arrow. The framework needs no structural change (OpMsg is map[string]any), but Pipeline.Run needs a Releasable sweep, since it currently never clears intermediate channels and abandons them on error — harmless for proto, a leak of pinned C++ memory for Arrow.

Stage 4 — remaining C++ copy elimination. Separate issue. MergeDataArray runs unconditionally even for a single segment (two in-tree TODOs at Utils.h:105, Utils.cpp:875), plus the redundant FixedVector for system fields.

Scope

Deliberately bounded. The QueryNode->Proxy wire format stays protobuf, the Proxy reduce is untouched, the SDK contract is unchanged, and shouldEnableIgnoreNonPk's admission logic is left exactly as it is — those conditions are about discard rate and are correct.

What this does and does not claim

Removes two protobuf codec passes from every retrieve path, and replaces the proto row gather. It is not zero-copy: Stage 1 adds a DataArray->Arrow copy in exchange for removing the codec passes, and the per-row costs for VarChar, JSON and Array remain until later stages. The theoretical floor is one copy (the gather), not zero — retrieve selects arbitrary row offsets, so a gather is definitionally a copy.

Design doc

To be submitted under docs/design-docs/design_docs/.

Anything else?

Related: #48986 (the search-side equivalent, already shipped), PR #52973 (the phase-2 Arrow boundary this builds on).