Skip to content

compute: Emit TopK monotonic and basic output as the columnar edge - #37783

Open
antiguru wants to merge 3 commits into
columnar-p5-arrangement-materializationfrom
columnar-p6-topk-output
Open

compute: Emit TopK monotonic and basic output as the columnar edge#37783
antiguru wants to merge 3 commits into
columnar-p5-arrangement-materializationfrom
columnar-p6-topk-output

Conversation

@antiguru

@antiguru antiguru commented Jul 21, 2026

Copy link
Copy Markdown
Member

Monotonic and basic TopK emit their from_collections output as the columnar edge. Bucketed TopK is already covered by the shared arrangement-materialization path (P5).

Columnar dataflow-edge migration. Design doc: doc/developer/design/20260720_columnar_dataflow_edges.md (#37744).

Part of CPU-51.

@linear-code

linear-code Bot commented Jul 22, 2026

Copy link
Copy Markdown

CPU-51

@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from c790948 to 31a84a6 Compare July 22, 2026 16:24
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 31a84a6 to 2f27548 Compare July 22, 2026 17:51
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 2f27548 to 1536039 Compare August 19, 2026 12:01
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 1536039 to 15eb779 Compare August 19, 2026 13:17
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 15eb779 to 10e7a85 Compare August 20, 2026 08:49
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 10e7a85 to 8ee12e6 Compare August 20, 2026 09:13
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 8ee12e6 to 40d648a Compare September 6, 2026 18:23
Comment on lines 324 to 326
let (oks, errs) = self.build_topk(
ok_input, group_key, order_key, offset, limit, arity, buckets,
);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We should remember to push columnar containers further down into top-k.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recorded as a TODO on topk_result_to_columnar, the seam that owns the encode:

/// TODO: TopK renders its stages over `Vec` containers, so this encode sits at
/// the very end of the plan. Pushing columnar containers down through
/// `build_topk` and the monotonic path would remove it.

Both TopK paths reach the edge through that one function, the monotonic arm directly and the basic arm via build_topk, so a single note covers the whole operator rather than one per call site.

Doing the push-down itself needs the same treatment mz_join_core got in #38368: build_topk's stages chain through arrangements, so only the last stage can write the output edge, and the fallible-limit arm materializes rows before the demux. Happy to take it as a follow-up PR on top of the stack if you want it before this lands.

Posted by Claude Code

@antiguru
antiguru marked this pull request as ready for review September 10, 2026 11:29
@antiguru
antiguru requested a review from a team as a code owner September 10, 2026 11:29
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 40d648a to 8def045 Compare September 10, 2026 11:33
antiguru and others added 3 commits September 10, 2026 14:07
Flip the two TopK plans that build a result collection (MonotonicTopK and Basic)
to produce a `CollectionEdge::Columnar` via a shared `topk_result_to_columnar`
helper. The bucketed MonotonicTop1 plan emits an arrangement and is materialized
by the shared `as_specific_collection` path, so it is untouched.

Both sites drop the hash-key pairing from a `consolidate_named`-consolidated
`(hash_key, row)` collection. The hash key is a function of the row, so the drop
is injective and the output has no within-batch duplicates. A non-consolidating
`ColumnBuilder` therefore matches the prior `map` semantics, and the row is
pushed borrowed.

The err collection stays `Vec`, and the intra-operator machinery stays on `Vec`.
Also corrects a stale comment on `map_topk_key`: its columnar arm runs once the
input edge is columnar, which the upstream producers now emit.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment-only, no behavior change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
TopK renders its stages over `Vec` containers, so the columnar output edge
is produced by a single encode at the end of the plan. Note at that seam that
the encode disappears once the stages themselves carry columnar containers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@antiguru
antiguru force-pushed the columnar-p6-topk-output branch from 23a66b9 to b1c836e Compare September 10, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant