* test(promql): feed the label-rewrite tests through an explicit input slot The runtime takes an input position now, so the tests that a label rewrite brought in name the leaf they push at, and the map import no longer carries the operation type the runtime reads through `MapOp`. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): feed the newly added native tests through input slots The histogram-function and range-modifier tests that landed on the branch use the execution entry points as they were before the runtime took an input position, so they name the leaf they push at. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(query): preserve legacy semantics at native admission Signed-off-by: discord9 <discord9@163.com> * test(query): iterate captured delta result batches Signed-off-by: discord9 <discord9@163.com> * test(query): cover fused Columnar Float64 execution Signed-off-by: discord9 <discord9@163.com> * refactor(promql): keep runtime trees owned by their executions Register each execution's node metric handles once in the physical plan's metrics set. Reading metrics no longer retains or locks runtime topology. Keep historical counters alive after execution drop and cover repeated reads and executions. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): register binary metrics before execution Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(mito2): read raw series when columnar indexes are not ready Keep native queries available for unflushed memtables and SSTs with incomplete columnar series or samples coverage by selecting the ordinary raw-series reader. Preserve structural validation and propagate artifact read errors instead of retrying them through legacy execution. Cover all four incomplete-readiness states in public PromQL queries, both storage scan modes and ordering, complete prepared-source execution, and artifact error propagation. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): keep fused POC execution partition-local Remove plan-global label-set occupancy and the speculative split-series tree guard. Keep the native evaluator, finality, memory budgets, errors and ordinary RecordBatch output local to each scan partition. Narrow native admission to selectors and the small unary POC subset. Document that cross-partition final-label conflicts and semantic merging are outside this POC, and cover real rate/abs(rate) execution across dense and sparse storage spanning SST and memtable data. Signed-off-by: discord9 <discord9@163.com> * test(promql): use an instant-vector subquery boundary case Signed-off-by: discord9 <discord9@163.com> * test(promql): restore the shared pool fixture for metric lifecycle tests Signed-off-by: discord9 <discord9@163.com> * feat(promql): bind selector occurrences without node paths Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): cover selector bounds and recursive binding contracts Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): avoid cloning a selector binding for validation Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): resolve runtime input ids from source bindings Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): lower independently bound vector binary operands Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): correct distinct-input arithmetic expectations Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): fan out a shared raw scan to bound binary inputs Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): align frame ordering and SQL result sorting Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): align native display and shared-source scan expectations Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): account for counter-zero range extrapolation Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): record shared-selector SQL regression results Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): read bounded scan metrics through cooperative wrapper Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): execute independent selector scans in fused binary trees Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * style(promql): satisfy strict fused adapter lints Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): regenerate independent matcher and range results Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): adapt complete aggregate wiring to recursive native runtime Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): preserve partial prefix rejection diagnostic Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): align aggregate row adapters with current native APIs Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): align aggregate admission with boxed parser inputs Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): admit complete aggregate in native shape coverage Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * style(promql): attach native predicate rustdoc directly Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): execute zero-input scalar roots through fused children Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): verify scalar routes and four-partition broadcasts Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): disambiguate the frontend SQL test helper Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): prove each scalar-route partition produces output Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): import partition properties for output assertions Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): let query encoding use auto-deref Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): retain and verify empty vector result schemas Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): cover scalar aggregate composition and fallback Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): scope partition proof to unfiltered scans Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): quote region label in Mito fixture SQL Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): fix scalar schema ownership and rebuild API Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): align admission expectations with literal entry Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): use fixed scalar batch fixture Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): bind instant anchors and execute native timestamps Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): cover the multi-value timestamp refusal Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(series): unify raw and evaluated SeriesFrame codec SeriesFrame is the internal transport of the Narthex native PromQL path, and it could only carry raw samples: an evaluated result had to fall back to a plain row table. This makes one self-describing Arrow format carry both, so a receiver decodes a frame from the frame alone, without the scanner, region, or planning context its producer had. What is unified is the physical representation and its codec, not the runtime data structures. RawSeriesChunk, Series, and EvaluatedChunk stay as they are; only the adapter boundaries branch on the sample shape. Three combinations are legal and every other one is refused in both directions: raw + key + timestamps a storage raw-series scan raw + explicit + timestamps a raw input whose labels are decoded evaluated + explicit + grid_spans a compute node's output An evaluated frame cannot claim a storage key, because the computation may rewrite its labels; raw samples have no grid to be addressed on. The schema builder and the declaration parser both enforce that, so a frame cannot be written or read in a shape no producer could mean. An evaluated frame declares its GridSpec once in schema metadata and carries absolute grid positions per row as spans, so a sparse grid costs its runs and not its holes: nothing is expanded, and no position a chunk does not hold is filled in. A chunk with no position is legal exactly when it closes its chain, and it is kept as one frame row, because dropping it would drop the finality it exists to carry. Layout is v2 and the writer and reader of the reserved greptime.series.* metadata live in one place each, so a producer and a consumer cannot spell one frame two ways. The unreleased v1 format is not read: the in-tree producers, consumers, tests, and the two frozen wire fixtures all move to v2 together. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> (cherry picked from commit176f6f6479) * fix(series): validate v2 ordering and repair scan binding fixtures Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(series): pin literal ordering declarations and decoder validation Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(series): remove unused decoder fixture binding Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(test): port MinIO conditional-write test fix to narthex (#9930) fix(test): avoid MinIO connection reuse after conditional writes (#9877) Signed-off-by: WenyXu <wenymedia@gmail.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> Co-authored-by: Weny Xu <wenymedia@gmail.com> * feat(promql): add a series frame output to the fused native node The fused node answers one way: a row table with the grid timestamps, one column per series field and one per declared tag. That is what a query returns, but a consumer of the native path needs to tell series and positions apart, and the row shape flattens both away - which series a value belongs to, and which grid positions that series actually holds. This adds a second output format, fixed when the plan is built rather than chosen at run time: PlainRows the existing row table, unchanged and still the only one a query reaches SeriesFrame the same evaluated chunks handed over as the unified series frame The format is part of the plan because it decides the node's output schema, so it takes part in the node's equality, its EXPLAIN text and its rebuild over new children. A row-table plan prints exactly what it printed before; a frame plan says so on its own line. A frame is encoded straight from each evaluated chunk, never by flattening it into rows and packing it again, so a sparse series keeps its runs and a closing chunk with no position is still one row. The output keeps one partition per input partition: a frame is not a reason to coalesce, and no exchange is inserted in either format. The partial-state output that a complete aggregate reads is a third thing again, and the format does not reach it. When a node exports partition-local state, the format is `PlainRows` by construction, `convert` hands every chunk to the fold before any format is consulted, and the EXPLAIN line keeps its `partial state:` suffix. Nothing in the aggregate path is rewritten to make room for frames. A tree whose root is not evaluated samples is refused while the plan is built, because aggregate state is a contribution to a later merge and a scalar has no series to name. So is a frame output over more than one raw source, which this node does not run in parallel yet. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): pin the frame output's boundaries and its pending hand-over The frame output was covered for its happy path and for the plan-level decisions, but three things the spec asks about had no test of their own at this boundary, and one test did not prove what it claimed. The pending test is the one that mattered. It awaited the stream, and `StagedStream` wakes itself right after reporting pending, so the await ran straight through the boundary: every later assertion held whether or not the buffered rows were handed over at the pending poll. It now polls that single poll by hand and requires it to answer the rows it already encoded. Deleting the `flush_frames` call from the pending branch makes it fail, which it did not before. The three boundaries now have their own tests: a chain that closes with no position survives as one row where the row table answers nothing at all; a sparse series carries exactly the positions the row table answers and no filled hole; and two chains that close on one label set are both kept, with values that differ so a lost chain would show. Also drops the `as_str` helper, which only asked whether to show a format and then spelled the same string twice, and corrects two comments: `convert` produces three outputs rather than two, and a built plan is not a promise that execution cannot fail. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): stream evaluated frames with batch-level backpressure Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): keep the frame output tests lint-clean The workspace denies the default Clippy warnings, and the new tests tripped three of them without changing what any of them proves: - an expected value was built through `scale as f64` even though the tuple already carries an `f64`, so the conversion is spelled in the literal and the cast is gone; - the standalone replay printed the executed plan and the per-partition counts even though the surrounding assertions already require four nonempty partitions, 24 rows in total and eight closing frames, so the diagnostics are gone rather than exempted from the workspace lint. No production code, assertion or fixture changes. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): finalize topk over globally merged aggregates Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): compile and run set operators natively Bind `and`, `or` and `unless` (with `on`/`ignoring`) to a new `NativeExpr::Set` node instead of refusing them. The node runs the existing MATCH-SET kernel through the binary runtime, which retains both operands until the input ends, so a set operation reads every series of both sides in one execution. The set kernel now reports its workspace like the binary kernel does: kept rows, the filter side's match groups, the sort and the merge are charged to the node's reservation. The compiler refuses a fill value on a set operator, which Prometheus rejects and the parser accepts, and sides with different field counts. Same-table set operations over two scans take the existing two-scan native route. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(query): keep two-selector native plans off partitioned tables A two-scan FusedSeries over a table split into several regions has no placement: DistPlannerAnalyzer rejects it with "only accept plan with at most one child", so the query failed instead of falling back. This hit the existing arithmetic pair and, since set operators now compile, set operators too. Decline the native route for two selectors when the table has partition columns. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): leave multi-field set operations to the legacy plan The legacy planner refuses `and`, `or` and `unless` over several fields (MultiFieldsNotSupported), and Prometheus has one value per sample, so per-field presence has no reference semantics. The compiler now declines a set operation unless each side has exactly one field, and the query keeps the legacy plan and its error. Errors raised by the shared two-operand runtime now name the set node instead of calling every such node "the binary node". Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * perf(promql): decide set membership from a per-group presence bitmap The set kernel checked every filter series of a kept series' match group at every kept point, so a coarse `on()` / `on(...)` cost O(kept series x points x group size). Prometheus decides a step from the set of signatures present on the filter side. Build one bitmap per filter match group, one bit per grid point, from the filter side's rows, and look each kept sample up in O(1). Each bitmap is charged to the walk phase when its group is first met and is released with the group table before the sort phase. Results are unchanged. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): fuse independent operands of hybrid binary queries Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): hold the labels of queued results until they are handed on A node that reads its whole input (binary, set, vector) queues the series its kernel produced and settles its reservation on the queue. Each queued result was held for `evaluated_bytes`, which covers the chunk and its fields but not the label set the chunk owns, so once the operands were released the reservation dropped below what the queue actually held. A set over many long-labelled one-point series made the gap large. Hold each result that does not share the input for `series_bytes`, the complete owned estimate including labels. The figure stored with the entry is still the one released when it is handed on. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): pin per-step or matching through the native entry A range query `a or on(host) b` where one host's left series covers only the middle steps: native must keep the left sample where it exists and take the right sample with its own labels at the other steps, matching the explicit rows and the legacy plan. The set test's row reader moves to module level so both cases share it. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): narrow global topk partition recording Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(promql): reuse prepared native operand context Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): address global topk review feedback Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): strengthen hybrid binary review regressions Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): run cross-table selector pairs natively A binary or set operation between selectors of two tables, such as `rate(a[5m]) / rate(b[5m])`, fell back to the existing plan: the native route required every input to share one metric, time index and tag list, and a fused node is placed inside the one region it reads. Two tables are two regions, so such a pair now runs on the frontend. Each input becomes a `RawSeriesSource` that rides in its own merge scan: the region binds its scan to that table's metric, tags and fields, decodes the labels and answers one explicit-label raw frame stream, reading its scan partitions one after another so each series stays contiguous. The fused node consumes those frames directly. Pairs on one table keep running in the region; partitioned tables keep the existing plan. A point-wise wrapper around an admitted pair, such as `100 * (1 - a / b)`, is admitted too, on one table and across two. The output labels are now derived from the whole tree with each input's own tags, and the physical node takes them from the output schema instead of narrowing by the root alone. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): decline cross-table outputs the native node cannot name Under `or` the right table's tags join the left side's columns, and one of them can share a name with the left side's field or time index; building the output schema then failed instead of leaving the query to the existing plan. Such a union is now declined. The output-label walk also declines an aggregate or whole-vector node instead of passing its input's labels through, which would describe the wrong schema if one were ever reached. Adds an end-to-end case over two tables whose tags, field and time index are all named differently, partly flushed and partly in the memtable, under both series scan modes. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * perf(promql): read native inputs and scan partitions concurrently A multi-input FusedSeriesExec drained every partition of its first input before it touched the second, and RawSeriesSourceExec drained its scan partitions one after another. The series distributor feeding those partitions then waited on the one partition being read, the two inputs' scans never overlapped, and all decoding ran on the one consuming task. Read every partition through SeriesGather instead. It polls all of them and hands a chunk on unless another partition of the same input has a series open; such a chunk is held until that series closes, so each input still sees contiguous series. A partition holding a closed series is not polled again until it is handed over, which bounds what is held to one series per partition, and that is charged to a memory reservation. Inputs do not constrain each other. When there is more than one partition, each is driven on its own query task with a two-chunk channel, so the scan conversion, frame codec and label decode of different partitions run in parallel. Dropping the stream aborts those tasks, and a task that panics ends its partition in an error rather than a silent end. On the o11ybench vmlite/vmlong data (standalone, native ON, median of 10 alternating runs; results byte-equal to the sequential reader): sequential* this change vmbench-lite-05 4.4ms 3.0ms vmbench-lite-06 7.3ms 4.2ms vmbench-lite-08 5.0ms 3.3ms vmbench-long-range-03 54.4ms 39.6ms cpu same-table pair 27.6ms 15.3ms long fs same-table pair 104.2ms 83.6ms * with the series distributor fix; without it the sequential reader stalled for up to 12.8s on these queries, and this change does not need that fix. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): delegate fused frame output to the shared packer (#9968) Reuse pack_evaluated_series for fused Frame output, preserving the single native driver and PlainRows/partial timing. Reject mismatched logical frame schemas and use the reset scan plan in integration tests. Add evaluated-packer lifecycle and invalid-sequence regressions, and address the review follow-ups. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): run vector-vector comparisons natively A one-to-one comparison between two selectors, such as `a > on(host) b` or `a == bool b`, kept the existing plan: the pair admission accepted only arithmetic operators. The kernel already pairs comparisons by the same matching rules and only differs in the value a pair keeps (the left sample when the comparison holds, or 1/0 with `bool`), so the operator check is dropped. This covers one table and two, and the point-wise wrappers around a pair, such as `(a > b) * 100`. Adds an end-to-end case over two tables comparing explicit rows, the legacy answer and the native placement for a filter and a `bool` comparison. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): charge the chunks a spawned partition reads ahead A spawned partition queues up to two chunks and its task holds a third while the queue is full. None of them was charged to a reservation, and since they carry materialized labels their size is unbounded even though their count is not. Each chunk is now charged to the query's memory pool when the task reads it, and the charge travels with the chunk: it is released when the chunk is handed to the gather, which charges what it holds back itself, or when the chunk is dropped in the queue or in an aborted task. A pool that cannot hold the next chunk ends the partition in an error. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(mito2): stop the series distributor from stalling on unread partitions (#9991) When every partition channel is full, the distributor walked the senders round-robin with a 100us send timeout each. Tokio timers fire on a 1ms tick, so a consumer that leaves some partitions unpolled costs about one millisecond per unpolled partition for every series batch. SeriesScan::build_stream and scan_all_partitions drain partitions one after another, and SortPreservingMergeExec above a multi-partition SeriesScan only pulls the partition holding the current minimum key. With 16 partitions and one batch per series after a merge, a 40-series scan read partition by partition took ~480ms (measured on the native PromQL two-input route). Wait on all senders at once and send to the first one that frees a slot. The send-timeout metric goes away with the timeout. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> (cherry picked from commite6b60644b3) Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): add explicit local canonical merge operator (#9969) * feat(promql): add explicit local canonical merge operator Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): tighten canonical merge accounting and validation Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(promql): remove redundant merge tree whitelist Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): retain canonical merge output label reservations Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(promql): finish canonical merge review simplifications Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): pin the parent barrier over canonical merge Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): assert the two-selector binary stays unfused Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --------- Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): keep the right side's labels for a filled left side across tables Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): repair native execution contracts and remove obsolete paths (#9980) * fix(promql): restore native scan statistics and remove unused raw merger Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): repair native execution contracts and remove obsolete paths Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(promql): leave fused frame output repairs to separate PR Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * docs: restore native contracts and regenerate config reference Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix: slice nullable sparse frame fields after span selection Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): intersect anchored timestamp selection windows Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(query): name anchored timestamp boundary case type Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): align partitioned pair checks with hybrid operands Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --------- Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> * feat(promql): run native statements over any number of selectors (#10004) * feat(promql): run native trees with more than two selectors Lift the two-selector cap of the native PromQL route. A tree of one-to-one vector matches and set operators, nested under point-wise wrappers, is now admitted for any number of selectors: on one table the node runs in the region over every scan, across tables it runs on the frontend over one RawSeriesSource per selector. Partitioned tables, aggregates, whole-vector operations and many-to-one matches still keep the existing plan. The dist analyzer and commutativity checks accept a same-table node with more than two scans; without that such a plan fails in the analyzer. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): cover nested set operators and metric-engine multi-selector decline Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): wait for aborted partition tasks to release their inputs Signed-off-by: Dennis Zhuang <killme2008@gmail.com> (cherry picked from commit 3f8699782c3116c4063ec70a3522d1f5f3bff897) * docs(promql): say spawned partitions are released after an error, not before Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * perf(promql): resolve the vector match result row once per pairing (#10007) * perf(promql): resolve the result row once per pairing in vector match Signed-off-by: discord9 <discord9@163.com> * docs(promql): state the native node metric naming contract Signed-off-by: discord9 <discord9@163.com> * bench(promql): make the vector match timing reproducible Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): run info() natively (#10005) * feat(promql): run info() natively info(v, {selector}) fell back to the existing plan, which has no info and refuses the query ("Unsupported expr type: info", or "Cannot accept multiple vector as function input" when a selector is given). Compile it into the native tree and run it on the info kernel: - Plan: NativeExpr::Info { base, info, selector }. The info side is an instant selection reporting each selected sample's own time in milliseconds (InstantValue::InfoTimestamp, which replaces the BoundInstant.timestamp flag); validation refuses any other info side. - Compiler: info_input derives the info selector the way Prometheus does: target_info or one __name__="..." matcher, the data matchers, and the @ and offset every selector of the first argument shares (subquery offsets added until an @ anchors them, none when they differ). Regex or negative name matchers, which can select several tables, __field__/__schema__/__database__ matchers and multi-field info tables are refused. The planner's selector walk uses the same helper, so both bind the info table as the last input. - Runtime: BinaryRuntime runs the kernel as PairKernel::Info, with the retention and pool accounting of binary and set nodes; the kernel reports its workspace through info_with_reservation. - Planner: the info table is a second table, so it is read through its own RawSeriesSource and the node runs on the frontend. The output adds the info table's tags, or only the data labels the selector names. Partitioned or non-Mito tables and a missing info table keep the existing plan. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): pin region-local placement of info over its own table info(rate(target_info[5m])) reads the info table twice. Check that the planner binds both as direct scans under one FusedSeries node bound to the table, that the node is placed in the region, and the columns it reports. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): keep sample-less base series out of info's identifying patterns Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): share identifying label strings in info() instead of copying them Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): keep a group's points together when decoding aggregate state (#10008) * fix(promql): keep a group's points together when decoding aggregate state The state encoder writes a group's points in ascending order, one row per (point, field). The decoder opened a group whenever the row's point differed from the group's first point, so every point of every group became its own group: each row re-allocated the label set's `Arc<str>` strings, and the merge then re-hashed those labels and repeated a map lookup for each of them. Open a group only when the labels change. A later point of the same group is appended to it and a repeated point is that point's next field, which keeps the arrival order of every (point, field) and therefore the floating-point merge order unchanged. A point that goes backwards within a group is refused. Appended points and their state vectors are admitted before they allocate. Measured with paired alternating A/B on one prepared vmbench-lite database, 30 measured requests per run, opposite order each round, 6 rounds: Q02 avg without(cpu) 5m p50 A/B 1.60, CPU A/B 1.25, 6/6 rounds faster Q11 sum by 4 tags 5m p50 A/B 1.57, CPU A/B 1.49, 6/6 Q01 100-(avg(...)*100) p50 A/B 1.40, CPU A/B 1.25, 6/6 Q10 count by p50 A/B 1.04, CPU A/B 0.99, 4/6 (neutral) Q03 sum by region,az p50 A/B 0.92, CPU A/B 0.87, 2/6 (slightly slower) `cargo nextest run -p promql` 987 passed, 0 skipped. Signed-off-by: discord9 <discord9@163.com> * fix(promql): accept concatenated aggregate state instead of rejecting it Review of #10008 found three problems. `decode_state` refused a row whose point went backwards within its group, and refused a repeated `(point, field)` pair. Both are real inputs once state crosses Flight: `CoalescingBatcher` merges consecutive small batches (`servers/src/grpc/flight/stream.rs:313`), so two partitions' state for one group arrives back to back and the second restarts the group at its first point. Accept them instead: the merge addresses points by index (`aggregate/state.rs:396-423`) and folds groups by label key, so a second entry for the same point lands in the same slot, exactly as merging the two batches separately would. Out-of-grid point and field indices are still errors. The doc comment on `decode_state` still described the old rule (a change of label or point opens a group); only a label change does now. `decode_admits_the_points_it_appends` did not test what it claimed: the fixed layout charge already exceeded its `tallest / 2` threshold, so the first admission was refused whether or not appended points were charged, and the test passed with the append-time `budget(total)?` removed. Derive the threshold from a one-point batch of the same group so only appended points can exceed it. Both files' tests updated to pin the new behaviour: a concatenated batch of two encoders' output decodes like the two batches merged, a repeated field sums, and the budget test now fails if the append-time charge is dropped. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> Signed-off-by: discord9 <discord9@users.noreply.github.com> * perf(mito2): coalesce raw series records before residual predicates (#10017) * perf(mito2): coalesce raw series records before residual predicates `raw::make_stream` evaluated every residual predicate against one record per `ScanBatch`, and a `ScanBatch` carries the rows of a single series. A predicate pass is dominated by per-call setup rather than by per-row comparison, so the cost was paid once per series: profiling the lite-02 aggregate query put `common_recordbatch::filter::batch_filter` at ~20% of CPU across 1280 calls for 640 series, and 70% of that was per-call overhead. Buffer records until 4096 rows, concatenate them with `concat_batches`, and evaluate the predicates once per group. The grouping loop, the `is_last` marking, the strictly-increasing checks and the error messages are unchanged. Three guards keep the behaviour identical: - A record whose first primary key continues the series the buffer ends with is held back, because concatenation would fuse two chunk boundaries of one series. Two existing tests pin those boundaries. - With no predicate there is nothing to amortize, so the threshold drops to one record and the stream keeps its per-record shape. - Buffered records are reported one at a time when an upstream error arrives. Merging them would put rows into the chunk withheld as `pending`, dropping a prefix the per-record stream emitted before the error. All 12 vmbench-lite queries return identical series, timestamps and values. Paired A/B against the previous head: CPU is lower in 30 of 30 rounds, median cut 13.8%-29.4% across five queries. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> * perf(mito2): release coalesced source records before filtering The concatenated arrays own their buffers through `Arc`, so the source `RecordBatch`es are dead once `concat_batches` returns. Releasing them keeps the original arrays from staying alive across the predicate pass and the per-chunk yields of the same round. Raised in review of #10017; no behaviour change. Signed-off-by: discord9 <discord9@163.com> * perf(mito2): start a group at a record that fills a batch, drop the error split Two review comments on #10017. `make_stream` processed the records buffered before an upstream error one at a time, so the chunks of the earlier records came out before the error. Nothing reads that prefix: the error fails the query, and the `RawSeriesStream` contract promises per-series ordering and finality, not a prefix on error. The predicate path already withholds its `pending` chunk on failure, so the split was also inconsistent with the rest of the stream. Removed, along with the half of `filtered_boundary_fuses_chunks_on_eof_but_an_upstream_error_still_withholds_one_record` that pinned it; the remaining fusing assertion keeps its own test. A record that reaches `coalesce_rows` rows by itself now heads its own group. Concatenating it with whatever is buffered copies it, and its predicate pass is paid once either way; on its own it takes the single-record path unchanged. The threshold's doc comment no longer claims a record larger than the bound is isolated, which was never true. Neutral for the measured workload: a vmbench-lite series is 61 rows, so the threshold is never met by one record. `cargo nextest -p mito2` series-scan selection: 53 passed. Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> * perf(mito): push predicates into columnar series discovery (#10014) * perf(mito): push predicates into columnar series discovery Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito): resolve series tags once per discovery batch Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito): batch samples reads and reuse part readers (#10016) * perf(mito): batch samples reads and reuse part readers Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito): validate boundary reads and report scan memory exhaustion Signed-off-by: evenyag <realevenyag@gmail.com> * docs: keep samples specification focused on the file format Signed-off-by: evenyag <realevenyag@gmail.com> * style: remove trailing blank line in samples format doc Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * feat(promql): run time(), vector(s) and data-free scalar broadcasts natively (#9988) * feat(promql): run time(), scalar(v), vector(s) and dynamic scalar broadcasts natively Bind time() and zero-argument date functions as EvalTime, scalar(v) as ScalarOf and vector(s) as VectorOf, and run binary operations whose scalar side varies per grid point: the scalar is read whole, vector chunks that arrive before it are held and charged, and both operand orders and bool comparisons follow Prometheus. A tree holding scalar(v) runs as one execution over every scan partition, and the planner admits it only over an unpartitioned Mito table. Data-free statements plan without a scan. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): hold the labels of chunks waiting for a varying scalar Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * feat(promql): read round and clamp parameters from varying scalars natively Bind round, clamp, clamp_min and clamp_max whose parameters are not all constants as a ParameterizedMap with scalar parameter nodes, run through map_math_with_parameters. The parameters are read whole first; vector chunks that arrive before them are held and charged, through the same hold the varying-scalar broadcast now shares. Constant parameters keep the MathOp map. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): pin a parameterized map's empty closing chunk Also correct the held-chunk docs, use same-table examples for varying map parameters, and assert the native decline instead of the existing planner's failure. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(query): plan vector(s) natively whatever the table's field is named The fused route declined a root field that is not a raw field, which is every root over vector(s): it names its result `value`. Take the compiled root's fields as they are and decline only a name the output already gives a tag or the time index. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): reserve a constant map parameter before building it Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): leave scalar(v) to the existing planner until it has its own execution boundary Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): leave data-free statements that generate labels to the existing plan Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): reserve the output point-wise kernels build before running them Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * ci: backport scoped heavy CI to narthex (#10053) * ci: backport scoped heavy CI to narthex Backport #9927 and the CI-only changes from #10043. Adapt script references to narthex, preserve manual platform checks, and document the default-branch schedule limitation. Upstream-Commit:ebb7e22566Upstream-Commit:e87766d7efSigned-off-by: WenyXu <wenymedia@gmail.com> * ci: refresh narthex compatibility release window Signed-off-by: WenyXu <wenymedia@gmail.com> --------- Signed-off-by: WenyXu <wenymedia@gmail.com> * chore(ci): slide the compatibility window to v1.3.0 (#10054) Signed-off-by: discord9 <discord9@163.com> * perf(mito): cache native reader metadata (#10015) * perf(mito): cache native reader metadata in the decoded SST tier Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito): account for partially occupied metadata tree nodes Signed-off-by: evenyag <realevenyag@gmail.com> * style(mito): use absolute cache imports Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito): trim native metadata cache lookup overhead Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito): bound wide metadata benchmark setup Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito): allow manual benchmark measurement output Signed-off-by: evenyag <realevenyag@gmail.com> * docs: keep series specification focused on the file format Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * feat(promql): route evaluated fragments to their canonical owner (#10038) * feat(promql): route evaluated chains independently by canonical key Signed-off-by: discord9 <discord9@163.com> * test(promql): verify canonical routing key semantics Signed-off-by: discord9 <discord9@163.com> * fix(promql): release closed-output chains and yield routing producers Signed-off-by: discord9 <discord9@163.com> * test(promql): check closed-chain budget before releasing the child Signed-off-by: discord9 <discord9@163.com> * fix(promql): account histogram slices and verify routing completion Signed-off-by: discord9 <discord9@163.com> * fix(promql): finalize contiguous series at repartition owners Wait for successful producer EOF before publishing exact complete metric-name/tag identities. Reuse the existing sample merge for position ordering, complementary fields, and conflicting-cell errors; recompute one final close per owner identity. Keep N producer tasks and M outputs. Admit nonwaiting queue payloads through the query pool, reserve merge workspace, and retain cancellation, failure, memory-release and unread-owner coverage. Signed-off-by: discord9 <discord9@163.com> * feat(promql): publish completed repartition identities incrementally Signed-off-by: discord9 <discord9@163.com> * test(promql): expose histogram amplification in public repartition Signed-off-by: discord9 <discord9@163.com> * fix(datatypes): encode only referenced histogram table rows Signed-off-by: discord9 <discord9@163.com> * test(promql): wait for queued retention before draining a failed read Signed-off-by: discord9 <discord9@163.com> * perf(promql): bound identity rescans and share repeated histogram rows Signed-off-by: discord9 <discord9@163.com> * docs(query): scope the evaluated validator to one chain Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(mito2): close a raw series when its package completes The raw producer only ever marked `is_last` when the next chunk of another series arrived or the input ended, so a series that a scanned package held completely stayed open until that later event. A consumer could not tell a finished series from one still being written, which is why the frontend's raw fan-in has to buffer a whole series before it can merge anything. `FlatSeriesBatchDivider` already emits a package only once it holds every row of the series in it, so the record that ends such a package also ends the last series in it. `raw::make_stream` flattened those packages into a plain record sequence and dropped that fact. Records now carry it, survive being held back a round, and a flagged record ends its group: the group's end and the package's end are the same record, so a record of the next package can never be closed by the wrong boundary. Two things had to follow. The tail primary key is taken before the residual predicates run, because a predicate may drop the run that would have closed the series while the package still holds all of its rows. And closing a package clears `pending`, so the ordering check keeps its own baseline instead of losing the key the next package must exceed. A series that continues past the package that completed it would be split into two runs that both claim to be final, so that is rejected rather than yielded. The prepared columnar source lost the same fact a second way: its per-range readers cut complete series out, but the row-level merge behind them re-cut the stream by batch size. Dividing that stream again restores packages, reusing the divider the legacy producer already uses. Both flat producers declare `KeyThenTime`, which is what lets the closed-key comparison stay a single key; the code states that dependency. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): retain streaming and batching around raw package completion Signed-off-by: discord9 <discord9@163.com> * feat(promql): add a versioned wire format for the native prefix Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat(promql): serialize fused native prefixes through substrait Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): make the native prefix codec agree with itself A payload the encoder accepts has to be one this version can decode. Three places disagreed. An `Input`'s field count was bounded only on the way in, so a 129-field `Input → Instant` encoded to 983 bytes and then failed to decode. The decoder's limit was `MAX_COUNT`, a constant that also bounds nesting depth and `Map` operation count, which is why the missing half was easy to miss; each limit now has its own name and both sides check it. `FusedSeries::serialize` only checked that the tag count fit in a `u32` while `deserialize` bounded it at 1024. Both sides now share `MAX_TAG_COUNT`. `FusedSeries::deserialize` passed an empty schema to `try_new_with_format`, which checks a frame node's declared schema against the layout derived from its tree rather than overwriting it. Every serialized frame node was therefore impossible to rebuild. The schema is derived from the decoded tree now, which is where it comes from in the first place, so nothing is added to the wire. Encoding refuses an over-limit count instead of writing a payload it cannot read back, and a field-count overflow no longer reports "operation count exceeds maximum". `rejects_excess_operation_count` hand-built a payload whose operation count was read from the wrong offset: it placed an `Instant` where the decoder expects the count, so it exercised the limit with 258 while claiming 129. It now starts from a tree the codec accepts, asserts the bytes it edits are the count it means, and checks the error names both the operation limit and the value. The same is added for field count, tag count and nesting. The integration test moves to its own file: it was written against `tests-integration/tests/raw_series.rs`, which the raw-fan-in line creates and this one does not carry. Signed-off-by: discord9 <discord9@163.com> * feat(promql): carry nested math maps in the native prefix The wire format accepted at most one Math map above the selection, so abs(ceil(x)) - which compiles to one map over another - could not be transported even though a map is transparent to shape: it keeps its input samples type and grid, and only the operation kinds are restricted. Walk every map before the selection check instead, and keep rejecting non-math operations at any depth. The tests cover a nested round trip that would notice flattening, a non-math operation under a valid outer map, three distinct levels, and the depth boundary in both directions. Signed-off-by: discord9 <discord9@163.com> * feat(promql): answer whole-vector and multi-metric statements natively (#10025) * feat(promql): name a fused tree's tags from the existing plan A fused node declares exactly the tags the planner gives it, and reads each one back off the series, so a label set this route cannot derive is a label set the answer would lose. The walk over the tree derives labels for a match, a set operation and the point-wise wrappers over them, and names none for an aggregate's groups or a whole-vector operation - which today declines every such statement. Take those columns from the existing planner instead, the way the aggregate split already does: its tag columns are what it projects for the same statement, and they are now shared through one helper rather than written out twice. Only the tag columns are copied, because the node names its field columns after its own tree while the existing planner can name a computed column after its expression. A label rewrite is a shape the walk cannot derive at all: label_replace adds its destination label and an empty replacement removes it, so passing the input's labels through is an inference the rewrite contradicts. Report no label set there. The rewrite itself keeps the existing plan, and this does not change that: the native runtime refuses two series a rewrite gives one label set, where that plan answers them, so admitting the shape would turn an answer into an error. The test that holds this now covers the two-occurrence shape as well. An aggregate or whole-vector root does not reach this branch today: both read across series, so they are planned by the aggregate split or fall back. It is the prerequisite for the placement that runs such a tree in one execution, and reaches the branch when that lands. Signed-off-by: discord9 <discord9@163.com> * feat(promql): run a classic histogram function above the aggregate cut The split accepts a suffix that runs once over the fully merged series, which is why TopK/BottomK were already admitted: the merge has folded every partition's contribution to each group, so the series the suffix reads are the ones the statement's input would have produced in one execution. A classic histogram function is that kind of operation. It reads each histogram off the bucket series that share its other labels and drops le, and the merge has already folded each (..., le) group into one complete series on the evaluated grid, so the buckets it reads are exactly the ones the input would have had. Reading le off those merged series is the same computation, not an approximation. LimitK still declines: it depends on the storage input order, which the merge does not preserve. This is what the o11ybench query `histogram_quantile(0.99, sum(rate(...[5m])) by (instance, le))` needs: it was planned by the existing path only because the split refused a whole-vector operation above the cut. The acceptance test runs the shape over real data and compares the rows two executions report: the fixture spreads six bucket series over several files and a memtable range, so the partial sums genuinely have partitions to merge, and the native answer must equal the complete input's for quantiles at both ends of the interpolation and for histogram_fraction. It also asserts the native run really merged state, so a silent fall back cannot pass it. Signed-off-by: discord9 <discord9@163.com> * feat(promql): read two metric logical tables as two inputs A two-selector statement whose two sides are aggregates kept the existing plan, even where both sides read a metric-engine logical table. The o11ybench query `sum(max by (...) (a)) by (namespace) / sum(b) by (namespace)` is that shape, and it fell back for three separate reasons. First, the engine gate refused every multi-selector metric-engine statement. The clause after it already requires each such selector to be a recognized logical rewrite, so the removed clause refused only the case this change handles. Second, a metric logical table is rewritten to a scan of the physical table restricted by `__table_id = <id>`, so two logical tables over one physical table prepare two scans of the same table. The check deciding whether the node binds one metric or one input per occurrence compared table names only, so the two metrics read as one and both inputs would carry the first one's name - a wrong answer, not a fall back. The id the rewrite already requires is now part of that identity. Third, a tree over two aggregates reads across series, so it is not answered per partition, and the branch for such trees was the aggregate split, which takes one child. A node with more than one input needs no split: it declares one partition and reads all of every input's partitions in one execution, so every group is folded in one place. Such a tree now falls through to the node. The one-selector path is unchanged: it still requires `can_split` and still declines a tree the split cannot cut. So is the multi-selector case whose inputs stay direct scans of one table - such a node is not region-local, as `Categorizer::check_extension_plan` refuses a cross-series plan over more than one scan - which is why the condition is the metric-logical-table one. The acceptance test runs both shapes over two logical tables of one physical table, with values that make a swapped input visibly wrong, and compares the rows the two routes report. Signed-off-by: discord9 <discord9@163.com> * test(promql): log the metric pair's rows through telemetry, not stdout The acceptance test printed its evidence with println!, which the crate lints as an error under -D warnings, and echoed a Display value through to_string inside the format arguments. Every other test in the file logs through common_telemetry::info!, so this one does too. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep the existing plan for a tree the runtime cannot execute The multi-input route skipped the aggregate split, and the split was what refused a tree the runtime cannot execute: `check_cut` declines a `quantile` and a grouping by a value field. Skipping it turned queries the existing plan answers into errors, because the node is chosen while planning the logical plan and a refusal the physical layer raises later has nowhere to fall back to. `quantile(0.5, a) / sum(b)` over two metric logical tables reported `NotImplemented: the native runtime does not execute the Quantile { .. } aggregate yet` where the existing plan answers it, and `count(count by (val) (a)) / sum(b)` failed on the grouping by a value field, which the outer `count` had hidden from the column check. Ask the runtime before taking the route, with the same construction the physical layer validates by, and keep the existing plan for whatever it refuses. Asking it rather than listing the unsupported kinds is what makes the check cover refusals this planner does not know about. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep the existing plan for a grouping and a selection the node cannot answer A multi-input node skips the aggregate split, so the refusals the split makes for reasons that are not about what the runtime computes were skipped with it. Two of them matter here. A grouping by the metric name keeps a label no column of the existing plan can name. The native aggregate folds its groups by `__name__` as by any other label, but the label set the node declares comes from the existing planner's columns, and `__name__` is the name a raw frame carries rather than a column of any scan - so the existing planner's `by(__name__)` finds nothing and reports no label. The schema would then report one label set for two groups the tree keeps apart: `sum by (__name__) (a or b)` over two metrics would answer two rows a reader cannot tell apart, which is a series identity lost rather than an answer given. A selection that depends on the order its input arrives in is the other. `limitk` keeps the first `k` series of each group in input order, while a node with more than one input reads its inputs' partitions through a gather that hands them over in the order they became ready: the schedule would decide which series a query keeps. Prometheus defines the selection over a series set. The split declines `LimitK` for the same reason. Every other vector operation orders its input itself - `topk` by label, `sort` by value, `limit_ratio` by a label hash - which is why only this one is asked about. Both shapes keep the existing plan. `limitk` is not answerable by either route today, since the existing planner has no kernel for the operator; the point is that the native route is not the first to answer a selection the schedule would decide. Each guard is checked with the guard removed, so both tests are known to fail without it. Signed-off-by: discord9 <discord9@163.com> * fix(promql): decline unsupported count_values groupings before execution Signed-off-by: discord9 <discord9@163.com> * docs(promql): scope the native capability probe guarantee Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the same-table pair the multi-selector exclusion used to keep out State that a Mito input joins a multi-input tree only when a second metric logical id makes the tree multi-input, and that only LimitK's selection depends on arrival order. Signed-off-by: discord9 <discord9@163.com> * fix(promql): decline ranking grouped by a value field before native execution topk, bottomk and limitk key their groups by series labels, while the existing plan also accepts a value field there and forms one group per sample value. Admitted multi-input trees could therefore keep one row where the existing plan keeps one per group. Validate the grouping when the vector runtime is built so the statement keeps the existing plan. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(promql): bound the prefix depth and name what a refusal names Lower MAX_DEPTH to 32. The old 128 was validated recursively, and a debug build overflows a default test-thread stack well before reaching it, so the depth guard itself could abort instead of refusing. Report the refused node by its own name instead of "unsupported", which is what every kind used to say. Add the multi-partition datanode case. It asserts the failure the review reproduced - a series chain cut by CoalescePartitionsExec no longer decodes - so the limitation stays visible and turns red when the region merge becomes chain-atomic. Reconcile the retained-rate comment with the values the test asserts. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): keep one predicate pass across a brief upstream pause The fill loop awaited upstream only while nothing was buffered, so one Pending split a predicate pass even when the group held no package tail that could close anything. Gate the wait on the package tail instead: without one, breaking out cannot settle a series, so waiting is free. One hundred small record batches separated by Pending now cost one pass instead of one hundred. Package completion is also only usable under KeyThenTime, which is what the one real flat producer declares. Drop the Contiguous package path and its closed-key state: it has no producer, and reaching it would close a series twice. A reopened key is still refused by the ordered-key comparison, now covered under KeyThenTime. Signed-off-by: discord9 <discord9@163.com> * perf(mito2): compare raw series keys without copying them The ordered-key guard built a Buffer for every record before checking whether a previous package key existed to compare against. Read the slices instead, so the common case allocates nothing. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin cross-producer topk to fixed partitions `native_aggregate_topk_over_global_partitions` also asserted that a selected hostname had state from two distinct original producers. That follows from the storage scheduler, not from the merge: a scan dispatches on a channel of capacity one and independent flushes do not fix their output partition, so a legal schedule can leave one partition holding every series but two. The assertion failed intermittently - `[25, 1, 1, 1]` - while the answer itself stayed correct. Move the requirement to a fixture that fixes which partition each contribution arrives on, so it holds on every run. `topk_above_the_cut_sees_every_producer_ contribution` folds `topk(1, sum by (hostname)(...))` over four producers whose contributions make the winner differ between the two grid points and require both major producers to be summed: at point 0 producer 0 holds A=6/B=10 and producer 1 holds A=6/C=10, so A wins on 12; at point 1 the same producers give B=12. Two further producers contribute a small hostname each so all four partitions carry state. Dropping a producer or taking topk inside a producer before the merge both answer a different winner, which the fixture catches - checked by mutating the fixture each way and watching it fail. The integration test keeps everything that follows from this build: the native/legacy comparison, the hand-computed twenty rows, the two points selecting different topk members, the producer and finalize plan shapes, and the four non-empty producer partitions. Its now-unused partial-state recorder is removed with it. Signed-off-by: discord9 <discord9@163.com> * feat(promql): carry the native plan with serde instead of a hand-written codec `native/wire.rs` encoded `NativeTree` by hand: fixed node tags, fixed field layouts, both directions written out, and a `check_shape` that narrowed the transport to `Input -> Instant|Window -> Map(Math*)`. The serialization layer therefore decided which plans could exist. `abs(ceil(x))` compiled but could not be transported, and every new node kind cost a second codec path plus a new whitelist entry. Widening the whitelist to nested maps maintained that interpreter rather than removing it. The file is deleted. The plan types derive serde and the codec is postcard 1.1.3 -- bincode is unusable here because RUSTSEC-2025-0141 marks the whole crate unmaintained with no patched version. postcard is maintained, has a documented stable wire format since 1.0, and writes an f64 as its bit pattern in eight little-endian bytes, so NaN payloads, signed zero, infinities and subnormals survive exactly. What remains hand-written is framing only: magic `NPRQ`, a version, a payload length. The version is rejected before the payload is deserialized, so an unknown version is a clean error instead of a silent misparse, and oversize, trailing bytes and truncation are separate errors. Decoding ends at `NativeTree::try_new`, so a tree the compiler would not build cannot be decoded. Three types keep written impls because they hold invariants. `EvalGrid` serializes its `GridSpec` and rebuilds through `try_deferred` with an empty cache -- the grid is never serialized and never materialized on decode. `SeriesLabels` rebuilds through `try_new`, keeping the sorting and the duplicate / `__name__`-as-a-tag rejection. `LabelRewrite` travels as its parameters with the regex recompiled, and fails to decode if the pattern no longer compiles; compiled internals never travel. `FusedSeries` now carries its output schema and accepts `PlainRows` and `partial_fold`, which it used to refuse. A carried schema is only honest if it is checked, so decode validates every column role, the exact time type and nullability, missing or extra value columns, and the scalar-root tag rule; a `SeriesFrame` schema must equal the frame layout the tree derives, and a partial export must match `state_schema(binding.tags)` including tag order. Identity stops being display text. `FusedSeries` compared `tree.to_string()` with a field patch, `AggregateFinalize` hashed the rendering, and `LabelRewrite` compared its own output; all three are structural now, with floats compared by `to_bits()` so that signed zero and NaN payloads stay reflexive under `Eq`. `same_binding` compared `Arc::ptr_eq`, which put an allocation address into a transportable plan; it compares the ordered fields and the optional grid spec now, distinguishing raw from evaluated. Tests assert the properties rather than the byte layout: a non-canonical NaN payload round-trips by bits, an unknown version is rejected before decode even when the payload is garbage, non-prefix trees (binary, set, aggregate, scalar, evaluated input) round-trip, thirteen malformed schemas are each rejected with their own message, and a multi-chunk chain over a real region is checked against its exact sample count and contiguous timestamps. The multi-partition integration test is split in two and labelled honestly. It used to assert a failure, on the theory that coalescing interleaved multi-chunk chains; its fixture's grid has one position, so no chain has more than one chunk and that assertion was already failing at the base commit. One test now covers the single-position shape and says it does not exercise interleaving; the other covers a 8192-position grid that does. Deserialization is bounded by depth, not only by bytes. The derived recursion walks boxed nodes, and a payload under the 1 MiB limit can nest far deeper than the stack allows, which aborts the process instead of returning an error. A thread-local budget guards `NativeNode`'s deserializer, so a hostile payload is rejected before a complete tree exists. `NativeTree::Deserialize` also routes through `try_new`, so no path can materialize a tree the constructor would refuse. Measured under postcard with no `RUST_MIN_STACK` override: 128 nodes decode, 129 return a decode error. Postcard collapses custom serde errors to its unit variant, so that rejection does not name the nesting limit; the other envelope failures (version, size, trailing bytes, truncation) each keep their own message. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): carry the fused plan as one derived payload The node still framed its fields by hand: the grid spec's integers, a 0/1 marker for the metric name, a length prefix before every string, the tag count, a format tag, and separate length-prefixed blobs for the partial fold and the output schema, with a matching Reader on the way in. That is per-field serialization sitting inside a change whose point was to stop writing per-field serialization, and it kept the maintenance cost: any new field touched both directions, and a test located a byte by computing 8 + tree.len() + 8 + 8 + 8. One derived payload replaces it. The envelope is now a version, a payload length, and a single Postcard-encoded `FusedSeriesPayload` holding the tree, the grid spec, the binding's name/time index/tags, the output format, the statement text, the optional partial fold and the output schema. Substrait still carries the children, which are exactly the fields this format should not be inventing. `text`, `Reader` and `MAX_TAG_COUNT` are gone; the tag bound existed only because a hand-written length prefix needs one. Every carried-schema check stays: the tag-order-sensitive comparison against `state_schema(binding.tags)` for a partial export, exact equality with `series_frame_output_schema` for a frame node, and the full column-role validation for plain rows. Decode also requires the payload to be consumed exactly, so a byte appended after a valid payload is rejected rather than ignored -- `postcard::from_bytes` would have accepted it, which is why the sub-payload framing had that hole. Two tests were reading the format rather than the behaviour: The depth-limit test asserted that `RUST_MIN_STACK` was unset, but CI sets it to 8 MiB, so the assertion failed before the decoder ran and the test could never do its job there. It now runs on an explicit 2 MiB worker stack, which is the stack a normal worker has, and asserts from inside that thread that 128 nodes decode and 129 are rejected. The integration test located the embedded version by assuming an offset and comparing raw bytes. The framing change made that offset stale and it failed. It now finds the envelope, decodes the version word and asserts the number, checks the length word against the payload, and prints the observed bytes when either assertion trips. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bound tree depth on both sides and validate merge inputs The depth limit was decode-only and set to a number nobody had measured. A 129-deep tree could therefore be built, serialized and shipped, while the receiver refused it; and in CI the boundary test itself aborted with a stack overflow, because a 2 MiB thread was asked to build, serialize, decode and drop a chain of that depth, and the recursive drop of `Box<NativeNode>` is not covered by a guard that only wraps `Deserialize`. Measured instead of guessed. A probe walked build, serialize, decode, validate and drop at increasing depth inside a named 2 MiB thread: 32 through 128 completed, 160 aborted. The cap is now 64, half the highest passing depth, and the same number is enforced in `NativeTree::try_new` and in the deserializer. Verified through the real constructor: a 64-node tree round-trips, and a 65-node tree is refused when it is built as well as when it is decoded, so sender and receiver accept the same set. The boundary test runs on a named thread, which is how a future failure will identify itself. The merge node accepted any single input. `with_exprs_and_inputs` rebuilt `AggregateFinalize` over whatever it was handed, on the reasoning that a rewritten input only changes where the state comes from. Nothing checked that it was state at all -- and until now nothing could produce a counterexample, because a values-producing producer could not be serialized. The serializer was standing in for a validation that belonged to the node. `with_exprs_and_inputs` now rejects an input whose schema is not `state_schema(binding.tags)`, so substituting a computed-values producer fails at the logical node with a message naming the expected schema, rather than depending on an encoding limitation. `AggregateFinalizeExec` already had the same check at physical planning; the serializer stays permissive. The three placement tests in `commutativity.rs` asserted the old refusal as their mechanism -- an ordinary fused node "fails to encode", a partial producer "cannot be pushed down". Those expectations were the encoding limitation wearing a test's clothes. They now assert the responsibilities that remain: an ordinary fused node round-trips through the encoder, a partial producer rides to the region while its finalize stays on the frontend, and a values producer handed to a merge is refused by the schema contract. The test-only `NPRQ` envelope is gone. It framed trees with its own version, a 1 MiB cap and its own rejections, none of which production had, so `native_tree_envelope_rejects_version_size_trailing_and_truncation` was proving a helper's protocol while the PR description claimed a production guarantee. Trees are tested through plain postcard, transport through the real `FusedSeries` interface. The redundant clone-and-revalidate in `FusedSeries::deserialize` is also gone: `NativeTree::Deserialize` already routes through `try_new`. Signed-off-by: discord9 <discord9@163.com> * fix(promql): stop carrying an Arrow schema in the fused payload The payload carried a full `arrow::Schema`, which dragged in `arrow_schema::DataType` -- whose `List`, `LargeList`, `FixedSizeList`, `Struct` and map variants recurse without bound through a derived `Deserialize` that cannot be hooked from outside. The tree has a measured, symmetric depth limit; the schema had none on either side, so a small payload nesting `List` a few thousand deep would exhaust the stack during decode, before any post-decode validation could run. Review reproduced that with an 80 KB payload and 8000 levels. The schema did not need to travel. `fused_output_schema` builds every column from three flat inputs and hardcodes every type -- the time column is `Timestamp(Millisecond, None)` non-nullable, values are `Float64` nullable, tags are `Utf8` nullable -- and a frame node's schema comes from `series_frame_output_schema` over the tree's root schema. The only genuinely irreducible part is which columns are labels. So `output_tags: Vec<String>` replaces `output_schema: Schema`, and decode reconstructs the schema instead of trusting one. That is strictly stronger than validating carried data: a mismatched schema can no longer be expressed at all, where before it could be carried and merely checked. The three formats differ, and the difference is now meaningful rather than decorative: - a frame node carries no tags, because its label columns come from the tree; decode rejects a non-empty field instead of comparing a copied value to itself, which is what the previous revision did; - a partial fold carries `binding.tags` and decode requires the exact order, because the state layout is position-sensitive and the binding is the ordering authority; - a plain-rows node carries its output tags, the one case where the labels cannot be derived from the tree. `skip_encodability_gate` in the district analyzer was one flag doing two unrelated jobs: skipping the Substrait encodability check, and bypassing multi-input column requirements on the strength of a placement proof. Making ordinary and partial producers serializable removed the premise of the first while leaving the second intact, so they are two fields now -- `skip_in_process_encodability` and `in_process_fused_root` -- and the placement bypass reads as `has_fused_pair_placement_proof` rather than as "we skipped the serialization check". Signed-off-by: discord9 <discord9@163.com> * fix(promql): let a too-deep tree fall back instead of failing the query The depth limit was reported as `DataFusionError::Internal`, the error a compiler defect gets. The planner only keeps the legacy plan on `NotImplemented`, so enabling the native route turned an answer into an error: a statement compiling to more than 64 nodes -- 70 `time()` terms compile to 139 -- failed outright, where the legacy planner answers it. Switching a feature flag on must never make a query stop working. The two rejections now say what they mean. Exceeding the depth limit is "this statement is beyond what this route handles", which is `NotImplemented` and makes the planner fall back, from both the constructor and the deserializer. Every other rejection in `validate()` -- a mismatched binding, a map over a scalar, a window with the wrong grid -- stays `Internal`, because those mean the compiler built something inconsistent and reclassifying them would hide real defects as unsupported queries. A fallback test pins it: 70 `time()` terms must plan exactly as the legacy route does, with the node count in the message so a future change to the cap explains itself. `postcard` moves into the external-dependencies block. It is declared with `default-features = false`, and that block exists precisely for inherited dependencies whose features are narrowed. Signed-off-by: discord9 <discord9@163.com> * test(promql): restore the scalar-root refusal and drop a duplicated derivation `a_samples_root_without_an_input_is_refused` was rewritten in place earlier in this branch, and the rewrite changed what it covers: it used to build a constant root that reports samples and assert the refusal names the contract ("does not produce a scalar"); it now builds a samples tree with no input and asserts "source indexes". Those are two different contracts, and the original one went uncovered. That gap matters here in particular, because this branch broke exactly that path: deriving output labels from the schema classified a scalar root's value column as a label, which two physical-plan tests caught. The original assertion is restored as `a_scalar_root_claiming_samples_is_refused`, and the samples-without-input case keeps its own test under its own name. `FusedSeries::serialize` also open-coded the same call `output_tags()` already makes, differing only in that the frame arm carries nothing. It now calls the method, so there is one derivation and one place for the format rule. Signed-off-by: discord9 <discord9@163.com> * style: let taplo order the workspace dependency entry `taplo format --check` runs over the whole workspace in CI, not over the two manifests I had checked. It sorts the `[workspace.dependencies]` table, so `postcard` belongs in alphabetical position inside the external-dependencies block rather than immediately after its comment. Local checking was narrower than the CI command, which is why this only surfaced there. Signed-off-by: discord9 <discord9@163.com> * style: place postcard in the sorted position the review asked for Inside the external-dependencies block, `taplo` was willing to leave the entry before the `axum` comment, because a comment line ends a reorder group. The review asked for the alphabetical position, which `taplo format --check` also accepts, so use it. Signed-off-by: discord9 <discord9@163.com> * refactor(mito2): flatten samples artifacts and reset incompatible index caches (#10041) * refactor(mito2): simplify samples paths and version index cache Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): preserve index cache root during reset Signed-off-by: evenyag <realevenyag@gmail.com> * ci: refresh compatibility release window Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * feat(promql): own raw series identities at the repartition boundary (#10058) * feat(promql): own raw series identities at the repartition boundary A raw frame's is_last closes one producer's stream, not the series: the same stored primary key may still arrive from another input. Routing such frames through the evaluated path therefore emits several partial series where a consumer expects one. Teach SeriesRepartitionExec to group raw identities. SeriesRouting selects the grouping key and try_new_with_routing takes an explicit policy, rejecting the combinations a frame's content cannot honour: an evaluated frame may not use RawPrimaryKey, a raw frame may not use CanonicalLabels, and a raw frame must declare explicit labels. Raw routing keys on the complete stored primary key rather than on labels so two pieces of one physical key always meet in one owner, where a disagreement about labels is rejected instead of being split across owners that would each look consistent on its own. A raw identity is published only after every input reaches normal EOF, unlike an evaluated identity, which is complete once each input either contributed it or ended. merge_raw_identity orders the pieces by timestamp, collapses equal duplicates, rejects conflicting ones and emits one closing chunk. The reconstruction's pool charge covers the two parallel row vectors, the timestamps and the worst-case per-row sample slices that alternating contributions produce. This adds the capability only; no node is constructed with raw routing yet. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover raw identity merging and routing source/merge covers the pure merge: interleaved ordering, duplicate collapse versus bit-level conflict, key and label rejection, histogram property comparison and shape mismatch. The router needs its own proof, because the readiness rule and the identity key are what a consumer depends on. A raw child whose partitions are scripted delivers them: one gated input that has already handed over every chunk but whose stream is still open blocks publication until it ends; identical labels with different primary keys stay apart; pieces of one key that disagree on labels fail; and one key with conflicting samples at one timestamp surfaces an error rather than dropping data. The gate holds back only the end of the stream, so the first test distinguishes "every input contributed" from "every input ended". Swapping the raw readiness rule for the evaluated one makes it fail. Signed-off-by: discord9 <discord9@163.com> * docs(promql): correct the cross-partition merge boundary The guide said native execution does not merge one logical series split across partitions. That stopped being true when the repartition owner began finalizing an exact identity's fragments: the merge now happens at that boundary, and the remaining limit is a logical series split across regions. Signed-off-by: discord9 <discord9@163.com> * fix(promql): charge raw chunks their slice and publish complete identities Two problems in the raw path, both about holding memory longer than the data requires. A frame batch decodes into many chunks that are slices of the same Arrow buffers. Charging each chunk the whole allocation charged one batch's timestamps once per chunk: 64 series of 64 rows retained 4.2 MiB for a 32 KiB timestamp buffer, 129 times the real size, and the reservations live until the identity is published. raw_chunk_slice_bytes charges the slice each chunk actually owns, using the same slice-aware accounting the histogram path already used. The same fixture now retains 95 KiB. A raw identity also waited for every input to reach EOF even when every input had already handed over its complete chain for it. read_raw_chains hands a run of chunks over atomically once is_last arrives, and an input cannot contribute the same key twice, so a contribution is final for that input. Readiness is now the same rule for both contents: every input has contributed the identity or ended. The previous test asserted that a fully contributed identity must still wait for an unrelated input's EOF, which pinned the conservative rule as if it were required. It is replaced by two tests, one for each direction: an identity whose inputs all contributed publishes without waiting, and an identity with an input that has contributed nothing waits. Reverting the readiness rule to the old one fails the first and leaves the second passing. Signed-off-by: discord9 <discord9@163.com> * fix(promql): charge histogram indices and steady the raw accounting tests A histogram field is an index array naming rows of a shared table. Charging only the table missed the indices, and a query over few distinct histograms holds mostly indices: 4096 positions naming one row is 16 KiB of indices against a table of a few hundred bytes. Both the histogram and the mixed branch now charge the index array's slice, as the evaluated path already does. The two accounting tests waited by sampling a fixed number of idle ticks. Under load the input task may not have run yet, so the sample reads zero and the test fails for a reason that has nothing to do with what it measures. Withdrawing the index charge reproduces the failure, so the test still discriminates after the wait was made deterministic. Signed-off-by: discord9 <discord9@163.com> * test(promql): gate the producer so the failure cannot drain unclaimed queues The retention this test reads is not guaranteed across `start` and `claim`. `start` spawns the producer before it returns, and a failure drains every queue nobody has claimed yet, releasing the charges those queues held. A producer that reaches its error first therefore leaves the test claiming two empty queues, and "queued output chains retain memory before drain" can never become true. That is the shape the suite now hits on this machine: the baseline commit fails this test in about ten seconds when the suite runs concurrently with another one, while the same test written with the gate passes every time. The producer now waits on a switch before its error, and the test claims both queues, waits for the retained charge, and only then opens the switch. The assertion keeps its meaning because nothing can drain the queues before the test owns them. This is a test fix. The production cleanup it exposed is correct behaviour: a queue no consumer claimed should not keep holding memory. Signed-off-by: discord9 <discord9@163.com> * feat(promql): route raw frames by a match key A vector operation between two raw sources needs the series of one match key in one partition, and the node could not give it that: raw frames were restricted to key routing, so `100 * (1 - a / b)` could not be planned at all. The restriction rested on an inference the code made when it started a read: the routing policy named the frame content, so only one policy could mean raw. That inference stops holding once a raw frame may be routed by a match key, and the content is now read from the child's own declaration instead. Choosing a destination and deciding a fragment's identity are separate jobs. A match key picks the partition by hashing the labels the frame already carries -- raw frames are required to declare them -- while the stored key still decides which identity a fragment belongs to. Both keep one key's fragments in one partition, because one key always decodes to one label set, so merging is unaffected. Canonical labels stay refused for raw frames: they include the metric name, which is not a match key. Signed-off-by: discord9 <discord9@163.com> * fix(promql): report a raw chain that cannot pick a destination Two paths hid a destination they could not compute. A matching-routed chunk without labels built an error and then discarded it through `unwrap_or_else`, routing the chunk by its stored key instead; and `output_labels` answered the stored-key policy with nothing at all, so every chain would have gone to one partition silently. Neither is reachable today -- a raw frame is required to carry explicit labels, and a stored-key-routed frame never asks for a label hash -- but a silent fallback turns a defect into a wrong answer. Both now say what went wrong. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover the histogram properties a duplicate check has to compare Merging two raw pieces treats a sample seen twice at one timestamp as a duplicate only when every property of the two matches. The comparison already covered all of them, but its test changed only the float ones, so dropping `reset_hint`, `start_timestamp` or `custom_values` from the comparison left every test passing: conflicting samples would have been discarded as duplicates with no failure. Each of the three now has a case that differs in exactly that property. Removing any of the three comparisons fails the test. The bucket side is deliberately not covered: a legal sample must satisfy `span_lengths` summing to the bucket count with an in-range cursor, so a sample differing in one bucket field is a different shape rather than a different value. Signed-off-by: discord9 <discord9@163.com> * perf(promql): publish an ordered identity as its inputs pass it, and charge what a merge uses A key-then-time identity could only be published after every input ended, so the node buffered a whole region even though the ordering it was protecting is exactly what lets it publish early. An input emits its keys in order and each chain goes to one owner, so the keys one owner sees from one input are non-decreasing too: a greater key from an input proves that input will not contribute a smaller one. The owner records the greatest key seen per input and publishes the pending identity with the smallest key once every input has contributed it, ended, or been seen past it. Readiness is checked in ascending key order, so the output stays ordered. An identity carried by a single piece needs no reconstruction at all: it is marked final and published as it is, which is what the evaluated path already did. A multi-piece identity charges each allocation the reconstruction actually makes — the two row vectors, the timestamps, and one descriptor per surviving run — instead of reserving a worst case per row per field that a well-ordered identity never approaches. The two tests for the ordered path were written against a fixture where the key they expected to be held was already complete, so they asserted the opposite of the rule. They now use fixtures where the held key really has not been passed, and they collect rows per identity because a frame may split one identity across chunks. Signed-off-by: discord9 <discord9@163.com> * fix(promql): drop the uncharged merge wrapper the charging path replaced Routing a raw identity charges each allocation before it is made, so `merge_raw_identity` had no caller left outside the tests and `cargo clippy -p promql --all-targets -- -D warnings` refused it as dead code. Its body is now the test helper that calls the charging form with a no-op reserve, and the production name is gone. Signed-off-by: discord9 <discord9@163.com> * fix(promql): stop scanning settled identities, and keep merge errors typed Three faults in the raw owner, each small: A key-then-time frame publishes only in key order, so if the smallest pending identity is not ready no larger one can be: an input reaches a later key only by passing the earlier one. The rescan applied that predicate to every pending group anyway, so an input that fell behind could have the owner walk the whole map after each arriving chain it could not yet settle. Ask the first entry only. `reserve` returning `ResourcesExhausted` came back through `invalid(...)`, so a memory-pool rejection reached the caller as a malformed-series error with the wrong status. A reservation failure is not a claim about the data; hand the `DataFusionError` through untouched. The merge reserved its row and selection scratch up front and kept holding both after `rows` and `selected` were dropped, since the reservation outlives them until the packer takes the output. Release the pair once the merge is done. The release amount matches the two reservations, so it can only fail if the reservation was already reduced elsewhere, which is why the assertion checks it but the query still succeeds. Signed-off-by: discord9 <discord9@163.com> * test(promql): assert the decode a chain-atomic merge produces This case asserted that unpacking fails with "evaluated series identity changed before its chain closed". It was written to keep that boundary honest until the region merge became chain-atomic, and its own comment asks for this change once that landed - which it has: unpacking now succeeds. The success it asserts is the same property read the other way. Sixteen hosts, one chain each, each closing exactly once, each reporting 1.0 - the rate its own samples produce, since the fixture's value rises one per second. A merge that started interleaving chains again would cut them, and a cut chain cannot report one correct value per host. The case's evaluation grid holds one step, so it says nothing about how a chain spanning several chunks behaves; that is a property of the grid, not of the merge, and the comment now says so instead of claiming four batches per chain. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover the gaps the review named, and drop two false claims Four independent gaps in the raw repartition tests, plus one comment that asserted something the code does not do. `RawScript` reported `SeriesOrdering::Contiguous` regardless of what its plan declared. `pack_raw_series` derives both the frame metadata and the `SequenceValidator` from that one value, so every `KeyThenTime` test packed `Contiguous` batches and validated them under the `Contiguous` contract — `SequenceValidator`'s "raw series keys are not ordered" check never ran. Carry the declared ordering through `RawScripted` and hand it to the stream, so the batches and the check agree with the plan. `raw_matching_routing_groups_by_match_key` asserted only that both identities shared an output, which holds under primary-key routing too because those two keys collide in a three-output layout. Assert the owner against `output_labels` of the match key instead, so routing by the wrong key fails. The test named for waiting asserted early publication through the watermark. Rename it, and cover the other side deterministically with `gate_chunks`: an identity is withheld while another input has delivered nothing, then publishes once the gate opens. The two lifecycle tests set `gate_chunks: true`, which blocks the *first* chunk, so nothing was ever charged and their wait for a reservation could not be satisfied. Let the chunks through and keep the gate closed at EOF: the chain is delivered, charged, parked, and then dropped. `histogram_duplicates_compare_every_property` claimed the bucket side was unreachable because a legal sample must satisfy layout constraints. Only the bucket *count* is constrained; bucket values are free. Add a case per property — schema, count, zero_count, sum, zero_threshold, either side's bucket value, either side's span offset and span length with equal counts, plus the existing reset_hint, start_timestamp and custom_values — so dropping any comparison from `histograms_equal` fails. `native_prefix_multi_partition_series_chains` said the region merges chain-atomically. It does not: `CoalescePartitionsExec` still interleaves partitions batch by batch. The decode passes because #10023 closes a region's pending raw chunk at package completion, so a chain's value and its close are no longer latched apart. Say that, drop the unsupported "four batches per chain" count, and note that a one-point grid gives one value plus a possible empty close. Signed-off-by: discord9 <discord9@163.com> * perf(promql): merge ordered raw pieces without a row index `merge_raw_identity_charging` rebuilt a `(timestamp, chunk, row)` entry for every row of every piece and sorted the lot, then walked it again to drop duplicate timestamps. Reconstructing one series therefore cost `24 * rows` bytes of transient workspace and an `O(n log n)` sort, even when the pieces already arrived in order. The validation above that point has already refused a piece whose own timestamps are not strictly increasing, so a piece never needs sorting internally. What is left to order is only the relation between pieces. When every adjacent pair satisfies `previous.last() < next.first()` the concatenation is already the merged sequence, and no timestamp can repeat across pieces, so neither the index nor the duplicate walk is needed. Keep the general path unchanged for the interleaved and touching cases - touching pieces share a timestamp, so they still need the duplicate check - and shrink only what the path actually reserved. Signed-off-by: discord9 <discord9@163.com> * test(promql): vary histogram spans one dimension at a time `histogram_duplicates_compare_every_property` varied `span_offsets` and `span_lengths` together in the two length cases: the baseline was `offsets: [0], lengths: [2]` and the cases used `offsets: [0, 0], lengths: [1, 1]`. The offsets comparison rejected them first, so removing the lengths comparison left the test green and those two cases pinned nothing. The baseline is now two spans in both sides (`offsets: [0, 0]`, `lengths: [1, 1]`). The offset cases change only the cursors (`[1, 0]`) and the length cases only the lengths (`[2, 0]`), keeping the cursor list, the span count and the bucket count fixed, with a zero-length span as the only difference. Ablating any one of the four comparisons - positive and negative offsets, positive and negative lengths - now fails the case that covers it. `single_chunk_uses_ordered_fast_path` is removed. It passed with the fast path forced off, so it did not pin path selection, and the owner never reaches the merge with one chunk: `finish_raw_group` returns the chunk after setting `is_last`. The fast path stays pinned by `ordered_disjoint_pieces_concatenate_without_row_workspace`, which asserts the exact reservation and zero shrink for disjoint chunks, and by `touching_ordered_chunks_use_general_duplicate_path` on the other side. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep a plain-rows schema in the column order it was built with Decoding rebuilt a PlainRows schema in a fixed order — time, then value fields, then tags — so a legal node whose schema was `[value, host, __name__, time]` came back as `[time, value, host, __name__]`, and a scalar root's customised value column came back as `value`. The planner happens to emit that fixed order today, so no ordinary query hits it yet, but `MergeScan` compares schemas by position, which makes a reordered schema a different schema. The wire now carries `output_columns`: the flat, ordered output column names. Decode reconstructs in that order and still derives each type from the role the name plays, so no recursive Arrow schema comes back — that was the previous blocker, and the point of dropping it was that only the ordering is irreducible. Before rebuilding, the carried list is checked as a set against the tree's value fields, the tags and the time index, so an order that names something absent, omits something present or duplicates a name is refused rather than quietly repaired. The test that used to catch this had been replaced by per-index assertions written against the new order, which pinned the defect instead of the contract. `assert_eq!(decoded.schema(), node.schema())` is back, and a fixture uses `[value, time, host]` so the assertion is load-bearing: reverting the reconstruction to the fixed order makes it fail. A frame node is unaffected. Its schema comes from `series_frame_output_schema` over the tree's evaluated root, so it never had a flat list to reconstruct out of order; the frame layout is what that derivation defines. Signed-off-by: discord9 <discord9@163.com> * fix(promql): carry fused output schema without reconstruction Signed-off-by: discord9 <discord9@163.com> * perf(query): reuse root plan encodability result Signed-off-by: discord9 <discord9@163.com> * test(promql): exercise depth fallback with a legacy-plannable query Signed-off-by: discord9 <discord9@163.com> * feat(promql): decide a duplicate match group across partitions (#10081) * refactor(promql): report every duplicate point from overlap `overlap` returned only the first point where two members of a group are present and a caller-supplied predicate held, so the caller could not tell which other points had a duplicate. Turn the predicate into a callback and invoke it for every such point in ascending order; the caller decides what a duplicate point means. The one caller reproduces its previous behaviour exactly: it ignores points its gate excludes and keeps the smallest point per group, which is what the group fold already took. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): number the binary runtimes of a tree `RuntimeNode::build` walks the compiled tree in pre-order, so a counter threaded alongside the input ids numbers each binary node deterministically: the same tree yields the same index on every partition, because every partition builds from the same compiled tree. That gives per-node execution state a key without depending on pointer identity. Signed-off-by: discord9 <discord9@163.com> * feat(promql): reduce duplicate findings across partitions A partitioned match cannot tell whether the other operand has a sample at a point, because each partition holds only its own slice. This adds the reducer that makes that decision possible without deciding anything yet: per binary node and field, it merges the operands' presence as partitions publish it and keeps the duplicate findings they report. Findings are retained regardless of what the gate says at the moment they arrive. A partition that publishes its presence late must not cause an earlier partition's finding to be discarded, so the gate is applied only when the merged presence is asked for a decision, with the same formula the kernel uses locally: `lhs && rhs`, or `lhs || rhs` where a fill value makes a point live with only one side. Presence and the retained findings are charged to the pool as they are added, by their real owned bytes, and a refusal is reported rather than swallowed. Storage is bounded by the grid length: one presence flag per point per operand and at most one finding per point, replaced only by one with a lower rank. Nothing constructs this yet. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): carry duplicate evidence down to the kernel Plumbing only: `FusedSeriesExec` holds a plan-instance slot for the execution's duplicate evidence, `NativeExecutionState` and every `BinaryRuntime` carry a handle to it, and the three vector-match layers that reach `binary_field` accept it. Nothing reads or writes the evidence yet — every call site passes `None` or forwards what it was given — so the crate behaves exactly as before. The slot starts empty in `build` rather than in `execute`: the partitions of one execution are separate `execute` calls on the same plan instance, so a slot created per call would give each partition its own state, while a rebuilt plan is a different execution and gets a fresh empty slot from its own `build`. `BinaryRuntime` gains a `slot(field)` accessor for the index the compiler already assigns it; the next change is its first caller. Signed-off-by: discord9 <discord9@163.com> * feat(promql): publish what a field's match saw, without deciding yet `binary_field` now publishes each side's per-point presence into the execution's evidence and records every duplicate point `overlap` reports, including the ones the local gate excludes. Recording them is the point: a partition whose finding arrives before the other side's presence is known must still be able to fire once that presence does arrive, so the gate is applied when a decision is asked for, not when the finding is made. Each published field carries its node and field index, which is what keeps two binary nodes or two fields from sharing presence and findings. The message a recorded candidate carries comes from the same helper the immediate error uses, so a deferred report and a direct one say the same thing. Nothing decides anything yet: `evaluated` is still computed from the local presence vectors exactly as before, and `settled` has no caller outside the tests. `FieldEvidence` groups node, field and handle so the kernel signatures gained one parameter rather than three. Signed-off-by: discord9 <discord9@163.com> * feat(promql): report a duplicate match group found on another partition A partitioned match decides whether to check a duplicate group from the presence of the other operand, and a partition only holds its own slice of that operand. So the partition holding `job="other"` had no left-hand data, skipped every point, and answered where Prometheus refuses the query. The findings a partition makes are now decided once the whole execution has reported. Each partition publishes its operand presence and records every duplicate point it sees, including points its own gate excludes; the partition that finishes last holds complete evidence and asks for the earliest point that is eligible once all the presence is merged. Earlier partitions return their rows and their stream ends normally, so nothing waits on a partition that is never polled — an abandoned execution simply never reaches a verdict, and a failing one aborts its claim rather than being counted as having contributed. Presence is merged per binary node and field, so two nodes or two fields cannot share a verdict, and `filling` is recorded once per slot: a second publisher that disagrees is an error rather than a silent pick. The gate itself is unchanged, which is why a point whose other operand is genuinely absent still answers instead of erroring: the merged presence still says that point is not live. Signed-off-by: discord9 <discord9@163.com> * fix(promql): size duplicate evidence by the grid, not by partition count `DuplicateEvidence::new` stored the output partition count as its grid length. Those are unrelated numbers, and the caller passed `partition_count`: `publish` kept the operand presence for at most that many points and `record_candidate` returned success for anything past it. With two partitions and a five-point grid, a duplicate group at point four was discarded by the very check that exists to find it, and the query answered. Take the point count from the tree's evaluation grid and the partition count separately. Every claim now leaves the counter exactly once, whether it completes or aborts, and the exit that closes the last claim releases what the evidence holds: the verdict is kept only when the run was not aborted, then the slots are cleared and the reservation released. Previously the last completion shrank the reservation while the vectors and strings stayed allocated, and an aborted claim could leave another claim's exit unaccounted, so the charge outlived the run. Candidate storage becomes a sparse map keyed by point instead of a grid-length vector, charged before it grows: the group's strings, its vector capacity, the candidate itself and a per-entry estimate. A grid thousand points long with one duplicate no longer pays for a thousand empty slots, and the charge now covers the containers it claims to cover. The execution test evaluates a five-point range at parallelism two — more points than partitions — with the duplicate at the last point, which is exactly the boundary the partition-sized array dropped. Its control runs the same duplicate against a left side that is absent at every point and still answers. Signed-off-by: discord9 <discord9@163.com> * fix(promql): decide a partitioned duplicate from the whole execution's presence A partitioned match decided whether to check a duplicate match group from the presence of the other operand, and a partition only ever holds its own slice of that operand. `left{job="api"} / on(job) right` with two `job="other"` series on the right returned `5.0`, because the partition holding `other` had no left-hand data and its gate was false at every point, while Prometheus checks every group of the one side whenever the other side is non-empty at that point. Each binary evaluation now publishes both operands' presence and records every duplicate point it sees, including the points its own gate excludes, because a finding that arrives before the other side's presence is known has to be able to fire once that presence does arrive. The partition that finishes last reduces the evidence and asks for the earliest eligible point. Presence and findings are keyed by binary node and field: a tree can hold several binary nodes, and the kernel evaluates fields separately with presence read from that field's own operand. No partition waits on another. A slot takes its length from the operands it is published with rather than from the statement's grid, because a binary inside a subquery runs on that subquery's own grid, which can be longer. A partition that publishes a different length for the same slot is an error instead of a truncation. The evidence exists only when the node has more than one output partition and the tree holds a binary with two vector operands; otherwise the local gate already sees every operand and there is no verdict to reach. A claim for a partition this generation already issued, or one arriving after it finished, starts a new generation, so a second execution of the same plan does not join an accumulator whose claims were spent. A retained finding holds its match group behind an `Arc` with the side and timestamp, and the error text is built only when a verdict is reported, so recording a duplicate point costs no formatting. Signed-off-by: discord9 <discord9@163.com> * perf(promql): record a duplicate only where this partition cannot decide it A point whose merged-in-partition presence makes it evaluated already aborts the execution from the partition that sees it, so storing it in the shared evidence took the lock to record a verdict nobody would ask for. Only the points whose local gate is false are recorded now, which is exactly the set whose eligibility depends on presence this partition does not hold. Both readings are in the comment at the call site, because the previous round's test depended on recording every point and the next reader should see why that changed. Signed-off-by: discord9 <discord9@163.com> * fix(promql): decide an evidence generation from its state, not from call order `claim_evidence` inferred an execution boundary from "this partition has not claimed yet". Cancellation breaks that inference: an execution that claimed partition 0 and was dropped leaves an unfinished generation behind, and the next execution claiming partition 1 joins it; only when that same execution reaches partition 0 does a new generation start. The two partitions of one execution then sit in different accumulators, and a duplicate that only the merged presence can decide is missed. No two executions have to be alive at once for this. A generation is now dead when it has finished or when any of its claims was aborted, and a claim for a partition that a live generation already issued is an error that names the cause instead of silently starting a new one. The previous review allowed refusing re-execution outright, and this is that: any inference from call order is a guess that cancellation can invalidate. The consequence is stated where it is caused: a plan instance whose first execution claimed some partitions and never claimed the rest has an unfinished generation that no later claim can join. That is the price of refusing re-execution; a legitimate second execution would need an explicit execution lifetime rather than a heuristic over partition indices. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep duplicate evidence single execution Signed-off-by: discord9 <discord9@163.com> * test(promql): pin disjoint duplicate groups and trim unused ranking Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(prometheus): report the metric name only where the aggregation keeps it (#10108) * fix(prometheus): report the metric name only where the aggregation keeps it An aggregate response carried a `__name__` label the aggregate does not have. The response layer derived the name from the selector and attached it whatever the aggregation did, so `sum(alpha_total{job="api"})` answered with `{"__name__":"alpha_total"}` where Prometheus answers with no labels at all, and `sum without (host)` likewise kept a name the aggregation discards. Prometheus keeps the metric name on an aggregate only when the aggregation groups by it: `by (__name__)`, or a `by` list containing `__name__`. Every `without` drops it, including `without ()` and exclusions of labels that do not exist, and an aggregate with no grouping modifier drops it too. The aggregate function does not matter, and neither does whether the selector names a metric. The rule is stated once now: keep the name only for a `by` whose labels include `__name__`, and clear otherwise. A chain of guards left the ungrouped case to fall through to the selector, which is how the name leaked in. The previous behaviour had a test asserting it, so the suite agreed with the code and neither agreed with Prometheus. The expectations here were measured against Prometheus 2.53.0 across all four modifier shapes and five aggregate functions before being written down. Signed-off-by: discord9 <discord9@163.com> * fix(prometheus): keep the metric name for the aggregates that select series The naming rule added for aggregates was applied to every operator. It holds for the ones that fold a group's values into one: those drop the metric name unless the grouping names it. But `topk`, `bottomk`, `limitk` and `limit_ratio` return some of the input's series with their labels intact, so the name survives them, and the grouping modifier only decides which bucket to select from. Applying the folding rule to those four stripped `__name__` from a response that used to carry it - on the default path, not only under the native route, so every deployment saw it. Read the operator before the modifier: the four selectors recurse into their input and keep whatever name it contributes, and every other aggregate keeps the measured rule. Recursing rather than synthesising also keeps a name the inner expression already dropped, so `topk(1, sum(cpu_usage))` stays nameless. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(promql): let native compilation and execution decide admission (#10071) Replace legacy output probing and selector allowlisting with native capability checks. Signed-off-by: discord9 <discord9@163.com> * feat(promql): scan every metric a nameless selector matches (#10106) feat(promql): answer a selector that names no metric by scanning each it matches A PromQL selector with no metric name used to be a planning error. It is now answered by enumerating the schema's logical metric tables, compiling one source per match under one union input, so the fused producer still reads what the compiler prepared: one compiler source per selector, not per metric. Each source names the metric it reads, in its own tag list. That is what makes this work at all: two metrics whose ordinary labels are equal are told apart by name alone, and nothing else in the response can carry that identity. Where the name survives is then a property of the operator rather than of discovery, so the same tag walk decides it for every query - the walk now drops the name where the runtime drops it, for a range function, a math or histogram kernel, a parameterized map, a timestamp selection and an arithmetic or `bool` binary operation, and keeps it for a filtering comparison. `sum by (__name__)` keeps it by grouping. The walk already had that same divergence without discovery: no metric-engine logical table carries `__name__` as a column, so a named selector's tags did not include it and the walk's answer was incomplete in the same way. Discovery only made the column real. The metric engine checks that two logical metrics agree on their time column's unit, not on its name, so each source's bound is built from the column that source actually carries, and a source without one is refused rather than read unbounded. Two upstream contracts assumed one table per selector and are widened rather than bypassed: the time-bound pushdown walks a union's sources, and a fused node may declare `__name__` when its inputs each name their own metric instead of binding one name itself. Declining still means the query goes to the existing planner; shapes this route cannot derive keep the plan they had. Signed-off-by: discord9 <discord9@163.com> * feat(promql): bound metric discovery by the caller's table grants (#10107) Discovery enumerates the schema's logical metric tables, which is a wider read than a caller's grants necessarily allow. The frontend now answers "which of these may this request see" before the planner touches the catalog, and the planner filters on that answer rather than on its own enumeration. The scope is process-local state on the query context, skipped by the builder the same way the other local-only fields are: a remote node must not receive a scope that widens what it may read. It defaults to `Unavailable`, so a path that did not prepare authorization cannot discover, and the validator turns "should have been set and was not" into an internal error instead of a silent unfiltered read. The named tables of a mixed query are checked too. The complete extractor answers "no tables at all" when any selector is unresolvable, and that was exactly the selector that made the query enter the discovery branch - so `beta_total{job="api"} or {job="api"}` used to lose `beta_total` from the check. Both the allowed and the unrestricted arms now take the partial answer. A denied metric is skipped rather than failing the query, which is what makes discovery mean "every metric you can see". The split route rejects a query whose name matchers reach a denied table, so the same query answers differently depending on the request header; that difference is stated where the skip is made. The planner's retain runs before any source is prepared, so a denied table's name reaches neither the plan nor an error message. It filters with borrowed keys, one pass to build the set and one lookup per metric. Signed-off-by: discord9 <discord9@163.com> * feat(promql): preserve scan parallelism through native frame boundaries (#10055) * fix(promql): let a closed chain keep its charge until the packer is done Four places released the frame reservation: the early-publish path handed it to the packer, but the queue drain and the end-of-input path freed it in place. Those two run while the packer still holds rows it has not turned into batches, so a series spanning several batches went unbilled once its last piece was handed over. Every emit path now hands the charge over, and the packed stream frees what it holds: what is left when it is polled and pending is the one identity it is turning into batches, and nothing survives its end or its drop. The identity guard is also widened: within one source every series shares its metric name, so a node that drops `__name__`/`__type__`/`__unit__` -- which is what a range function, a math map and the timestamp shape do -- still maps distinct series to distinct labels. Only rewriting an ordinary label can make two equal, and that is what the guard refuses. Ordinary `rate` and arithmetic frame output therefore publish as their chains close instead of buffering a partition. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep a cross-source tree's partitions, and gather a raw one only when it must Three defects in how this node decided a tree's execution layout. A match whose two operands derive from the same source still needs its match keys co-located, but only the two-source case was recognized. `x - 2*x` with `on(host)` therefore fell through to single-partition execution and lost the parallelism the scan gave it. A raw input never received a matching router: the normalization branch returned it unchanged unless the whole tree was global, while the builder requires a direct matching router for any multi-partition matching-local input. A two-source raw query was rejected at planning. Nothing reconciled the partition counts of different sources either, though the builder requires one common positive count. A single count is now computed for the matching-local case and every router under it uses it, gathering when that count is one. The window restriction also ran before normalization decided the layout, so a tree about to be gathered could be refused for a limit that only applies to partitioned windows. Two tests changed with the behaviour rather than around it: hash routing does not promise which partition holds a given series, so that test compares results instead of placement while keeping its partition count, per-partition execution and operand-order assertions; and a test that pinned the old refusal of a multi-source frame now pins its acceptance. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): keep a raw source's scan partitions instead of gathering them `RawSeriesSourceExec` declared one partition and read every child partition inside `execute(0)`, so a cross-table node lost the scan's parallelism before its inputs reached it. It now declares the child's own count, executes exactly the partition it is asked for, and re-labels that partition's frames. That leaves `SeriesGather` with no consumer: it existed to interleave several partitions into one stream. The module is gone rather than kept as a hidden N-to-one path a later plan could quietly fall back on. Signed-off-by: discord9 <discord9@163.com> * fix(promql): publish a raw source's frames under the ordering it declared `pack_raw_series` derives the frame schema from the stream's own ordering, and `RawSeriesSourceExec` fixes that schema at plan time from a constant. Passing the scan's stream through unchanged broke that agreement: a columnar scan promises key-then-time, so the region published key-then-time frames while the frontend still expected the schema it had built, and `MergeScan` refused them. The forwarding adapter restates the ordering this node declares. It is the weaker promise, so a scan that keeps a finer one still satisfies it, and every other stream property is forwarded unchanged. Signed-off-by: discord9 <discord9@163.com> * fix(promql): route a raw frame that names its labels by its key A region cannot hand out complete labels: it has no metric-name binding, so `prepare_raw_scan` refuses an explicit binding outright. What it hands out is the stored key plus the description a decoder needs, which is the normal input to this node rather than a case to refuse — every single-table selector is planned that way. The node's constructor refused exactly those frames, so any plan that inserted a router under a single-table selector failed before it ran: the matching policies this branch adds, and the one-partition normalization of an evaluated tree. The node publishes labels, because that is what it groups and closes identities by: `finish_raw_group` reads `chunk.metric` and the merge needs it too. So the input is decoded once, at the unpack boundary this node already has, and an already-labelled stream passes through it untouched. The frame it declares is rebuilt from the input's own declaration instead of being compared against it, which keeps the check that a frame this node cannot re-declare is refused while letting input and output differ in how they name the same series. `frame_schema_with` becomes public for that rebuild, since it is the one place that decides what a declaration is. `FusedSeries` now describes the router's output rather than the scan's when it wraps a raw input, because the binding it hands `build` has to match the frame the router actually publishes. Tested through the node directly: a key-labelled input routes at all; matching puts both pieces of one label set in one owner and closes it once; and `RawPrimaryKey` still hashes the key rather than the decoded labels. Signed-off-by: discord9 <discord9@163.com> * test(promql): measure a routed pair by the width it routes to Four assertions still described the layout this branch replaced: a node with two inputs used to read every partition of both into one and answer one partition, and that gather is gone. The pair is now matched in the partitions it was scanned in, so the fused node answers as many partitions as its inputs route to. Each of these fixtures scans with four partitions, and on the base of this branch all five tests passed, so this is a behaviour change this branch made and did not re-verify rather than a defect: the value assertions behind these shape assertions pass unchanged, in both the native and the legacy comparison. The width is read from the routed children instead of being written as four, and the scan is found by walking down through the nodes that only pass its frames along, since a routed input is no longer a bare `SeriesScanExec`. Signed-off-by: discord9 <discord9@163.com> * fix(query): normalize a multi-partition series-frame root A query engine hands its plan to one stream, and for a plan with several partitions that means `CoalescePartitionsExec` - ordinary batch coalescing. A series frame cannot survive it: one stored series may be split across partitions, and a chunk's `is_last` closes that producer rather than the series, so interleaving two partitions' batches produces a stream whose decoder refuses it (`raw series key changed before final chunk`). Evaluated frames have the same shape of problem: their validator keeps one open chain, and a batch from another partition interrupts it. The engine's root is also a region's root, which is how a cross-table native statement reaches this: its per-region sub-plan is rooted at a partitioned `RawSeriesSourceExec`. So the rule belongs at the physical optimizer's end, before the final sanity check, and it normalizes the root and nothing else - `FusedSeries` already inserts its own owner wherever a consumer needs one. A single-partition root is left alone: one producer is the whole answer. A key-labelled raw root is refused rather than coalesced, because the router checks that one stored key decodes to one label set and it needs the labels to do that. No production plan reaches that rejection today - the only producer of a key-labelled frame is the region's series scan, and every plan that executes it puts `RawSeriesSourceExec` or `FusedSeries` above it, both of which publish explicit labels - and the rejection is what keeps it that way. `schema_check` stays enabled: for the roots this rule accepts, the router re-declares its input's frame with the same content, label mode, decode description and ordering, so the schema it publishes is the one it was given. Signed-off-by: discord9 <discord9@163.com> * feat(promql): admit an evaluated frame as a fused input The extension planner hands a child straight to the fused executor when that child already publishes a series frame, and until now it only recognised a raw one. A segment's output is an evaluated frame, so a statement planned as two segments could not be bound above the first one. The check it replaces asked for a raw frame; the property that matters is that the frame names its own series, which is what `labels() == Explicit` says - evaluated frames always declare it and carry no decode description. Everything else stays with `FusedSeriesExec::build`, which already refuses a mixed-content node, an evaluated input that is not contiguous, and a frame whose declaration does not match the binding it was given. Signed-off-by: discord9 <discord9@163.com> * feat(query): plan a global topk under an aggregate as two segments `sum(topk(1, m))` needs the whole vector for its ranking, which is a property of the tree rather than of the statement, and the routes that existed could only answer a whole-vector tree in one partition: the statement fell back to the existing planner. Splitting it lets the per-series prefix keep the scan's partitions while the ranking sees every candidate. The cut goes below the `topk`, not below the `sum`. A segment holding a `topk` reads across series, so it would gather its own input before evaluating the prefix - correct numbers, no parallelism, which is the thing the split is for. Below the `topk`, the prefix runs on the scan's partitions and the ranking and the fold above it run once, on the child's evaluated frame. Both segments are built from one compiled tree: the child is the prefix subtree, the parent is the original tree with that subtree replaced by an input bound to the child's frame. Nothing is re-parsed, so the grid, the matching rules and the bound scans are the ones the compiler produced. The parent needs its output columns without asking the existing planner to name a computed column after its expression, so `fused_output_tags` now derives the grouping labels of an `Aggregate` and passes a selecting `Vector`'s input labels through. It derives output *columns*, not a complete runtime label set: the metric name is bound separately from the tag columns, and a grouping by `__name__` keeps that name in the labels while contributing no column. `fused_root_schema` is that derivation, shared with the ordinary route. The segmenter is its own method, boxed at the call site. Inlined, its future made every frame of the planner's recursion large enough to overflow the stack on a deeply nested statement - `test_parse_or_operator` aborted before this. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the two-segment topk plan and what it keeps The statement's two segments do not land in one physical tree: the prefix has one scan for a child, so the categorizer classifies it commutative and pushes it into the region, while the aggregate above it stays at the frontend. The observer therefore records every plan a query engine wraps, not only the first, so the test can look at the region's own root. What the assertions pin, and why each one is worth its brittleness: - the answer is the global maximum, not a sum of per-partition winners; - the frontend segment holds the complete sum and the global topk over an evaluated input, with no instant evaluation left in it; - the region's segment holds the prefix and its output is an evaluated, explicitly labelled, contiguous frame; - that segment keeps more than one output partition, which is the whole point of cutting below the topk; - the region's root is the series-aware router, one output, and it reads that segment. Column names are not compared: this route names a computed column after its compiled root while the existing planner names it after the expression, which is older than this split and not what this test is about. Signed-off-by: discord9 <discord9@163.com> * feat(promql): share the input-locality classification A tree's distribution requirement is one property, and two layers now ask it. The physical planner already decided with `input_locality` what a tree needs from its inputs; the logical planner has to ask the same question when it splits a statement, or the two can disagree about what a subtree requires. `InputLocality` and `input_locality` are therefore public within the workspace. The classification describes the external inputs a tree needs - not its output distribution, and not which neighbouring operators may share a node - so a caller that reads it as either of those will cut where it should not. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a statement where a gather would swallow its prefixes The previous commit planned `sum(topk(k, prefix))` by matching that shape. A planner that grows one matcher per query shape grows one per benchmark entry, and the shape is not what decides where a statement divides: the tree already says what each subtree needs from its inputs, and `input_locality` answers it. So a segment is now a maximal subtree with one distribution requirement. Inside a tree that must gather, any child that (a) can cross a boundary - it produces evaluated samples rather than raw samples, aggregate state or a scalar - and (b) does not itself need a gather, becomes a segment of its own and keeps the partitions it was scanned with. Nothing else is cut, and a tree with nothing to cut keeps the plan it had. Every segment rebinds its own inputs: the scans it reads directly first, in the order it first names them, then the segments cut out of it, because `FusedSeries` requires dense source indices over its children. `fused_output_tags` derives the parent's columns from those inputs rather than from the statement's first selector. Three gates keep this from answering what the routes before it would not. Each one is a failure this change produced before it was added: - the existing planner must still be able to plan the statement. Deriving tags locally had cut the route off from that refusal, so `sum(clamp(m, 2, 1))` - an empty range, which the existing planner rejects - was answered instead of failing; - every segment's tree must construct a `NativeExecutionState`, because nothing below can fall back once physical planning starts, and a grouping by a value field is a shape the runtime refuses; - the tree must contain a prefix that a boundary could carry, so a whole-vector tree with no per-series work inside it is not split for nothing. The scope is one selector. A statement over two tables binds each scan as a `RawSeriesSource`, and a segment whose child is that wrapper cannot be placed in a region, so its prefix would not gain the partitions the cut is for; those statements keep the plan they had, which the acceptance test pins. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the segment boundaries and their scope One statement per shape the cut can meet, asserting what the rule says rather than what one query happens to produce: a per-series tree stays one node, a matching tree routes instead of gathering, a global fold over per-series work cuts that work out, a constant stays embedded because a boundary cannot carry one, and a statement over two tables keeps the plan it had because a segment over `RawSeriesSource` cannot be placed in a region. Answers are compared as sets of rows with the value column renamed. Three things differ between the routes and none of them is the answer: this one names a value column after its compiled root while the existing planner names it after the expression, the two emit columns in a different order, and this one is partitioned so its rows arrive by partition. Comparing them as what they are leaves the values as the only thing an assertion can fail on. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep a selected segment whole A segment is chosen because its subtree needs one distribution; cutting inside it again contradicts the choice. The inner builder was still applying the cut predicate, and that predicate is "exportable and not `SinglePartition`" - which every node inside a per-series subtree satisfies, since a per-series tree has no `SinglePartition` node in it to begin with. `sum(topk(1, abs(m)))` showed it: the prefix was cut out of the `topk` as one segment, then `abs` was cut out of that segment, leaving a middle segment whose child is a node rather than a scan. That middle segment cannot be placed in a region, so it answered one partition while the scan had several - the prefix lost exactly the parallelism the cut is for. The inner builder now collects the segment's `Input` leaves and nothing else. Signed-off-by: discord9 <discord9@163.com> * refactor(query): bind a segment to its own scan A cut segment carries one source's identity: its scan, its metric name, its time index, and its labels. Building it from the statement's first selector only happens to be the same thing while a statement has one selector. `build_inner_segment` takes the two lists the planner already has - each occurrence's filtered scan, and each occurrence's metric, time index and tags - and binds the segment's single source from them. The parent keeps the wrapped children and the statement-level binding it has now, because a source that reaches the parent directly still has to cross a region as a raw frame. A segment that collects more than one source is declined. `MatchingLocal` satisfies the cut predicate while reading two sources, and one segment cannot carry both sources' identity. No behaviour changes: the entry is still one selector, so no scan is wrapped and the statement-level values are already that selector's. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a statement that reads more than one table A whole-vector statement over two sources is now cut into one per-series prefix segment per source, with the fold above them in the frontend. Each segment binds its own source's scan, metric, time index and labels, so it can be placed in the region that holds that source, and each prefix keeps the scan partitions it was read with. Three things had to change for the existing segmenter to reach that shape: The cut sat inside `!per_partition && !multi_input`, so a statement over two metric tables - which is `multi_input` - never reached it. The cut now sits under `!per_partition` alone. The aggregate split keeps its own conditions, including `!multi_input`, so a multi-input tree is still not split that way. The single-selector gate was doing two jobs. A statement naming several selectors declines unless those selectors read more than one table: the count alone says nothing about whether the tree has more than one input to place, and the shapes it would otherwise admit - one metric named twice under a fold, such as `sum(m) / m` or `m + sum(m)` - are a plan the existing path already answers. `cross_table` rather than `multi_input` decides this, because two Mito tables carry no metric logical id and are still two sources. A segment that collects more than one source is declined. A matching subtree over two sources is a cut candidate, and one segment cannot carry both sources' identity, so `sum(topk(1, m / n))` keeps the plan it had. The segmented parent reports the value column the compiled tree names, not the one the existing planner names; `sum(rate(a[5m])) / sum(b)` reports `v` where the existing plan reports an expression-shaped name. The values are identical and both names are pinned in the test, so a change to either rule shows up there. Restoring the existing name needs a rename above the parent - the node's own schema must keep the compiled names its output columns are classified by - and is left to a follow-up. Signed-off-by: discord9 <discord9@163.com> * test(query): pin that two sources keep their own scan bounds A segmented statement binds each prefix to its own source's scan, and A1 made that binding: `bare_scans` is derived from the prepared scans after each selector's time filter has been pushed into its own `TableScan`. Nothing tested that the two segments actually read `their` bounds rather than one window applied twice - the existing two-source case has no offset, so both sides read the same range and a crossed binding would answer the same numbers. `sum(off_a) / sum(off_b offset 60s)` differs from `sum(off_a) / sum(off_b)` only in the right side's window, so the two queries must disagree: 20/1 and 30/2 against 20/2 and 30/3. The test asserts they do, which is what fails if both segments were given the left scan's bounds. The shape is read from `MergeScanExec`'s `Debug`, because its `DisplayAs` prints only the peers: the debug form carries the table each segment reads and the embedded `FusedSeries` segment. An in-process region hands the plan observer no separately wrapped region tree, so the per-partition evidence for segments is measured in `native_aggregate_test.rs::check_two_source_segregation` instead. Signed-off-by: discord9 <discord9@163.com> * fix(query): decline a multi-source tree that groups by the metric name The gate that lets a multi-source statement reach the segmenter is `selectors.len() != 1 && !cross_table`, but the metric-name grouping guard above it is keyed on `multi_input`, which is `selectors.len() > 1 && logical_ids_differ`. Two ordinary Mito tables differ in table name and carry no metric logical id, so they are `cross_table && !multi_input`: the guard did not apply and the statement reached the segmenter. `fused_output_tags` keeps a grouping by `__name__` out of the declared columns on purpose - the name travels in the chunk's labels, not as a tag column - so `sum by (__name__)` over two sources derives no tag column while the runtime holds two groups that differ only by metric name. Both are then reported under one label set, as two rows a reader cannot tell apart. That is the failure the metric-logical-table test already documents; it could not catch this path because its tables make `multi_input` true. The check is scoped to a tree that reads more than one source. One source folds one metric, so its groups carry the same name and naming that name or dropping it cannot merge two of them. Signed-off-by: discord9 <discord9@163.com> * test(query): cut a range function on each side of a division The two-source cases so far cut an `Instant` prefix: one sample per grid point. A window function's prefix computes its window inside the region over that source's own samples instead, so the segment carries a `Window` rather than an `Instant` and nothing tested that such a prefix is still a cut candidate. `sum(increase(a[2m])) / sum(increase(b[2m]))` over two tables: at the first step the increases are 60 and 30, at the second 120 and 90, so the ratio is 2 and then 4/3. Two different step values are what let a shared window bound change an answer, which is asserted before the result is compared. The shape is read from `MergeScanExec`'s `Debug` for the same reason as the offset case: an in-process region hands the plan observer no separately wrapped region tree, so the per-partition evidence lives in `native_aggregate_test.rs`. This is the shape of the throttling query in the benchmark corpus: a window under a fold, on each side of a division. Signed-off-by: discord9 <discord9@163.com> * test(query): plan the benchmark's throttling and namespace-ratio shapes Every two-source case so far divides two ungrouped scalars. The corpus queries that motivate this work group by a label on each side, so each segment reports several groups and the parent matches the two sides by that label. Nothing tested that path. `container_cpu_cfs_throttled_periods_total` over `container_cpu_cfs_periods_total` is the corpus query verbatim: two metric logical tables on one physical table, `sum(increase(...)) by (container)` on each side. It plans as one frontend `FusedSeries` over two `MergeScan` children, each holding a segment bound to its own metric, and reports the same labelled rows as the existing plan. The namespace-CPU-usage-over-requests shape differs from the corpus text only in the metric names, because the corpus names carry recording-rule colons that a table name cannot: it exercises the nested `sum(max by (...) (...)) by (...)` form and is asserted as that shape rather than as the query verbatim. Both tests assert the native route answered, so a decline fails here instead of passing on the legacy rows. The value column still differs from the existing plan's - the same known gap recorded for the ungrouped case - and both names are pinned. The fixture helper records the three setup traps the hard way: `INSERT` needs explicit column lists because the physical table's column order differs from the logical table's, SQL keywords used as tags need quoting, and no sample may sit at timestamp zero, which both the scan's lower bound and PromQL staleness drop. Signed-off-by: discord9 <discord9@163.com> * test(query): record which native route every corpus query takes The corpus is 29 queries and nothing said which of them the native route answers, or by which of its plans. One parameterised test now runs all of them over generated fixtures and records, per query, the route and the numbers. Four routes, and the frontend tree alone cannot tell them apart: - `segmented` - the frontend runs a `FusedSeries` over `MergeScan` children, one per source; the prefix work happens in the regions. - `aggregate-split` - the frontend runs `AggregateFinalizeExec` over a region `FusedSeries` that reports `partial state:`, so what crosses the boundary is aggregate state. - `region-local` - the frontend holds no native node at all: a per-series tree is commutative, so the whole `FusedSeries` is pushed into the region. A classifier that only looks at the frontend calls these legacy, which is what happened before this test existed. - `legacy` - no native node on either side. All 29 take a native route: sixteen `aggregate-split`, nine `segmented`, two `region-local`, none legacy. The two `region-local` ones are the corpus queries that fold nothing - a bare selector and a `rate` - which is also why pushing the whole tree into the region costs nothing. The test asserts only that the existing plan answers each query with rows, and that a native route's labelled rows agree to within `1e-10` relative. It records the route rather than asserting it, because which route a shape takes is a property of the planner that this test exists to report, not to legislate. Ten queries differ from the existing plan in the last bits; the largest relative difference is 2.9e-16, which is summation order, not arithmetic. The table prints that figure per query so a future equality failure can be told apart from rounding without re-measuring. Every fixture here is generated: explicit `INSERT` column lists, quoted SQL keywords, and no sample at timestamp zero. They establish the plans and the values; they say nothing about speed, memory, or how many partitions actually produced rows. Signed-off-by: discord9 <discord9@163.com> * test(query): record how many partitions each corpus query's nodes used The route matrix said which plan answers each query. It did not say whether that plan produced anything, so a node that ran and emitted nothing looked the same as one that worked. `output_values_per_partition` reads `native.root.output_values` off a `FusedSeriesExec` and returns the counts per partition, and the matrix prints them as `partitions used`. `assert_four_native_partitions` keeps its own assertions and now builds on the same helper. What the column does not establish, and says so where it is printed: these fixtures hold a handful of series each, so a scan puts them all in one partition - every vector here is `[n,0,0,0]`. That is a property of the fixture, not of the plan. The one place a fixture is built to fill the scan's partitions is `native_aggregate_test.rs::check_two_source_segregation`, which asserts all four produce values for both segments of a two-source statement. This matrix records a single assertion instead: at least one partition produced values, so a node that ran and emitted nothing fails. Four cases report `no metric` - L05, L06, L08 and R03, the same-table pointwise divisions. Their region side has no `FusedSeriesExec` at all, because both scans are matched inside one region: that is the route, not a missing measurement, and the table says `no metric` rather than implying zero. Signed-off-by: discord9 <discord9@163.com> * test(query): record the new rule in the explain stages `TQL EXPLAIN` lists the plan after every physical optimizer rule, so registering `SeriesFrameOutput` adds one line to that listing whether or not the rule changes the plan. The three `TQL EXPLAIN VERBOSE` statements in this case use ordinary tables, whose schemas carry no series frame declaration, so the rule returns the plan untouched - the new line says `SAME TEXT AS ABOVE`, which is what the existing lines say for the same reason. Regenerated by the sqlness runner; the diff is those three lines and nothing else. Signed-off-by: discord9 <discord9@163.com> * test(query): make the corpus matrix prove what it claims Three gaps, all in the test the "every corpus query answers natively" claim rests on. The partition helper returned early on a plan that reported no `native.root.output_values`, so a producer that registered nothing passed on the declared partition count alone. It now expects the metric: the point of the assertion is that every partition executed, and an absent counter says nothing about that. `segmented` was decided by the frontend tree containing a `MergeScan`, which also matches a frontend native node consuming raw frames from its regions - a different placement that says nothing about a prefix running in a region. The merge scan's `Debug` carries the plan its region runs, so the check now reads that for a segment; the raw case gets its own `frontend-raw` route. Four queries move there: L05, L06, L08 and R03. The matrix held 23 of the 29 queries: Q05, Q08, Q09 and Q10 had only ever been probed in a throwaway run. They are entries now, with the join labels Q08 and Q09 match on and real `le` buckets for Q10's histogram. A fallback is no longer a route to record: a case that reaches the existing plan fails, because that is the regression this table exists to catch. Twenty-seven cases here plus the separate Q04 and Q07 tests cover all 29. Signed-off-by: discord9 <discord9@163.com> * refactor(query): let the compiler decide which calls this route answers A second list of function names stood beside the compiler's own capability check, and the two disagreed. `admitted_selector` named five calls; the compiler folds `ceil`, `floor`, `sqrt`, `irate`, `avg_over_time`, `sort`, `absent` and more. So `ceil(m)` was refused while `sum(ceil(m))` was admitted, and the same call meant two different things depending on what wrapped it. The compiler already answers this question: `compile_call` refuses a name it has no kernel for with `NotImplemented`, and the planner turns that into a decline. With the list gone there is one place that decides, and a call the compiler folds reaches the route whether or not it is wrapped in an aggregate. `sort` and `absent` read across a vector rather than one series at a time, which is why the old list named them out. They compile, so they are planned; the tests that asserted the refusal now assert the admission. Only the shapes the compiler genuinely cannot express keep the existing plan - a subquery evaluates its body on a grid of its own, which this route does not offer. Signed-off-by: discord9 <discord9@163.com> * refactor(query): admit an operand by its shape, not by call name An operand of a hybrid binary was admitted only if it was a selector under one of five named calls. The compiler folds many more than those five, so `ceil(m)`, `irate(m[5m])`, `sort(m)` and `absent(m)` were refused while the same call under an aggregate was admitted - the name list disagreed with the compiler about what this route can answer. What the list was really protecting is a layout assumption, and the shape states it directly: `try_plan_native_operand` hands back a selector's planner context, and the hybrid caller reads field columns and tags off that context, so an operand whose output layout is not its selector's cannot be one. `sum(A) / B` is refused for that reason, not because `sum` is a name. `single_selector_spine` states it on the expression: a selector, parentheses, unary, a call carrying exactly one vector-or-matrix argument, or a binary whose other side is a compile-time constant. Calls are followed by the type of their arguments rather than by `constant_value`, because a call's string parameters are constants that `constant_value` does not fold and would otherwise look like data. Which calls this route answers is now the compiler's answer alone: a name it has no kernel for comes back as `NotImplemented`, which the planner turns into a decline. Signed-off-by: discord9 <discord9@163.com> * feat(promql): mix raw and evaluated inputs in one fused tree `build` refused a tree whose children were not all raw or all evaluated, but nothing below that point assumed uniformity: `execute` picks the decoder from each source's own schema, `FusedFeed` carries the source index, and `collect_source_schemas` already validates a repeated source against its own grid. A frame stream has one format per stream, not one per consumer, so one segment can decode the raw samples of a rate and compare the result against a vector a previous stage already evaluated. Remove the refusal and make the remaining per-input decisions per source: `evaluated_global` now asks about the source it orders, and `window_sources` keeps only the evaluated sources, since a raw source is answered by the raw path it always used. Cover it by executing `rate(x[5m]) + y` where `x` arrives raw and `y` arrives evaluated on the statement grid. The test asserts all ten (host, timestamp) rows and fails on the removed refusal if the refusal is restored. Signed-off-by: discord9 <discord9@163.com> * feat(promql): bind a segment to every source its subtree reads `cut_as_segment` accepts any exportable subtree that is not `SinglePartition`, so a matching subtree over two sources - `m / n` - is a legal cut point. `build_inner_segment` then required exactly one source and returned `None` for it, and `segment_tree` propagates that `None` as "the statement keeps the plan it had", so `sum(topk(1, m / n))` fell back to the legacy path even though its cut was legal. Build the segment from every source the subtree reads. Each child gets the `RawSeriesSource` boundary already used for separate metric tables, which carries that source's own metric, tags and fields across the boundary and makes the child placeable; a segment over two tables cannot sit inside either region, so it runs above them. The single-source case keeps its existing direct-scan path unchanged, which is what lets a one-table segment still be pushed into its region. Field names come from `tree_source_fields` on the rewritten tree, whose source indexes are already dense in the order the children are built. That helper also validates a repeated source against its own schema and refuses a non-dense index set, which a second traversal would have to re-derive. It becomes `pub` and is re-exported for the query crate to call. Take the segment's time column from its own first source rather than from the statement's first: a cut whose sources are `[1, 2]` would otherwise name the time column of a table it does not read. Cover the construction with a planner test and with a real-Mito integration test that asserts both the exact values and the route: one segment over the two tables, each child reading its own table through its own raw series source. Without the route assertion a silent fallback would pass on equal values. Signed-off-by: discord9 <discord9@163.com> * feat(promql): run a matching tree at the configured width A matching tree's width came from its inputs: `matching_partitions` took the selected source's count, or the maximum of every input's. In standalone a cross-table statement arrives as one `MergeScanExec` per table with one partition each, so `m / n` matched on a single worker while the scans under it ran in parallel. The engine's `execution.target_partitions` was reachable - `plan_fused_series` already uses it for `series_scan` - but never reached this decision. Add `to_execution_plan_with_parallelism(inputs, target_partitions)`, which resolves a matching tree's width as `target_partitions.max(1)` for both the same-source and the multi-input case. `to_execution_plan` keeps its signature and its input-derived width, so a caller that has no configured parallelism is unchanged. `PartitionLocal` and `SinglePartition` trees do not consult the value at all: a per-series tree runs on whatever partitions it was scanned with, and asking for a router there would only add a shuffle. Forward the value through `FusedSeriesExec` because `with_new_children` rebuilds from the node's own children, which are the ones below the router; rebuilding without it would resolve the width again from the pre-router count and silently fall back to one. Verified on a real standalone: the two-table segment now reports four partitions with a `SeriesRepartitionExec` under each one-partition region scan, where it reported one before, and the rows are identical. Signed-off-by: discord9 <discord9@163.com> * test(promql): declare a keyed test frame's ordering, and order its keys `plan_keyed` built its schema with `datatypes::series::frame::series_frame_schema`, which hardcodes the frame metadata `ORDERING` to `contiguous`. The stream it returns packs what `RawScript::ordering` reports, which is now the key-then-time order this helper models. The node reads the ordering off the *plan* schema, so the two disagreeing meant the router scheduled these fixtures as `Contiguous` while unpacking validated them under the stricter ordered contract. Build the schema through `frame_schema_with` with the ordering the stream actually produces, so the plan and the runtime frames state the same contract. That mismatch was invisible until `RawScript` stopped hardcoding `Contiguous`: with both sides claiming `contiguous`, the ordered validation never ran. Running it showed the matching fixture feeding key `b` before `a` within one partition, which its declared ordering forbids. Reorder the partition; the two pieces of `host="a"` still arrive in different partitions, which is what the test is about. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): declare the key order a two-phase raw scan actually keeps `SeriesScan::raw_ordering` reported `SeriesOrdering::Contiguous` for a `TwoPhase` scan that is not reading columnar artifacts. The data that path produces is ordered by primary key: - candidates are merged and sorted ascending by the encoded primary-key column, then decoded to ids by walking that ordered stream without reordering; - partition assignment is a deterministic TSID-to-partition map that appends in arrival order, so one series never spans two partitions; - each assignment is drained completely before the next is taken, rather than emitted in completion order; - the raw adapter's predicate buffering preserves input order and cannot let a later key overtake a held one, and two-phase records always report `ends_package: false`, so it never engages the package-tail machinery that legacy relies on. Declaring the weaker order costs two things that are available: the frame codec's `SequenceValidator` never ran its increasing-key check, and a repartition owner could not use a key watermark to release an identity before another input ended. It also contradicts the scanner's own documented contract, which states the output is always ordered by (primary key, time index) within a partition. Report the order the path actually keeps, and reword the two ordering errors that said "legacy" now that both modes can reach them. Cover it with a test that forces two-phase mode and the non-prepared fallback, asserts which of the two it ran, and then checks per-partition key monotonicity, per-series timestamp monotonicity, single-partition ownership, and the ordering the scan reports. The fixture writes three rounds, uses two output partitions and a residual predicate, and keeps one series above a batch so the multi-batch path is exercised. The three existing two-phase raw tests asserted the old declaration. They check that a series stays in one run and never recurs non-adjacently, which the stronger order still guarantees; only their expected declaration and their names said "contiguous", so those change and the substantive assertions stay. Signed-off-by: discord9 <discord9@163.com> * fix(promql): route a raw match only by a key the computation keeps `same_source` answers "this subtree reads one source", and a `MatchingLocal` classification was taking that answer as licence to insert the router below the fused computations, hashing the labels as they are at the raw stage. Those are different facts. A math map drops the metric name and the `__type__`/`__unit__` metadata, `timestamp` does the same, and every range function drops them except `last_over_time` and `first_over_time` — so `on(__name__)` over `abs(...)` routes by a key the very next node deletes. Concretely, `abs(x) + on(__name__) abs(y)` with one series on each side routes `x` and `y` to different owners; both become the empty key after `abs`, nothing re-partitions between the map and the match, and the pair is silently lost. Decide preservation separately from source identity. A node keeps the key when it cannot remove one of the labels the key is built from; a `Window` consults `RangeFunction::drops_metric_name` rather than assuming, so the two functions that keep the name still route early. Anything not proven to keep the key — a label rewrite, a histogram map, an unmodelled node — does not establish preservation, and the tree is classified `SinglePartition`. That is not a fallback that trades parallelism for correctness. When the computation removes the labels the key is built from, every series on one side reduces to the same empty key, so every left series matches every right one: the match is whole-vector by construction and has no partitioned form that preserves its result. One partition is the only placement that answers it. Where the key does survive, the match stays partitioned. Signed-off-by: discord9 <discord9@163.com> * fix(query): describe an admitted operand by what it produces `try_plan_native_operand` handed the binary matcher the context saved during scanning, which describes the operand's *input* layout. An admitted call can change that layout: `histogram_quantile` folds a classic histogram and drops `le`, so the scan context still names a tag column the operand no longer produces, and default matching then builds a join key over a column that is not there. Concretely, `histogram_quantile(0.9, m) / histogram_quantile(0.5, m)` declines whole-tree planning (two selectors over one table) and is then admitted operand by operand; each operand drops `le`, and planning fails building the join with `FieldNotFound { field: "le" }` against a schema of `timestamp, field_0, host`. Publish only the tag and field columns that the operand's own plan schema actually contains, and drop `use_tsid`, which the produced output does not carry. The check is against the schema the node returns rather than against a list of functions that happen to shrink it, so a call added later cannot reintroduce the gap by not being on a list. Covered by a classic-histogram fixture with `host` and `le` and a float bucket field, asserting each operand's context reports `["host"]` and that the planned join key omits `le`. Reverting the change fails that test with the `FieldNotFound` above. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the partitioned duplicate-group answer, with the gap named `native_hybrid_binary_05_06_08` asserted that the right side's two `job="other"` series are refused as a duplicate match group. On the partitioned route they are not: the check is gated on `lhs.presence && rhs.presence` computed from the partition's own slices, so the partition holding `other` sees no left-hand data and filters every point out. Pin what the route actually answers, and state the three things that constrain the fix, because each has already been tried and rejected here: - the gate cannot be dropped. `prometheus_cases.txt:1065-1075` is a Prometheus-generated case where the left is absent at one point and the right carries three samples of one group there, and the answer is a value with no error; - the scan cannot run unconditionally, for the same reason; - the match cannot be collapsed to one partition to make both operands whole, because that gives up the parallelism this route exists for. What remains is to let the verdict see whole-operand presence while the partitions keep answering — a deferred check rather than a different placement. This test now makes any change to the current answer visible instead of silent. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a nested match instead of gathering it A nested one-to-one match — `x + y + z`, or `(x - y) / on(host) z` — passes the logical admission check, because `independent_scan_pair` recurses through `scan_operand`. The physical locality classification does not go that far: it recognizes a match only when both operands read one source each, so `same_source` fails on an operand that is itself a match and the whole tree is classified `SinglePartition`. The fused computation then ran on one partition while the scans under it stayed parallel, which the existing planner does not do: it builds ordinary equijoins that DataFusion can execute as partitioned hash joins. Admission and placement are different questions, so they now get different predicates. The tree is segmented when it is cross-table, not multi-input, classified `SinglePartition`, and its root is a vector match with a nested vector match directly under it. The inner match becomes a segment and the outer one repartitions the evaluated operands by its own key, which is what the segmenter already does for any exportable evaluated prefix; a nested match whose two levels use different keys is routed twice, once per key, rather than pretending one routing serves both. The predicate stays narrow on purpose. Three-selector trees over distinct metric logical ids are `multi_input` and keep their existing construction, including the parent binding that construction produces. A same-table nested match does not enter this branch either, so its prior admission is unchanged. The plan test's collector walks each fused node's native tree in expression-child order and resolves each input's `source_index` against that node's inputs, so a segmented plan is checked for the same property as before — every selector occurrence bound exactly once, in expression order — rather than being checked more weakly. It panics on a shape it does not model instead of returning an empty list. Signed-off-by: discord9 <discord9@163.com> * fix(promql): prove a raw match key survives the computation `preserves_matching_key` decides whether a subtree keeps the labels a vector match routes by. Two arms answered yes without looking at the field that decides it. A binary with a scalar operand recursed into the vector side alone, but arithmetic and a `bool` comparison drop the metric name while a filtering comparison keeps it — the distinction execution already makes. And an `Instant` recursed unconditionally, while `timestamp(x)` compiles to `InstantValue::Timestamp`, which drops the name too; the check written for the separate `Timestamp` node never covered that shape. Both now read the field that decides: the operator together with `return_bool`, and `InstantValue`. The labels checked are the whole computed set — name, type and unit — because `drop_metric_name` removes all three and default matching does not ignore the last two by itself. Without this, `(x * 2) + on(__name__) (y * 2)` was classified matching-local, the router hashed the raw names before the maps dropped them, and a valid pair could land in different partitions with nothing re-partitioning afterwards. The regression asserts the value is 10 and that the tree is `SinglePartition`, computing the destinations the router would have used (`x0` to partition 0, `y0` to partition 1 of two). With the old arm restored the value assertion fails with `left: [10.0], right: []`. Signed-off-by: discord9 <discord9@163.com> * feat(query): find a nested match through the wrappers around it Segmentation was gated on the root itself being a vector match with a nested match beneath it, so `abs(x + y + z)` and `2 * (x + y + z)` never entered: the wrapper or the scalar broadcast sat where the match was expected. Meanwhile the segmenter already walks children and leaves a wrapper in the parent while cutting what it can carry, so no per-wrapper case is needed — the search just has to look through them. Replacing the root check with `carries_prefix` was too wide: almost any multi-source tree contains something a boundary could carry, so ordinary shapes like `some_metric unless on(tag_0) other_metric` were cut for no gain and their inputs stopped being raw sources. So keep requiring a nested vector match, and search for it anywhere in the tree rather than at the root. Wrappers and scalar broadcasts are transparent because the walk visits every child; the nested match itself is still required, which is what keeps the plain multi-source shapes on the plan they had. `cross_table`, `!multi_input` and the `SinglePartition` locality requirement stay, as before: they are what keeps distinct metric logical ids and the same-table shapes out of this branch. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): let a router publish an identity whose chain is complete `SeriesRepartitionExec` published an identity only once every input had contributed it or ended, because an identity may be split across inputs. A per-series region scan assigns each identity to one partition, so on that shape the rule holds every identity until the other partitions reach EOF: a region's whole raw selection is retained before the first series leaves. The node now carries an `IdentityCompletion`, defaulting to the existing merge. `CompleteDisjoint` publishes an identity as soon as its chain closes and keeps the published identities charged in the pool, so a second chain for the same identity fails the execution instead of emitting a partial series as final. The declaration is the producer's, not something a consumer infers from a node's type: publishing early against a producer that does not own its identities would be wrong, so the conservative mode stays the default and every existing constructor keeps it. Signed-off-by: discord9 <discord9@163.com> * fix(query): choose a series-frame root's router from declared provenance `SeriesFrameOutput` normalized every multi-partition frame root through a router that merges identities, which is wrong for a root whose identities are already disjoint: it waits for every scan partition to end before the first series leaves. The rule now selects `CompleteDisjoint` only for a root whose producer declared that property. A raw root qualifies when `RawSeriesSourceExec` was built through `to_per_series_execution_plan` - which also checks the child is a `SeriesScanExec`, so the type alone is not taken as proof - and a direct `SeriesRepartitionExec` root qualifies because it merged the identities itself. Everything else, including a fused frame root, keeps the merging router: a native label transformation can map two source series onto one output label set, so its output identities are not exclusive. The rejection of a key-only raw frame is unchanged and its reason is restated: coalescing cannot produce such a frame, and a router needs explicit labels to check that one key has one binding. Signed-off-by: discord9 <discord9@163.com> * fix(promql): report the labels `absent` names, not the table's columns `fused_output_tags` answered `None` for `absent`, so the caller fell back to the existing planner's column names. Those are the table's tag columns, which is not what `absent` reports: `absent(m{host="x"})` carries the labels its matchers name, and the compiled tree already knows them in `BoundVectorOp::Absent { labels }`. The label set is now read from that field: the named labels are kept in the input's column order, so `absent(native_shapes{host="missing"})` over a table with `host` and `le` reports `host` rather than `ts, val, host, le`. A label the matchers name that is not an input column still answers `None`, because a frame has no column to carry it; `count_values` and `histogram` are unchanged. Caught by the native-versus-legacy value comparison: the extra column made `absent` differ from the existing plan while every value matched. Signed-off-by: discord9 <discord9@163.com> * fix(promql): describe a frame root's emission from what it does `FusedSeriesExec` declared `EmissionType::Final` for a frame output, but `poll_output` hands a frame's evaluated chunk over while its input is still arriving, so the declaration overstated the node to the optimizer. Only a partial aggregate's state is emitted after EOF; every other output keeps its input's emission type. Signed-off-by: discord9 <discord9@163.com> * test(promql): compare the shapes the native route now admits with the existing plan Removing the shapes a name list used to refuse put single-selector `sort` and `sort_desc`, `absent`, and a bare `histogram_quantile` on the segmented route. Nothing compared their answers with the existing plan, so the widening was unverified. The new case runs each shape both ways over one metric table. `sort`, `sort_desc` and both `absent` cases compare the whole printed result, which covers column names and values together. `histogram_quantile` compares values row by row and asserts the one known difference instead of hiding it: a segmented statement names its value column from the compiled tree (`val`) where the existing plan names it after the expression that produced it. That case is given a window long enough to produce a row, so it cannot pass by comparing two empty results. The `absent` cases caught a real difference: the native route reported the table's tag columns rather than the labels the matchers name, which is fixed in the preceding commit. Signed-off-by: discord9 <discord9@163.com> * fix(query): publish a fused root's identities early when the tree keeps them The root rule publishes an identity as soon as its chain closes only for a root whose producer declared that each identity lives in one partition, and it knew two such producers: a per-series raw scan, and a router that had already merged its identities. A fused root was always treated as needing a merge, so a region whose segment is a plain instant selection over one per-series scan still held every identity until the other scan partitions reached EOF - `sum(topk(1, m))` is that shape, and its segment is already multi-partition with no label rewrite. `FusedSeriesExec` now answers whether its output identities are disjoint, and the rule asks it. The answer is narrow on purpose: one input, and a tree of nothing but inputs and sample instant selections, over a per-series scan or another fused node that already answered yes. Anything that computes labels is excluded, because a timestamp or a pointwise map can map two source series onto one output identity, and publishing early would then hand over one identity's pieces as if they were different ones. A vector-to-vector binary reads across series and is excluded too. Signed-off-by: discord9 <discord9@163.com> * fix(query): segment a computed matching key's operands instead of gathering them A vector match whose operands compute away one of the matched labels was classified `SinglePartition` and executed on one partition. That is correct for the bare tree - the raw names cannot route a match whose operands drop them - but it also gave up the parallelism the operands still have: `(x * 2) + on(__name__, host) (y * 2)` loses `__name__` and keeps `host`, so the computed sides can be routed by what they actually carry. The planner now cuts those operands into segments of their own and lets the parent route their evaluated outputs by the unchanged match key. The key itself is not rewritten: `group_key` reads the labels present at that point, so `On(__name__, host)` degrades to the `host` a computed operand still has. Which shapes take this route is decided by one predicate shared with `input_locality`, so the admission rule cannot drift from the locality judgement: a matching site whose two operands are each proven single-source computations, at least one of which does not preserve the key. A failed preservation proof on its own is not enough - it can also mean the proof gave up, as with a parameter that is a compound expression or an operand that is itself a vector match - and the shared doc says so. The same table read twice is admitted for this shape only. The rule that declines several selectors on one table exists to keep folds such as `sum(m) / m` off this route, not because one table cannot be read twice; the compiler already gives each occurrence its own source index, and each cut gets its own input. Distinct partitions are what the two operands need, and they get them. The regression executes both the same-table and the cross-table shape over a four-host fixture and asserts that at least two output partitions produce rows, so the result is not silently produced by one of them. Signed-off-by: discord9 <discord9@163.com> * fix(query): take the early-publication guarantee from the scan's binding The root rule publishes an identity as soon as its chain closes only when the producer can promise that each identity lives in one partition, and the fused answer to that question asked whether its input was a `SeriesScanExec`. The node's type is not that promise: a scan binds a set of logical tags and decodes those into the series' labels, and `try_to_named_series_scan` requires the caller to pass complete tag names but does not check it. A binding that names only some primary-key columns maps two stored series onto one output identity, and early publication would hand one identity's pieces over as different ones. The answer now reads the binding: the label source has to be `PrimaryKey`, and every primary-key column has to be among the bound tags. A source that carries its labels explicitly is not this shape and answers no, as before. Covered by a new `bound_tags_cover_primary_key` unit test - partial coverage is false, full coverage is true, an explicit source is false - and by tests for the predicate's two other parts: a tree that computes labels and a tree that is not one instant selection over one input both answer no, and a gated execution shows a completed identity leaving a fused node while the other input is still held. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): drop the checks the types and decoders already guarantee Two re-checks ran inside the repartition node over facts its inputs had already established, and both cost real work on every query. A raw merge scanned each chunk's timestamps for strict increase, but `RawTimestamps` cannot hold an unordered buffer: its field is private, its only constructor validates, and the accessors are read-only or order-preserving, so no safe caller can build the value this check defends against. The check is gone; the identity, label and shape checks around it stay, because those compare different producers' pieces rather than one chunk's own timestamps. An owner rebuilt each chunk's identity to prove a chain does not change it, but the decoder that hands the chain over already refuses that: `SequenceValidator` holds one open key and rejects a key or metric change before the chain closes, `EvaluatedSequenceValidator` does the same for labels, and the input task that assembles chains only reads from those decoders. What stays is the identity the owner needs anyway to pick a destination, now built by the named functions rather than inline. Where a schema was needed, the node built an empty stream of its own, wrapped it in a packer and read the packer's schema back. The frame module already answers that question from the declaration, so the fake stream is deleted along with its half of the roundtrip. Signed-off-by: discord9 <discord9@163.com> * fix(promql): recursively segment native matching plans Signed-off-by: discord9 <discord9@163.com> * fix(promql): derive native schemas without legacy probes Signed-off-by: discord9 <discord9@163.com> * fix(promql): recognize complete metric scan identities Signed-off-by: discord9 <discord9@163.com> (cherry picked from commit 8f752a02dbb9dc7858618c1d5cc0c41e2d4efb23) * fix(promql): release completed disjoint identity history Signed-off-by: discord9 <discord9@163.com> (cherry picked from commit 9975fa6c5c68786e18af230f62041d2aa5e71f6c) * test(promql): assert native aggregate schemas independently Signed-off-by: discord9 <discord9@163.com> * fix(promql): identify internal metric keys by reserved id Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep parallel sources and derive group match labels Signed-off-by: discord9 <discord9@163.com> * test(promql): observe the frontend fused root in scan-parallelism checks Signed-off-by: discord9 <discord9@163.com> * fix(promql): release duplicate evidence immediately on abort Signed-off-by: discord9 <discord9@163.com> * test(promql): preserve operand identity across matching repartition Signed-off-by: discord9 <discord9@163.com> * fix(promql): charge the final duplicate verdict until it is reported Signed-off-by: discord9 <discord9@163.com> * test(promql): observe native scans across frontend and region plans Signed-off-by: discord9 <discord9@163.com> * chore(promql): drop dead test helper and clippy lints Signed-off-by: discord9 <discord9@163.com> * fix(promql): select limitk by canonical label order Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep data-free subtrees in the parent segment Signed-off-by: discord9 <discord9@163.com> * test(promql): prove the duplicate error crosses matching partitions Signed-off-by: discord9 <discord9@163.com> * test(promql): drop debug prints from the segmentation test Signed-off-by: discord9 <discord9@163.com> * revert(promql): keep limitk's Prometheus input-order semantics Signed-off-by: discord9 <discord9@163.com> * chore(promql): satisfy clippy in fused root schema Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): admit label rewrites and decide canonical collection once (#10097) * fix(promql): let a closed chain keep its charge until the packer is done Four places released the frame reservation: the early-publish path handed it to the packer, but the queue drain and the end-of-input path freed it in place. Those two run while the packer still holds rows it has not turned into batches, so a series spanning several batches went unbilled once its last piece was handed over. Every emit path now hands the charge over, and the packed stream frees what it holds: what is left when it is polled and pending is the one identity it is turning into batches, and nothing survives its end or its drop. The identity guard is also widened: within one source every series shares its metric name, so a node that drops `__name__`/`__type__`/`__unit__` -- which is what a range function, a math map and the timestamp shape do -- still maps distinct series to distinct labels. Only rewriting an ordinary label can make two equal, and that is what the guard refuses. Ordinary `rate` and arithmetic frame output therefore publish as their chains close instead of buffering a partition. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep a cross-source tree's partitions, and gather a raw one only when it must Three defects in how this node decided a tree's execution layout. A match whose two operands derive from the same source still needs its match keys co-located, but only the two-source case was recognized. `x - 2*x` with `on(host)` therefore fell through to single-partition execution and lost the parallelism the scan gave it. A raw input never received a matching router: the normalization branch returned it unchanged unless the whole tree was global, while the builder requires a direct matching router for any multi-partition matching-local input. A two-source raw query was rejected at planning. Nothing reconciled the partition counts of different sources either, though the builder requires one common positive count. A single count is now computed for the matching-local case and every router under it uses it, gathering when that count is one. The window restriction also ran before normalization decided the layout, so a tree about to be gathered could be refused for a limit that only applies to partitioned windows. Two tests changed with the behaviour rather than around it: hash routing does not promise which partition holds a given series, so that test compares results instead of placement while keeping its partition count, per-partition execution and operand-order assertions; and a test that pinned the old refusal of a multi-source frame now pins its acceptance. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): keep a raw source's scan partitions instead of gathering them `RawSeriesSourceExec` declared one partition and read every child partition inside `execute(0)`, so a cross-table node lost the scan's parallelism before its inputs reached it. It now declares the child's own count, executes exactly the partition it is asked for, and re-labels that partition's frames. That leaves `SeriesGather` with no consumer: it existed to interleave several partitions into one stream. The module is gone rather than kept as a hidden N-to-one path a later plan could quietly fall back on. Signed-off-by: discord9 <discord9@163.com> * fix(promql): publish a raw source's frames under the ordering it declared `pack_raw_series` derives the frame schema from the stream's own ordering, and `RawSeriesSourceExec` fixes that schema at plan time from a constant. Passing the scan's stream through unchanged broke that agreement: a columnar scan promises key-then-time, so the region published key-then-time frames while the frontend still expected the schema it had built, and `MergeScan` refused them. The forwarding adapter restates the ordering this node declares. It is the weaker promise, so a scan that keeps a finer one still satisfies it, and every other stream property is forwarded unchanged. Signed-off-by: discord9 <discord9@163.com> * fix(promql): route a raw frame that names its labels by its key A region cannot hand out complete labels: it has no metric-name binding, so `prepare_raw_scan` refuses an explicit binding outright. What it hands out is the stored key plus the description a decoder needs, which is the normal input to this node rather than a case to refuse — every single-table selector is planned that way. The node's constructor refused exactly those frames, so any plan that inserted a router under a single-table selector failed before it ran: the matching policies this branch adds, and the one-partition normalization of an evaluated tree. The node publishes labels, because that is what it groups and closes identities by: `finish_raw_group` reads `chunk.metric` and the merge needs it too. So the input is decoded once, at the unpack boundary this node already has, and an already-labelled stream passes through it untouched. The frame it declares is rebuilt from the input's own declaration instead of being compared against it, which keeps the check that a frame this node cannot re-declare is refused while letting input and output differ in how they name the same series. `frame_schema_with` becomes public for that rebuild, since it is the one place that decides what a declaration is. `FusedSeries` now describes the router's output rather than the scan's when it wraps a raw input, because the binding it hands `build` has to match the frame the router actually publishes. Tested through the node directly: a key-labelled input routes at all; matching puts both pieces of one label set in one owner and closes it once; and `RawPrimaryKey` still hashes the key rather than the decoded labels. Signed-off-by: discord9 <discord9@163.com> * test(promql): measure a routed pair by the width it routes to Four assertions still described the layout this branch replaced: a node with two inputs used to read every partition of both into one and answer one partition, and that gather is gone. The pair is now matched in the partitions it was scanned in, so the fused node answers as many partitions as its inputs route to. Each of these fixtures scans with four partitions, and on the base of this branch all five tests passed, so this is a behaviour change this branch made and did not re-verify rather than a defect: the value assertions behind these shape assertions pass unchanged, in both the native and the legacy comparison. The width is read from the routed children instead of being written as four, and the scan is found by walking down through the nodes that only pass its frames along, since a routed input is no longer a bare `SeriesScanExec`. Signed-off-by: discord9 <discord9@163.com> * fix(query): normalize a multi-partition series-frame root A query engine hands its plan to one stream, and for a plan with several partitions that means `CoalescePartitionsExec` - ordinary batch coalescing. A series frame cannot survive it: one stored series may be split across partitions, and a chunk's `is_last` closes that producer rather than the series, so interleaving two partitions' batches produces a stream whose decoder refuses it (`raw series key changed before final chunk`). Evaluated frames have the same shape of problem: their validator keeps one open chain, and a batch from another partition interrupts it. The engine's root is also a region's root, which is how a cross-table native statement reaches this: its per-region sub-plan is rooted at a partitioned `RawSeriesSourceExec`. So the rule belongs at the physical optimizer's end, before the final sanity check, and it normalizes the root and nothing else - `FusedSeries` already inserts its own owner wherever a consumer needs one. A single-partition root is left alone: one producer is the whole answer. A key-labelled raw root is refused rather than coalesced, because the router checks that one stored key decodes to one label set and it needs the labels to do that. No production plan reaches that rejection today - the only producer of a key-labelled frame is the region's series scan, and every plan that executes it puts `RawSeriesSourceExec` or `FusedSeries` above it, both of which publish explicit labels - and the rejection is what keeps it that way. `schema_check` stays enabled: for the roots this rule accepts, the router re-declares its input's frame with the same content, label mode, decode description and ordering, so the schema it publishes is the one it was given. Signed-off-by: discord9 <discord9@163.com> * feat(promql): admit an evaluated frame as a fused input The extension planner hands a child straight to the fused executor when that child already publishes a series frame, and until now it only recognised a raw one. A segment's output is an evaluated frame, so a statement planned as two segments could not be bound above the first one. The check it replaces asked for a raw frame; the property that matters is that the frame names its own series, which is what `labels() == Explicit` says - evaluated frames always declare it and carry no decode description. Everything else stays with `FusedSeriesExec::build`, which already refuses a mixed-content node, an evaluated input that is not contiguous, and a frame whose declaration does not match the binding it was given. Signed-off-by: discord9 <discord9@163.com> * feat(query): plan a global topk under an aggregate as two segments `sum(topk(1, m))` needs the whole vector for its ranking, which is a property of the tree rather than of the statement, and the routes that existed could only answer a whole-vector tree in one partition: the statement fell back to the existing planner. Splitting it lets the per-series prefix keep the scan's partitions while the ranking sees every candidate. The cut goes below the `topk`, not below the `sum`. A segment holding a `topk` reads across series, so it would gather its own input before evaluating the prefix - correct numbers, no parallelism, which is the thing the split is for. Below the `topk`, the prefix runs on the scan's partitions and the ranking and the fold above it run once, on the child's evaluated frame. Both segments are built from one compiled tree: the child is the prefix subtree, the parent is the original tree with that subtree replaced by an input bound to the child's frame. Nothing is re-parsed, so the grid, the matching rules and the bound scans are the ones the compiler produced. The parent needs its output columns without asking the existing planner to name a computed column after its expression, so `fused_output_tags` now derives the grouping labels of an `Aggregate` and passes a selecting `Vector`'s input labels through. It derives output *columns*, not a complete runtime label set: the metric name is bound separately from the tag columns, and a grouping by `__name__` keeps that name in the labels while contributing no column. `fused_root_schema` is that derivation, shared with the ordinary route. The segmenter is its own method, boxed at the call site. Inlined, its future made every frame of the planner's recursion large enough to overflow the stack on a deeply nested statement - `test_parse_or_operator` aborted before this. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the two-segment topk plan and what it keeps The statement's two segments do not land in one physical tree: the prefix has one scan for a child, so the categorizer classifies it commutative and pushes it into the region, while the aggregate above it stays at the frontend. The observer therefore records every plan a query engine wraps, not only the first, so the test can look at the region's own root. What the assertions pin, and why each one is worth its brittleness: - the answer is the global maximum, not a sum of per-partition winners; - the frontend segment holds the complete sum and the global topk over an evaluated input, with no instant evaluation left in it; - the region's segment holds the prefix and its output is an evaluated, explicitly labelled, contiguous frame; - that segment keeps more than one output partition, which is the whole point of cutting below the topk; - the region's root is the series-aware router, one output, and it reads that segment. Column names are not compared: this route names a computed column after its compiled root while the existing planner names it after the expression, which is older than this split and not what this test is about. Signed-off-by: discord9 <discord9@163.com> * feat(promql): share the input-locality classification A tree's distribution requirement is one property, and two layers now ask it. The physical planner already decided with `input_locality` what a tree needs from its inputs; the logical planner has to ask the same question when it splits a statement, or the two can disagree about what a subtree requires. `InputLocality` and `input_locality` are therefore public within the workspace. The classification describes the external inputs a tree needs - not its output distribution, and not which neighbouring operators may share a node - so a caller that reads it as either of those will cut where it should not. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a statement where a gather would swallow its prefixes The previous commit planned `sum(topk(k, prefix))` by matching that shape. A planner that grows one matcher per query shape grows one per benchmark entry, and the shape is not what decides where a statement divides: the tree already says what each subtree needs from its inputs, and `input_locality` answers it. So a segment is now a maximal subtree with one distribution requirement. Inside a tree that must gather, any child that (a) can cross a boundary - it produces evaluated samples rather than raw samples, aggregate state or a scalar - and (b) does not itself need a gather, becomes a segment of its own and keeps the partitions it was scanned with. Nothing else is cut, and a tree with nothing to cut keeps the plan it had. Every segment rebinds its own inputs: the scans it reads directly first, in the order it first names them, then the segments cut out of it, because `FusedSeries` requires dense source indices over its children. `fused_output_tags` derives the parent's columns from those inputs rather than from the statement's first selector. Three gates keep this from answering what the routes before it would not. Each one is a failure this change produced before it was added: - the existing planner must still be able to plan the statement. Deriving tags locally had cut the route off from that refusal, so `sum(clamp(m, 2, 1))` - an empty range, which the existing planner rejects - was answered instead of failing; - every segment's tree must construct a `NativeExecutionState`, because nothing below can fall back once physical planning starts, and a grouping by a value field is a shape the runtime refuses; - the tree must contain a prefix that a boundary could carry, so a whole-vector tree with no per-series work inside it is not split for nothing. The scope is one selector. A statement over two tables binds each scan as a `RawSeriesSource`, and a segment whose child is that wrapper cannot be placed in a region, so its prefix would not gain the partitions the cut is for; those statements keep the plan they had, which the acceptance test pins. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the segment boundaries and their scope One statement per shape the cut can meet, asserting what the rule says rather than what one query happens to produce: a per-series tree stays one node, a matching tree routes instead of gathering, a global fold over per-series work cuts that work out, a constant stays embedded because a boundary cannot carry one, and a statement over two tables keeps the plan it had because a segment over `RawSeriesSource` cannot be placed in a region. Answers are compared as sets of rows with the value column renamed. Three things differ between the routes and none of them is the answer: this one names a value column after its compiled root while the existing planner names it after the expression, the two emit columns in a different order, and this one is partitioned so its rows arrive by partition. Comparing them as what they are leaves the values as the only thing an assertion can fail on. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep a selected segment whole A segment is chosen because its subtree needs one distribution; cutting inside it again contradicts the choice. The inner builder was still applying the cut predicate, and that predicate is "exportable and not `SinglePartition`" - which every node inside a per-series subtree satisfies, since a per-series tree has no `SinglePartition` node in it to begin with. `sum(topk(1, abs(m)))` showed it: the prefix was cut out of the `topk` as one segment, then `abs` was cut out of that segment, leaving a middle segment whose child is a node rather than a scan. That middle segment cannot be placed in a region, so it answered one partition while the scan had several - the prefix lost exactly the parallelism the cut is for. The inner builder now collects the segment's `Input` leaves and nothing else. Signed-off-by: discord9 <discord9@163.com> * refactor(query): bind a segment to its own scan A cut segment carries one source's identity: its scan, its metric name, its time index, and its labels. Building it from the statement's first selector only happens to be the same thing while a statement has one selector. `build_inner_segment` takes the two lists the planner already has - each occurrence's filtered scan, and each occurrence's metric, time index and tags - and binds the segment's single source from them. The parent keeps the wrapped children and the statement-level binding it has now, because a source that reaches the parent directly still has to cross a region as a raw frame. A segment that collects more than one source is declined. `MatchingLocal` satisfies the cut predicate while reading two sources, and one segment cannot carry both sources' identity. No behaviour changes: the entry is still one selector, so no scan is wrapped and the statement-level values are already that selector's. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a statement that reads more than one table A whole-vector statement over two sources is now cut into one per-series prefix segment per source, with the fold above them in the frontend. Each segment binds its own source's scan, metric, time index and labels, so it can be placed in the region that holds that source, and each prefix keeps the scan partitions it was read with. Three things had to change for the existing segmenter to reach that shape: The cut sat inside `!per_partition && !multi_input`, so a statement over two metric tables - which is `multi_input` - never reached it. The cut now sits under `!per_partition` alone. The aggregate split keeps its own conditions, including `!multi_input`, so a multi-input tree is still not split that way. The single-selector gate was doing two jobs. A statement naming several selectors declines unless those selectors read more than one table: the count alone says nothing about whether the tree has more than one input to place, and the shapes it would otherwise admit - one metric named twice under a fold, such as `sum(m) / m` or `m + sum(m)` - are a plan the existing path already answers. `cross_table` rather than `multi_input` decides this, because two Mito tables carry no metric logical id and are still two sources. A segment that collects more than one source is declined. A matching subtree over two sources is a cut candidate, and one segment cannot carry both sources' identity, so `sum(topk(1, m / n))` keeps the plan it had. The segmented parent reports the value column the compiled tree names, not the one the existing planner names; `sum(rate(a[5m])) / sum(b)` reports `v` where the existing plan reports an expression-shaped name. The values are identical and both names are pinned in the test, so a change to either rule shows up there. Restoring the existing name needs a rename above the parent - the node's own schema must keep the compiled names its output columns are classified by - and is left to a follow-up. Signed-off-by: discord9 <discord9@163.com> * test(query): pin that two sources keep their own scan bounds A segmented statement binds each prefix to its own source's scan, and A1 made that binding: `bare_scans` is derived from the prepared scans after each selector's time filter has been pushed into its own `TableScan`. Nothing tested that the two segments actually read `their` bounds rather than one window applied twice - the existing two-source case has no offset, so both sides read the same range and a crossed binding would answer the same numbers. `sum(off_a) / sum(off_b offset 60s)` differs from `sum(off_a) / sum(off_b)` only in the right side's window, so the two queries must disagree: 20/1 and 30/2 against 20/2 and 30/3. The test asserts they do, which is what fails if both segments were given the left scan's bounds. The shape is read from `MergeScanExec`'s `Debug`, because its `DisplayAs` prints only the peers: the debug form carries the table each segment reads and the embedded `FusedSeries` segment. An in-process region hands the plan observer no separately wrapped region tree, so the per-partition evidence for segments is measured in `native_aggregate_test.rs::check_two_source_segregation` instead. Signed-off-by: discord9 <discord9@163.com> * fix(query): decline a multi-source tree that groups by the metric name The gate that lets a multi-source statement reach the segmenter is `selectors.len() != 1 && !cross_table`, but the metric-name grouping guard above it is keyed on `multi_input`, which is `selectors.len() > 1 && logical_ids_differ`. Two ordinary Mito tables differ in table name and carry no metric logical id, so they are `cross_table && !multi_input`: the guard did not apply and the statement reached the segmenter. `fused_output_tags` keeps a grouping by `__name__` out of the declared columns on purpose - the name travels in the chunk's labels, not as a tag column - so `sum by (__name__)` over two sources derives no tag column while the runtime holds two groups that differ only by metric name. Both are then reported under one label set, as two rows a reader cannot tell apart. That is the failure the metric-logical-table test already documents; it could not catch this path because its tables make `multi_input` true. The check is scoped to a tree that reads more than one source. One source folds one metric, so its groups carry the same name and naming that name or dropping it cannot merge two of them. Signed-off-by: discord9 <discord9@163.com> * test(query): cut a range function on each side of a division The two-source cases so far cut an `Instant` prefix: one sample per grid point. A window function's prefix computes its window inside the region over that source's own samples instead, so the segment carries a `Window` rather than an `Instant` and nothing tested that such a prefix is still a cut candidate. `sum(increase(a[2m])) / sum(increase(b[2m]))` over two tables: at the first step the increases are 60 and 30, at the second 120 and 90, so the ratio is 2 and then 4/3. Two different step values are what let a shared window bound change an answer, which is asserted before the result is compared. The shape is read from `MergeScanExec`'s `Debug` for the same reason as the offset case: an in-process region hands the plan observer no separately wrapped region tree, so the per-partition evidence lives in `native_aggregate_test.rs`. This is the shape of the throttling query in the benchmark corpus: a window under a fold, on each side of a division. Signed-off-by: discord9 <discord9@163.com> * test(query): plan the benchmark's throttling and namespace-ratio shapes Every two-source case so far divides two ungrouped scalars. The corpus queries that motivate this work group by a label on each side, so each segment reports several groups and the parent matches the two sides by that label. Nothing tested that path. `container_cpu_cfs_throttled_periods_total` over `container_cpu_cfs_periods_total` is the corpus query verbatim: two metric logical tables on one physical table, `sum(increase(...)) by (container)` on each side. It plans as one frontend `FusedSeries` over two `MergeScan` children, each holding a segment bound to its own metric, and reports the same labelled rows as the existing plan. The namespace-CPU-usage-over-requests shape differs from the corpus text only in the metric names, because the corpus names carry recording-rule colons that a table name cannot: it exercises the nested `sum(max by (...) (...)) by (...)` form and is asserted as that shape rather than as the query verbatim. Both tests assert the native route answered, so a decline fails here instead of passing on the legacy rows. The value column still differs from the existing plan's - the same known gap recorded for the ungrouped case - and both names are pinned. The fixture helper records the three setup traps the hard way: `INSERT` needs explicit column lists because the physical table's column order differs from the logical table's, SQL keywords used as tags need quoting, and no sample may sit at timestamp zero, which both the scan's lower bound and PromQL staleness drop. Signed-off-by: discord9 <discord9@163.com> * test(query): record which native route every corpus query takes The corpus is 29 queries and nothing said which of them the native route answers, or by which of its plans. One parameterised test now runs all of them over generated fixtures and records, per query, the route and the numbers. Four routes, and the frontend tree alone cannot tell them apart: - `segmented` - the frontend runs a `FusedSeries` over `MergeScan` children, one per source; the prefix work happens in the regions. - `aggregate-split` - the frontend runs `AggregateFinalizeExec` over a region `FusedSeries` that reports `partial state:`, so what crosses the boundary is aggregate state. - `region-local` - the frontend holds no native node at all: a per-series tree is commutative, so the whole `FusedSeries` is pushed into the region. A classifier that only looks at the frontend calls these legacy, which is what happened before this test existed. - `legacy` - no native node on either side. All 29 take a native route: sixteen `aggregate-split`, nine `segmented`, two `region-local`, none legacy. The two `region-local` ones are the corpus queries that fold nothing - a bare selector and a `rate` - which is also why pushing the whole tree into the region costs nothing. The test asserts only that the existing plan answers each query with rows, and that a native route's labelled rows agree to within `1e-10` relative. It records the route rather than asserting it, because which route a shape takes is a property of the planner that this test exists to report, not to legislate. Ten queries differ from the existing plan in the last bits; the largest relative difference is 2.9e-16, which is summation order, not arithmetic. The table prints that figure per query so a future equality failure can be told apart from rounding without re-measuring. Every fixture here is generated: explicit `INSERT` column lists, quoted SQL keywords, and no sample at timestamp zero. They establish the plans and the values; they say nothing about speed, memory, or how many partitions actually produced rows. Signed-off-by: discord9 <discord9@163.com> * test(query): record how many partitions each corpus query's nodes used The route matrix said which plan answers each query. It did not say whether that plan produced anything, so a node that ran and emitted nothing looked the same as one that worked. `output_values_per_partition` reads `native.root.output_values` off a `FusedSeriesExec` and returns the counts per partition, and the matrix prints them as `partitions used`. `assert_four_native_partitions` keeps its own assertions and now builds on the same helper. What the column does not establish, and says so where it is printed: these fixtures hold a handful of series each, so a scan puts them all in one partition - every vector here is `[n,0,0,0]`. That is a property of the fixture, not of the plan. The one place a fixture is built to fill the scan's partitions is `native_aggregate_test.rs::check_two_source_segregation`, which asserts all four produce values for both segments of a two-source statement. This matrix records a single assertion instead: at least one partition produced values, so a node that ran and emitted nothing fails. Four cases report `no metric` - L05, L06, L08 and R03, the same-table pointwise divisions. Their region side has no `FusedSeriesExec` at all, because both scans are matched inside one region: that is the route, not a missing measurement, and the table says `no metric` rather than implying zero. Signed-off-by: discord9 <discord9@163.com> * test(query): record the new rule in the explain stages `TQL EXPLAIN` lists the plan after every physical optimizer rule, so registering `SeriesFrameOutput` adds one line to that listing whether or not the rule changes the plan. The three `TQL EXPLAIN VERBOSE` statements in this case use ordinary tables, whose schemas carry no series frame declaration, so the rule returns the plan untouched - the new line says `SAME TEXT AS ABOVE`, which is what the existing lines say for the same reason. Regenerated by the sqlness runner; the diff is those three lines and nothing else. Signed-off-by: discord9 <discord9@163.com> * test(query): make the corpus matrix prove what it claims Three gaps, all in the test the "every corpus query answers natively" claim rests on. The partition helper returned early on a plan that reported no `native.root.output_values`, so a producer that registered nothing passed on the declared partition count alone. It now expects the metric: the point of the assertion is that every partition executed, and an absent counter says nothing about that. `segmented` was decided by the frontend tree containing a `MergeScan`, which also matches a frontend native node consuming raw frames from its regions - a different placement that says nothing about a prefix running in a region. The merge scan's `Debug` carries the plan its region runs, so the check now reads that for a segment; the raw case gets its own `frontend-raw` route. Four queries move there: L05, L06, L08 and R03. The matrix held 23 of the 29 queries: Q05, Q08, Q09 and Q10 had only ever been probed in a throwaway run. They are entries now, with the join labels Q08 and Q09 match on and real `le` buckets for Q10's histogram. A fallback is no longer a route to record: a case that reaches the existing plan fails, because that is the regression this table exists to catch. Twenty-seven cases here plus the separate Q04 and Q07 tests cover all 29. Signed-off-by: discord9 <discord9@163.com> * refactor(query): let the compiler decide which calls this route answers A second list of function names stood beside the compiler's own capability check, and the two disagreed. `admitted_selector` named five calls; the compiler folds `ceil`, `floor`, `sqrt`, `irate`, `avg_over_time`, `sort`, `absent` and more. So `ceil(m)` was refused while `sum(ceil(m))` was admitted, and the same call meant two different things depending on what wrapped it. The compiler already answers this question: `compile_call` refuses a name it has no kernel for with `NotImplemented`, and the planner turns that into a decline. With the list gone there is one place that decides, and a call the compiler folds reaches the route whether or not it is wrapped in an aggregate. `sort` and `absent` read across a vector rather than one series at a time, which is why the old list named them out. They compile, so they are planned; the tests that asserted the refusal now assert the admission. Only the shapes the compiler genuinely cannot express keep the existing plan - a subquery evaluates its body on a grid of its own, which this route does not offer. Signed-off-by: discord9 <discord9@163.com> * refactor(query): admit an operand by its shape, not by call name An operand of a hybrid binary was admitted only if it was a selector under one of five named calls. The compiler folds many more than those five, so `ceil(m)`, `irate(m[5m])`, `sort(m)` and `absent(m)` were refused while the same call under an aggregate was admitted - the name list disagreed with the compiler about what this route can answer. What the list was really protecting is a layout assumption, and the shape states it directly: `try_plan_native_operand` hands back a selector's planner context, and the hybrid caller reads field columns and tags off that context, so an operand whose output layout is not its selector's cannot be one. `sum(A) / B` is refused for that reason, not because `sum` is a name. `single_selector_spine` states it on the expression: a selector, parentheses, unary, a call carrying exactly one vector-or-matrix argument, or a binary whose other side is a compile-time constant. Calls are followed by the type of their arguments rather than by `constant_value`, because a call's string parameters are constants that `constant_value` does not fold and would otherwise look like data. Which calls this route answers is now the compiler's answer alone: a name it has no kernel for comes back as `NotImplemented`, which the planner turns into a decline. Signed-off-by: discord9 <discord9@163.com> * feat(promql): mix raw and evaluated inputs in one fused tree `build` refused a tree whose children were not all raw or all evaluated, but nothing below that point assumed uniformity: `execute` picks the decoder from each source's own schema, `FusedFeed` carries the source index, and `collect_source_schemas` already validates a repeated source against its own grid. A frame stream has one format per stream, not one per consumer, so one segment can decode the raw samples of a rate and compare the result against a vector a previous stage already evaluated. Remove the refusal and make the remaining per-input decisions per source: `evaluated_global` now asks about the source it orders, and `window_sources` keeps only the evaluated sources, since a raw source is answered by the raw path it always used. Cover it by executing `rate(x[5m]) + y` where `x` arrives raw and `y` arrives evaluated on the statement grid. The test asserts all ten (host, timestamp) rows and fails on the removed refusal if the refusal is restored. Signed-off-by: discord9 <discord9@163.com> * feat(promql): bind a segment to every source its subtree reads `cut_as_segment` accepts any exportable subtree that is not `SinglePartition`, so a matching subtree over two sources - `m / n` - is a legal cut point. `build_inner_segment` then required exactly one source and returned `None` for it, and `segment_tree` propagates that `None` as "the statement keeps the plan it had", so `sum(topk(1, m / n))` fell back to the legacy path even though its cut was legal. Build the segment from every source the subtree reads. Each child gets the `RawSeriesSource` boundary already used for separate metric tables, which carries that source's own metric, tags and fields across the boundary and makes the child placeable; a segment over two tables cannot sit inside either region, so it runs above them. The single-source case keeps its existing direct-scan path unchanged, which is what lets a one-table segment still be pushed into its region. Field names come from `tree_source_fields` on the rewritten tree, whose source indexes are already dense in the order the children are built. That helper also validates a repeated source against its own schema and refuses a non-dense index set, which a second traversal would have to re-derive. It becomes `pub` and is re-exported for the query crate to call. Take the segment's time column from its own first source rather than from the statement's first: a cut whose sources are `[1, 2]` would otherwise name the time column of a table it does not read. Cover the construction with a planner test and with a real-Mito integration test that asserts both the exact values and the route: one segment over the two tables, each child reading its own table through its own raw series source. Without the route assertion a silent fallback would pass on equal values. Signed-off-by: discord9 <discord9@163.com> * feat(promql): run a matching tree at the configured width A matching tree's width came from its inputs: `matching_partitions` took the selected source's count, or the maximum of every input's. In standalone a cross-table statement arrives as one `MergeScanExec` per table with one partition each, so `m / n` matched on a single worker while the scans under it ran in parallel. The engine's `execution.target_partitions` was reachable - `plan_fused_series` already uses it for `series_scan` - but never reached this decision. Add `to_execution_plan_with_parallelism(inputs, target_partitions)`, which resolves a matching tree's width as `target_partitions.max(1)` for both the same-source and the multi-input case. `to_execution_plan` keeps its signature and its input-derived width, so a caller that has no configured parallelism is unchanged. `PartitionLocal` and `SinglePartition` trees do not consult the value at all: a per-series tree runs on whatever partitions it was scanned with, and asking for a router there would only add a shuffle. Forward the value through `FusedSeriesExec` because `with_new_children` rebuilds from the node's own children, which are the ones below the router; rebuilding without it would resolve the width again from the pre-router count and silently fall back to one. Verified on a real standalone: the two-table segment now reports four partitions with a `SeriesRepartitionExec` under each one-partition region scan, where it reported one before, and the rows are identical. Signed-off-by: discord9 <discord9@163.com> * test(promql): declare a keyed test frame's ordering, and order its keys `plan_keyed` built its schema with `datatypes::series::frame::series_frame_schema`, which hardcodes the frame metadata `ORDERING` to `contiguous`. The stream it returns packs what `RawScript::ordering` reports, which is now the key-then-time order this helper models. The node reads the ordering off the *plan* schema, so the two disagreeing meant the router scheduled these fixtures as `Contiguous` while unpacking validated them under the stricter ordered contract. Build the schema through `frame_schema_with` with the ordering the stream actually produces, so the plan and the runtime frames state the same contract. That mismatch was invisible until `RawScript` stopped hardcoding `Contiguous`: with both sides claiming `contiguous`, the ordered validation never ran. Running it showed the matching fixture feeding key `b` before `a` within one partition, which its declared ordering forbids. Reorder the partition; the two pieces of `host="a"` still arrive in different partitions, which is what the test is about. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): declare the key order a two-phase raw scan actually keeps `SeriesScan::raw_ordering` reported `SeriesOrdering::Contiguous` for a `TwoPhase` scan that is not reading columnar artifacts. The data that path produces is ordered by primary key: - candidates are merged and sorted ascending by the encoded primary-key column, then decoded to ids by walking that ordered stream without reordering; - partition assignment is a deterministic TSID-to-partition map that appends in arrival order, so one series never spans two partitions; - each assignment is drained completely before the next is taken, rather than emitted in completion order; - the raw adapter's predicate buffering preserves input order and cannot let a later key overtake a held one, and two-phase records always report `ends_package: false`, so it never engages the package-tail machinery that legacy relies on. Declaring the weaker order costs two things that are available: the frame codec's `SequenceValidator` never ran its increasing-key check, and a repartition owner could not use a key watermark to release an identity before another input ended. It also contradicts the scanner's own documented contract, which states the output is always ordered by (primary key, time index) within a partition. Report the order the path actually keeps, and reword the two ordering errors that said "legacy" now that both modes can reach them. Cover it with a test that forces two-phase mode and the non-prepared fallback, asserts which of the two it ran, and then checks per-partition key monotonicity, per-series timestamp monotonicity, single-partition ownership, and the ordering the scan reports. The fixture writes three rounds, uses two output partitions and a residual predicate, and keeps one series above a batch so the multi-batch path is exercised. The three existing two-phase raw tests asserted the old declaration. They check that a series stays in one run and never recurs non-adjacently, which the stronger order still guarantees; only their expected declaration and their names said "contiguous", so those change and the substantive assertions stay. Signed-off-by: discord9 <discord9@163.com> * fix(promql): route a raw match only by a key the computation keeps `same_source` answers "this subtree reads one source", and a `MatchingLocal` classification was taking that answer as licence to insert the router below the fused computations, hashing the labels as they are at the raw stage. Those are different facts. A math map drops the metric name and the `__type__`/`__unit__` metadata, `timestamp` does the same, and every range function drops them except `last_over_time` and `first_over_time` — so `on(__name__)` over `abs(...)` routes by a key the very next node deletes. Concretely, `abs(x) + on(__name__) abs(y)` with one series on each side routes `x` and `y` to different owners; both become the empty key after `abs`, nothing re-partitions between the map and the match, and the pair is silently lost. Decide preservation separately from source identity. A node keeps the key when it cannot remove one of the labels the key is built from; a `Window` consults `RangeFunction::drops_metric_name` rather than assuming, so the two functions that keep the name still route early. Anything not proven to keep the key — a label rewrite, a histogram map, an unmodelled node — does not establish preservation, and the tree is classified `SinglePartition`. That is not a fallback that trades parallelism for correctness. When the computation removes the labels the key is built from, every series on one side reduces to the same empty key, so every left series matches every right one: the match is whole-vector by construction and has no partitioned form that preserves its result. One partition is the only placement that answers it. Where the key does survive, the match stays partitioned. Signed-off-by: discord9 <discord9@163.com> * fix(query): describe an admitted operand by what it produces `try_plan_native_operand` handed the binary matcher the context saved during scanning, which describes the operand's *input* layout. An admitted call can change that layout: `histogram_quantile` folds a classic histogram and drops `le`, so the scan context still names a tag column the operand no longer produces, and default matching then builds a join key over a column that is not there. Concretely, `histogram_quantile(0.9, m) / histogram_quantile(0.5, m)` declines whole-tree planning (two selectors over one table) and is then admitted operand by operand; each operand drops `le`, and planning fails building the join with `FieldNotFound { field: "le" }` against a schema of `timestamp, field_0, host`. Publish only the tag and field columns that the operand's own plan schema actually contains, and drop `use_tsid`, which the produced output does not carry. The check is against the schema the node returns rather than against a list of functions that happen to shrink it, so a call added later cannot reintroduce the gap by not being on a list. Covered by a classic-histogram fixture with `host` and `le` and a float bucket field, asserting each operand's context reports `["host"]` and that the planned join key omits `le`. Reverting the change fails that test with the `FieldNotFound` above. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the partitioned duplicate-group answer, with the gap named `native_hybrid_binary_05_06_08` asserted that the right side's two `job="other"` series are refused as a duplicate match group. On the partitioned route they are not: the check is gated on `lhs.presence && rhs.presence` computed from the partition's own slices, so the partition holding `other` sees no left-hand data and filters every point out. Pin what the route actually answers, and state the three things that constrain the fix, because each has already been tried and rejected here: - the gate cannot be dropped. `prometheus_cases.txt:1065-1075` is a Prometheus-generated case where the left is absent at one point and the right carries three samples of one group there, and the answer is a value with no error; - the scan cannot run unconditionally, for the same reason; - the match cannot be collapsed to one partition to make both operands whole, because that gives up the parallelism this route exists for. What remains is to let the verdict see whole-operand presence while the partitions keep answering — a deferred check rather than a different placement. This test now makes any change to the current answer visible instead of silent. Signed-off-by: discord9 <discord9@163.com> * feat(query): segment a nested match instead of gathering it A nested one-to-one match — `x + y + z`, or `(x - y) / on(host) z` — passes the logical admission check, because `independent_scan_pair` recurses through `scan_operand`. The physical locality classification does not go that far: it recognizes a match only when both operands read one source each, so `same_source` fails on an operand that is itself a match and the whole tree is classified `SinglePartition`. The fused computation then ran on one partition while the scans under it stayed parallel, which the existing planner does not do: it builds ordinary equijoins that DataFusion can execute as partitioned hash joins. Admission and placement are different questions, so they now get different predicates. The tree is segmented when it is cross-table, not multi-input, classified `SinglePartition`, and its root is a vector match with a nested vector match directly under it. The inner match becomes a segment and the outer one repartitions the evaluated operands by its own key, which is what the segmenter already does for any exportable evaluated prefix; a nested match whose two levels use different keys is routed twice, once per key, rather than pretending one routing serves both. The predicate stays narrow on purpose. Three-selector trees over distinct metric logical ids are `multi_input` and keep their existing construction, including the parent binding that construction produces. A same-table nested match does not enter this branch either, so its prior admission is unchanged. The plan test's collector walks each fused node's native tree in expression-child order and resolves each input's `source_index` against that node's inputs, so a segmented plan is checked for the same property as before — every selector occurrence bound exactly once, in expression order — rather than being checked more weakly. It panics on a shape it does not model instead of returning an empty list. Signed-off-by: discord9 <discord9@163.com> * fix(promql): prove a raw match key survives the computation `preserves_matching_key` decides whether a subtree keeps the labels a vector match routes by. Two arms answered yes without looking at the field that decides it. A binary with a scalar operand recursed into the vector side alone, but arithmetic and a `bool` comparison drop the metric name while a filtering comparison keeps it — the distinction execution already makes. And an `Instant` recursed unconditionally, while `timestamp(x)` compiles to `InstantValue::Timestamp`, which drops the name too; the check written for the separate `Timestamp` node never covered that shape. Both now read the field that decides: the operator together with `return_bool`, and `InstantValue`. The labels checked are the whole computed set — name, type and unit — because `drop_metric_name` removes all three and default matching does not ignore the last two by itself. Without this, `(x * 2) + on(__name__) (y * 2)` was classified matching-local, the router hashed the raw names before the maps dropped them, and a valid pair could land in different partitions with nothing re-partitioning afterwards. The regression asserts the value is 10 and that the tree is `SinglePartition`, computing the destinations the router would have used (`x0` to partition 0, `y0` to partition 1 of two). With the old arm restored the value assertion fails with `left: [10.0], right: []`. Signed-off-by: discord9 <discord9@163.com> * feat(query): find a nested match through the wrappers around it Segmentation was gated on the root itself being a vector match with a nested match beneath it, so `abs(x + y + z)` and `2 * (x + y + z)` never entered: the wrapper or the scalar broadcast sat where the match was expected. Meanwhile the segmenter already walks children and leaves a wrapper in the parent while cutting what it can carry, so no per-wrapper case is needed — the search just has to look through them. Replacing the root check with `carries_prefix` was too wide: almost any multi-source tree contains something a boundary could carry, so ordinary shapes like `some_metric unless on(tag_0) other_metric` were cut for no gain and their inputs stopped being raw sources. So keep requiring a nested vector match, and search for it anywhere in the tree rather than at the root. Wrappers and scalar broadcasts are transparent because the walk visits every child; the nested match itself is still required, which is what keeps the plain multi-source shapes on the plan they had. `cross_table`, `!multi_input` and the `SinglePartition` locality requirement stay, as before: they are what keeps distinct metric logical ids and the same-table shapes out of this branch. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): let a router publish an identity whose chain is complete `SeriesRepartitionExec` published an identity only once every input had contributed it or ended, because an identity may be split across inputs. A per-series region scan assigns each identity to one partition, so on that shape the rule holds every identity until the other partitions reach EOF: a region's whole raw selection is retained before the first series leaves. The node now carries an `IdentityCompletion`, defaulting to the existing merge. `CompleteDisjoint` publishes an identity as soon as its chain closes and keeps the published identities charged in the pool, so a second chain for the same identity fails the execution instead of emitting a partial series as final. The declaration is the producer's, not something a consumer infers from a node's type: publishing early against a producer that does not own its identities would be wrong, so the conservative mode stays the default and every existing constructor keeps it. Signed-off-by: discord9 <discord9@163.com> * fix(query): choose a series-frame root's router from declared provenance `SeriesFrameOutput` normalized every multi-partition frame root through a router that merges identities, which is wrong for a root whose identities are already disjoint: it waits for every scan partition to end before the first series leaves. The rule now selects `CompleteDisjoint` only for a root whose producer declared that property. A raw root qualifies when `RawSeriesSourceExec` was built through `to_per_series_execution_plan` - which also checks the child is a `SeriesScanExec`, so the type alone is not taken as proof - and a direct `SeriesRepartitionExec` root qualifies because it merged the identities itself. Everything else, including a fused frame root, keeps the merging router: a native label transformation can map two source series onto one output label set, so its output identities are not exclusive. The rejection of a key-only raw frame is unchanged and its reason is restated: coalescing cannot produce such a frame, and a router needs explicit labels to check that one key has one binding. Signed-off-by: discord9 <discord9@163.com> * fix(promql): report the labels `absent` names, not the table's columns `fused_output_tags` answered `None` for `absent`, so the caller fell back to the existing planner's column names. Those are the table's tag columns, which is not what `absent` reports: `absent(m{host="x"})` carries the labels its matchers name, and the compiled tree already knows them in `BoundVectorOp::Absent { labels }`. The label set is now read from that field: the named labels are kept in the input's column order, so `absent(native_shapes{host="missing"})` over a table with `host` and `le` reports `host` rather than `ts, val, host, le`. A label the matchers name that is not an input column still answers `None`, because a frame has no column to carry it; `count_values` and `histogram` are unchanged. Caught by the native-versus-legacy value comparison: the extra column made `absent` differ from the existing plan while every value matched. Signed-off-by: discord9 <discord9@163.com> * fix(promql): describe a frame root's emission from what it does `FusedSeriesExec` declared `EmissionType::Final` for a frame output, but `poll_output` hands a frame's evaluated chunk over while its input is still arriving, so the declaration overstated the node to the optimizer. Only a partial aggregate's state is emitted after EOF; every other output keeps its input's emission type. Signed-off-by: discord9 <discord9@163.com> * test(promql): compare the shapes the native route now admits with the existing plan Removing the shapes a name list used to refuse put single-selector `sort` and `sort_desc`, `absent`, and a bare `histogram_quantile` on the segmented route. Nothing compared their answers with the existing plan, so the widening was unverified. The new case runs each shape both ways over one metric table. `sort`, `sort_desc` and both `absent` cases compare the whole printed result, which covers column names and values together. `histogram_quantile` compares values row by row and asserts the one known difference instead of hiding it: a segmented statement names its value column from the compiled tree (`val`) where the existing plan names it after the expression that produced it. That case is given a window long enough to produce a row, so it cannot pass by comparing two empty results. The `absent` cases caught a real difference: the native route reported the table's tag columns rather than the labels the matchers name, which is fixed in the preceding commit. Signed-off-by: discord9 <discord9@163.com> * fix(query): publish a fused root's identities early when the tree keeps them The root rule publishes an identity as soon as its chain closes only for a root whose producer declared that each identity lives in one partition, and it knew two such producers: a per-series raw scan, and a router that had already merged its identities. A fused root was always treated as needing a merge, so a region whose segment is a plain instant selection over one per-series scan still held every identity until the other scan partitions reached EOF - `sum(topk(1, m))` is that shape, and its segment is already multi-partition with no label rewrite. `FusedSeriesExec` now answers whether its output identities are disjoint, and the rule asks it. The answer is narrow on purpose: one input, and a tree of nothing but inputs and sample instant selections, over a per-series scan or another fused node that already answered yes. Anything that computes labels is excluded, because a timestamp or a pointwise map can map two source series onto one output identity, and publishing early would then hand over one identity's pieces as if they were different ones. A vector-to-vector binary reads across series and is excluded too. Signed-off-by: discord9 <discord9@163.com> * fix(query): segment a computed matching key's operands instead of gathering them A vector match whose operands compute away one of the matched labels was classified `SinglePartition` and executed on one partition. That is correct for the bare tree - the raw names cannot route a match whose operands drop them - but it also gave up the parallelism the operands still have: `(x * 2) + on(__name__, host) (y * 2)` loses `__name__` and keeps `host`, so the computed sides can be routed by what they actually carry. The planner now cuts those operands into segments of their own and lets the parent route their evaluated outputs by the unchanged match key. The key itself is not rewritten: `group_key` reads the labels present at that point, so `On(__name__, host)` degrades to the `host` a computed operand still has. Which shapes take this route is decided by one predicate shared with `input_locality`, so the admission rule cannot drift from the locality judgement: a matching site whose two operands are each proven single-source computations, at least one of which does not preserve the key. A failed preservation proof on its own is not enough - it can also mean the proof gave up, as with a parameter that is a compound expression or an operand that is itself a vector match - and the shared doc says so. The same table read twice is admitted for this shape only. The rule that declines several selectors on one table exists to keep folds such as `sum(m) / m` off this route, not because one table cannot be read twice; the compiler already gives each occurrence its own source index, and each cut gets its own input. Distinct partitions are what the two operands need, and they get them. The regression executes both the same-table and the cross-table shape over a four-host fixture and asserts that at least two output partitions produce rows, so the result is not silently produced by one of them. Signed-off-by: discord9 <discord9@163.com> * fix(query): take the early-publication guarantee from the scan's binding The root rule publishes an identity as soon as its chain closes only when the producer can promise that each identity lives in one partition, and the fused answer to that question asked whether its input was a `SeriesScanExec`. The node's type is not that promise: a scan binds a set of logical tags and decodes those into the series' labels, and `try_to_named_series_scan` requires the caller to pass complete tag names but does not check it. A binding that names only some primary-key columns maps two stored series onto one output identity, and early publication would hand one identity's pieces over as different ones. The answer now reads the binding: the label source has to be `PrimaryKey`, and every primary-key column has to be among the bound tags. A source that carries its labels explicitly is not this shape and answers no, as before. Covered by a new `bound_tags_cover_primary_key` unit test - partial coverage is false, full coverage is true, an explicit source is false - and by tests for the predicate's two other parts: a tree that computes labels and a tree that is not one instant selection over one input both answer no, and a gated execution shows a completed identity leaving a fused node while the other input is still held. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): drop the checks the types and decoders already guarantee Two re-checks ran inside the repartition node over facts its inputs had already established, and both cost real work on every query. A raw merge scanned each chunk's timestamps for strict increase, but `RawTimestamps` cannot hold an unordered buffer: its field is private, its only constructor validates, and the accessors are read-only or order-preserving, so no safe caller can build the value this check defends against. The check is gone; the identity, label and shape checks around it stay, because those compare different producers' pieces rather than one chunk's own timestamps. An owner rebuilt each chunk's identity to prove a chain does not change it, but the decoder that hands the chain over already refuses that: `SequenceValidator` holds one open key and rejects a key or metric change before the chain closes, `EvaluatedSequenceValidator` does the same for labels, and the input task that assembles chains only reads from those decoders. What stays is the identity the owner needs anyway to pick a destination, now built by the named functions rather than inline. Where a schema was needed, the node built an empty stream of its own, wrapped it in a packer and read the packer's schema back. The frame module already answers that question from the declaration, so the fake stream is deleted along with its half of the roundtrip. Signed-off-by: discord9 <discord9@163.com> * fix(promql): recursively segment native matching plans Signed-off-by: discord9 <discord9@163.com> * fix(promql): derive native schemas without legacy probes Signed-off-by: discord9 <discord9@163.com> * fix(promql): recognize complete metric scan identities Signed-off-by: discord9 <discord9@163.com> (cherry picked from commit 8f752a02dbb9dc7858618c1d5cc0c41e2d4efb23) * fix(promql): release completed disjoint identity history Signed-off-by: discord9 <discord9@163.com> (cherry picked from commit 9975fa6c5c68786e18af230f62041d2aa5e71f6c) * test(promql): assert native aggregate schemas independently Signed-off-by: discord9 <discord9@163.com> * fix(promql): identify internal metric keys by reserved id Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep parallel sources and derive group match labels Signed-off-by: discord9 <discord9@163.com> * test(promql): observe the frontend fused root in scan-parallelism checks Signed-off-by: discord9 <discord9@163.com> * fix(promql): release duplicate evidence immediately on abort Signed-off-by: discord9 <discord9@163.com> * test(promql): preserve operand identity across matching repartition Signed-off-by: discord9 <discord9@163.com> * fix(promql): charge the final duplicate verdict until it is reported Signed-off-by: discord9 <discord9@163.com> * test(promql): observe native scans across frontend and region plans Signed-off-by: discord9 <discord9@163.com> * chore(promql): drop dead test helper and clippy lints Signed-off-by: discord9 <discord9@163.com> * fix(promql): select limitk by canonical label order Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep data-free subtrees in the parent segment Signed-off-by: discord9 <discord9@163.com> * test(promql): prove the duplicate error crosses matching partitions Signed-off-by: discord9 <discord9@163.com> * test(promql): drop debug prints from the segmentation test Signed-off-by: discord9 <discord9@163.com> * revert(promql): keep limitk's Prometheus input-order semantics Signed-off-by: discord9 <discord9@163.com> * feat(promql): admit label rewrites on the native route The native route declined label_replace and label_join outright, because the runtime refuses two series that a rewrite gives one canonical label set where the existing plan answered them. That refusal is what Prometheus does, so the existing answer was the wrong one, and on the current parent the refusal already reaches a rewrite that folds series together: the collapse errors at the root, under sum and under topk. Admit both functions: only the first argument is a vector expression and contributes selectors, and each function's arity is checked before its selectors are collected. Signed-off-by: discord9 <discord9@163.com> * feat(promql): derive canonical ownership and insert the merge consumers need Stacked on the frame-segment route so the ownership this pass proves is the ownership the physical plan actually gives it: a merge is inserted only where its input is co-located by canonical key, which the routing boundary establishes. The pass answers one series per canonical label set at the consumers that read series whole, and leaves the point-wise, kernel-filed and aggregate paths alone - their own duplicate checks already refuse two values of one field at one point. (cherry picked from commitd0bbfc6893) Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the label rewrite shapes the native route now admits The rewrite test still asserted that every label_replace and label_join keeps the existing plan, which was the admission this branch removed. Assert what the route does now: the shape is admitted, its rewritten label is declared, and the plan differs from the one built with the flag off. Signed-off-by: discord9 <discord9@163.com> * refactor(prom… * perf(promql): resolve a partial fold's labels once per group (#10145) `PartialFold::encode` writes one row per (point, field) of a group, and it looked every output tag up with `SeriesLabels::get` for each of those rows. That lookup binary-searches the group's tags, so the loop paid `rows * tags * log(tags)` string comparisons for a value that cannot change inside a group. Resolve the tags once per group and push the resolved values. Measured with `perf` on a `step=1s` range query over 28.8M grid points (the native PromQL path). Before the change `SeriesLabels::get` held 12.8% of samples (self) and `__memcmp_avx2_movbe` 14.5% (self); both frames are gone from the profile after it, and the remaining native-side hot spots are the sample iterators, `select_instants`, `seen_points` and `push_samples`. Wall clock on that query moved from 6.8s to 6.1s, from a single paired run rather than a repeated measurement. Behavior is unchanged: the same tag values are pushed in the same order. `cargo nextest run -p promql` passes 1115/1115, including `aggregate::tests::partials_merge_to_the_serial_result`. Signed-off-by: discord9 <discord9@163.com> * perf(promql): walk a batch's window ends instead of searching each one (#10113) * perf(promql): walk a batch's window ends instead of searching each one A range function's windows advance with the grid, so the samples one window covers are a prefix of the next window's: the end only moves forward. The batch path nevertheless binary-searched the retained timestamps once per point, per field, to find where each window ends. On a profile of `rate(...[1m]) / rate(...[1m])` over 1801 grid points, that search was the largest single flat entry: `accumulate` accounted for 5.39% of sampled CPU and `-peek` showed all of it inside `partition_point` -> `binary_search_by`. A batch now carries one cursor per field, reset when the batch is cleared, and `accumulate` advances it while the timestamp is at or before the evaluation timestamp. The predicate is the same and the array is ordered, so the span is identical; the cost drops from O(points x log samples) to O(samples). On that query each batch went from ~16,800 comparisons per series to ~216. `clear_points` resets the cursors because `FieldSamples::advance` drains the retained arrays, which the existing debug assertion already requires to happen only after the batch is flushed. The cursors are charged in `bytes()` with the rest of the batch. Measured with the server's own CPU time (utime+stime from /proc), alternating run order over 11 paired rounds on the same fixture: the bare-rate query, where the evaluator is a large share of the work, used 1.10-1.12x less CPU (8 of 11 rounds faster); the rate-over-aggregate query, where the aggregate split dilutes it, 1.02x. No wall-clock claim: the host ran at a load average above its core count and wall time swung 20-47% between rounds. Correctness: `cargo nextest run -p promql` 1099/1099, including the brute-force evaluator reference and the random-input batch-versus-per-window comparison. The HTTP responses of both queries hash identically before and after the change. Signed-off-by: discord9 <discord9@163.com> * perf(promql): keep the window cursor across batch flushes The cursor added in the previous commit was reset on every batch flush, but a flush does not drain the retained arrays: `FieldSamples::advance` does, once at the end of `evaluate`. So after each 512-point batch the cursor restarted at index 0 while `head` sat mid-array, and the next batch rescanned the samples already behind every remaining window. Measured in timestamp comparisons for 100,000 points at ~6 samples per window: the pre-optimisation binary search cost 1,536,267, resetting on every flush cost 9,985,289, and keeping the cursor costs 200,005. A single point over a 100,000-sample window costs 18 comparisons, so a large window is still located by search rather than walked, and 600 points across one flush boundary cost 1,216. The cursor is now an index into the retained arrays, valid across flushes and invalidated only where they are drained: `evaluate` resets it next to `advance`, and only when a field actually drained. Before use it is clamped to `field.head`, so samples behind the window are never revisited. A `positioned` flag marks a cursor that has no valid index yet, and the first point after a reset locates the end with `partition_point`; the rest of the batch walks forward from there. The comparison counts are pinned by a test, and it was checked against both broken shapes: resetting in `clear_points` fails it at 203,125 (the binary search still saves it), and the pre-fix shape of resetting plus walking from zero fails it at 9,985,289. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): execute split native aggregates as partial state over a state router (#10147) * feat(datatypes): add the shared aggregate-state representation A frame that carries partial aggregate state has to say which aggregate it is state of and which accumulator components it carries, or a consumer can read a sum state as an average one. These types are that statement: the kind, the ordered component list, one position's values, and the schema that validates the two against each other. Nothing uses them yet; the frame content that carries them follows. Signed-off-by: discord9 <discord9@163.com> * feat(datatypes): carry aggregate state as a third frame content A state frame keeps the series-major columns a frame already has — the key, finality, grid spans and labels — and puts each aggregate field's accumulators in one list of component structs under `fields`, the shape a classic histogram payload already uses. An absent list item is that field having no contribution at that position, so a hole stays a hole instead of becoming a zero, and a group state — which carries no component at all — still says per field where it was folded. The reader keeps typed handles into the batch rather than expanding the state into rows and rebuilding it, so the merge above it reads the arrays where they lie. Signed-off-by: discord9 <discord9@163.com> * feat(common-query): pack and unpack aggregate-state series frames The packer takes what a partial aggregate produces — one group, its carried positions and its per-field state — and the unpacker hands back the row with typed handles into the batch. That asymmetry is deliberate: export columnarises once, import must not rebuild the state to read it. Validation mirrors the evaluated pair: the declaration is parsed, contiguity required, the empty batch decoded before the stream is returned, and kind, component order, grid and field count are each checked with the part that disagreed named. Signed-off-by: discord9 <discord9@163.com> * feat(promql): run native partial and final aggregates An aggregate node used to compute only `Complete`, refusing the stages a split aggregate needs. It now folds evaluated chunks into kernel state for `Partial` and merges that state into values for `Final`, so the compiler's `Partial -> Final` plan has a runtime behind it. The executor gains a third chunk kind: an input leaf accepts raw, evaluated or state chunks according to what its binding produces, never guessing from a schema, and a state chunk cannot be handed to a node that reads values. The state binding now carries the aggregate kind and its ordered components, derived from the kernel's own state fields, so a sum state cannot be merged as an average one. The sibling router refuses aggregate state explicitly for now; the node that routes it follows in its own change. Signed-off-by: discord9 <discord9@163.com> * feat(promql): route aggregate state by its group labels A state row is one group, complete as one producer wrote it: there is nothing to chain and nothing to merge, so the existing repartition node — whose invariants are all about assembling a key's chain and waiting for every input to close — is the wrong place for it. This node does one thing: send each row to the output its canonical labels name, so every contribution of a group reaches one owner and the merge above sees all of them. The read belongs to the outputs that were claimed, not to the plan, so dropping every output stops it and returns what it reserved. Signed-off-by: discord9 <discord9@163.com> * feat(promql): execute partial aggregates as state frames A fused node now reads its inputs by what they produce — raw samples, evaluated values, or aggregate state — instead of inferring the kind from a schema, and a partial root answers state rather than rows: the executor's state chunks are packed into the aggregate-state frame the merge above consumes. The temporary partial-fold bridge goes with it: no marker field, no side channel fold, no compatibility accessor. A tree that folds on the side is exactly what this change exists to remove, and the aggregate merge that replaces it is a separate node. The state path derives its mode and its binding from one reading of the root, so the two cannot disagree, and no production path panics on a malformed tree. Signed-off-by: discord9 <discord9@163.com> * feat(promql): split native aggregates into partial and final trees The previous commit made a `Partial` aggregate export its state, but left `AggregateFinalize` in place: it still called `FusedSeries::try_new_partial` and `partial_fold`, which that commit deleted, so the crate did not compile. Replace the bridge with the two trees that run a split aggregate: - `native/split.rs` owns the cut. It moves out of `aggregate_finalize.rs` unchanged in structure, and `Split::into_trees` binds the two halves: the prefix under a `Partial` aggregate answering aggregate state, and a `Final` aggregate consuming that state with the suffix above it. - The suffix is narrower than the old merge admitted. Only point-wise maps and a binary operation with a constant side may sit above the cut; `topk`, the classic-histogram functions, a second aggregate and a vector matching are declined, because the groups a `Final` aggregate owns are split across partitions and each of those reads a whole vector. - `FusedSeries` gains `try_new_state_export` (a `Partial` node declares its own state frame schema rather than taking a caller's), `split_aggregate` (declining shapes become `None`, not an error), `reads_aggregate_state` and the state-input path of `to_execution_plan_with_parallelism_option`, which routes state through `StateRepartitionExec` and lets a cross-series tree read state from more than one partition. - The runtime executes the `Final` stage: the guard that refused it is gone. `AggregateFinalize`, `aggregate_exchange` and their tests are deleted; nothing in the crate referenced the exchange module. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): route aggregate state through the series repartitioner Replace the dedicated state-repartition node with the existing series repartition execution: state batches are routed by their canonical labels without being rebuilt as StateSeries, and each row slice is charged for the Arrow wrappers it newly allocates while the parent buffers stay charged once. Carry a producer's state charge with the chunk it hands over, so the exporter that packs rows across polls remains accountable for the batch it still holds instead of releasing it at handoff. Read a Final aggregate's value and tag columns positionally, which is the order the split's output schema is built in, and name them through the legacy expression only at the outer boundary; a bare sum over a metric whose value column is named after the whole expression no longer fails planning. Pack aggregate-state frames in one pass over positions and validity instead of scanning the contributing rows for every position. Cover the changed behaviour with execution tests for bare global and grouped sums over one- and two-value-field tables, for the handed-over state charge, and for the export lifecycle on drain and early drop. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bound tree depth on both sides and validate merge inputs The depth limit was decode-only and set to a number nobody had measured. A 129-deep tree could therefore be built, serialized and shipped, while the receiver refused it; and in CI the boundary test itself aborted with a stack overflow, because a 2 MiB thread was asked to build, serialize, decode and drop a chain of that depth, and the recursive drop of `Box<NativeNode>` is not covered by a guard that only wraps `Deserialize`. Measured instead of guessed. A probe walked build, serialize, decode, validate and drop at increasing depth inside a named 2 MiB thread: 32 through 128 completed, 160 aborted. The cap is now 64, half the highest passing depth, and the same number is enforced in `NativeTree::try_new` and in the deserializer. Verified through the real constructor: a 64-node tree round-trips, and a 65-node tree is refused when it is built as well as when it is decoded, so sender and receiver accept the same set. The boundary test runs on a named thread, which is how a future failure will identify itself. The merge node accepted any single input. `with_exprs_and_inputs` rebuilt `AggregateFinalize` over whatever it was handed, on the reasoning that a rewritten input only changes where the state comes from. Nothing checked that it was state at all -- and until now nothing could produce a counterexample, because a values-producing producer could not be serialized. The serializer was standing in for a validation that belonged to the node. `with_exprs_and_inputs` now rejects an input whose schema is not `state_schema(binding.tags)`, so substituting a computed-values producer fails at the logical node with a message naming the expected schema, rather than depending on an encoding limitation. `AggregateFinalizeExec` already had the same check at physical planning; the serializer stays permissive. The three placement tests in `commutativity.rs` asserted the old refusal as their mechanism -- an ordinary fused node "fails to encode", a partial producer "cannot be pushed down". Those expectations were the encoding limitation wearing a test's clothes. They now assert the responsibilities that remain: an ordinary fused node round-trips through the encoder, a partial producer rides to the region while its finalize stays on the frontend, and a values producer handed to a merge is refused by the schema contract. The test-only `NPRQ` envelope is gone. It framed trees with its own version, a 1 MiB cap and its own rejections, none of which production had, so `native_tree_envelope_rejects_version_size_trailing_and_truncation` was proving a helper's protocol while the PR description claimed a production guarantee. Trees are tested through plain postcard, transport through the real `FusedSeries` interface. The redundant clone-and-revalidate in `FusedSeries::deserialize` is also gone: `NativeTree::Deserialize` already routes through `try_new`. Signed-off-by: discord9 <discord9@163.com> * style: let taplo order the workspace dependency entry `taplo format --check` runs over the whole workspace in CI, not over the two manifests I had checked. It sorts the `[workspace.dependencies]` table, so `postcard` belongs in alphabetical position inside the external-dependencies block rather than immediately after its comment. Local checking was narrower than the CI command, which is why this only surfaced there. Signed-off-by: discord9 <discord9@163.com> * style: place postcard in the sorted position the review asked for Inside the external-dependencies block, `taplo` was willing to leave the entry before the `axum` comment, because a comment line ends a reorder group. The review asked for the alphabetical position, which `taplo format --check` also accepts, so use it. Signed-off-by: discord9 <discord9@163.com> * docs(promql): name the real reason a multi-source name grouping declines The comments still said the fused node's declared columns cannot name `__name__`. Since #10106 a discovered source declares it, so a nameless selector's `sum by (__name__)` survives; what actually declines is a tree reading more than one *named* source, where the table name is the metric name and no source declares the tag. Same conditions, accurate reason. Signed-off-by: discord9 <discord9@163.com> * test(promql): find the topk producer by behaviour, not by node count `native_aggregate_topk_over_global_partitions` asserted that the whole plan holds exactly one fused node. Once native frames cross the region boundary a plan legitimately holds the frontend root and the region producers at the same time, so that count is no longer an invariant. The test now selects the segmented producer and the ranking node by what their plans do: at least one producer contains `segment` and none of them runs `topk`, and exactly one node across the fused and final captures ranks. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(mito2): release metadata cache locks before asynchronous loads (#10125) * fix(mito2): avoid holding metadata cache locks across loads Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): atomically admit loaded columnar metadata Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): verify concurrent loaders share admitted metadata Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * test(compat): exercise the bloom-token case only below v1.3.0 (#10170) `fulltext_bloom_tokens` reads a fulltext bloom SST in the first format and asserts that rows written by the older binary stay visible next to a current one. Its `from_range` started at v1.0.0, but the released v1.3.0 binary already writes `bloom_version: 2`, so the setup produces two current-format SSTs and the expectation ("one old, one new") can never hold: expected: | false | 1 | actual: | true | 2 | expected: | true | 1 | Narrow the range to the releases that still write the first format. The constraint language has `>=`, `<=`, `==` and `=` only, and several entries are alternatives rather than a conjunction, so `<=v1.2.99` is the bound that excludes v1.3.0 while keeping v1.2.x and older - including the nightly window. Verified with the compat runner: `--from-version v1.2.1 --dry-run` selects the case, `--from-version v1.3.0 --dry-run` skips it with `from_range ["<=v1.2.99"] does not match version 'v1.3.0'`, and `update-compat-versions.py --check --published-only --check-anchors` passes. Signed-off-by: discord9 <discord9@163.com> * perf(mito2): buffer sample artifact writes across blocks (#10105) * perf(mito2): buffer sample artifact writes across blocks Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): use telemetry for sample writer benchmark output Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): merge columnar samples using identity-only keys (#10126) * perf(mito2): merge columnar samples with identity-only keys Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): instrument columnar sample read stages Signed-off-by: evenyag <realevenyag@gmail.com> * refactor(mito2): clarify reader timing and focus merge regression coverage Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): cover first-field null recovery in identity merge Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): encode fallback candidate keys from borrowed labels (#10133) perf(mito2): encode candidate keys from borrowed labels Signed-off-by: evenyag <realevenyag@gmail.com> * feat(promql): query native histograms through the native PromQL route Admission reads the field's kind, the output column is typed by what the compiled tree answers, the reader follows the field kind, and the response writes the canonical histogram column. PromQL warnings reach the native kernels. Tracks #8887. * fix(promql): answer a nameless selector that matches no metric with the empty vector (#10159) fix(promql): answer a nameless selector with no metric by the empty vector A nameless selector that matches no metric table returned nothing to the native route, which fell back to the existing planner; there the missing metric name surfaced as a `TableNameNotFound` error instead of the empty result Prometheus returns. Plan a typed empty input instead: an empty relation whose schema is the raw explicit-label series frame a scan would declare, with one field and no evaluation grid. Declaring the frame is what tells the physical planner this is a producer, so no region scan is looked for below it, and every operator above keeps its own answer for zero series - an ungrouped fold reports no group rather than 0, `absent` still derives its labels from the matchers, and `or` keeps the vector operand's own row. Two shapes keep the old fallback deliberately: a statement holding a second selector occurrence (a real scan's partition count and the empty frame's one cannot share the node's partition contract) and a `__field__` matcher (a field projection, not ordinary label filtering). Authorization that is unavailable still fails closed, and the metric cap still errors, both before this branch is reached. The discovery route had no value-level test: every existing one asserts a schema or a source name. Add one that runs the Prometheus handler against two metric tables with identical ordinary labels, so only `__name__` tells them apart, and asserts each row's name and sample; disabling the `__name__` tag injection leaves the values and empties the names. Signed-off-by: discord9 <discord9@163.com> * fix(promql): carry each row's metric name through to the response (#10162) A PromQL response could carry only one metric name for the whole result, derived from the statement. That is wrong whenever the rows of one result come from different metrics: a set operator reports the series of both its operands, so `left_metric or right_metric` returned the right-hand series under the left metric's name, with their own labels and samples intact. Carry the name as a column and declare what that column is: the column metadata key `greptime:metric_name`, the same place `greptime:time_index` declares a column's role. A consumer reads the declaration, not the column name, so a label an operation generates may itself be called `__name__` without being mistaken for one. The native planner adds `__name__` to the output tags of `or` -- the only set operator whose output mixes both operands -- and marks that column. Every other shape that keeps a per-row name already carries it the same way, since a native `__name__` tag always reads the series' own metric-name slot; arithmetic and aggregates drop it, as Prometheus does. The response layer reads the declared column per row instead of prepending the statement's name, keeps it out of the ordinary label set, and treats an empty value as no name, since Prometheus drops empty label values. A result with no declared column behaves exactly as before. Scope: the native route only. The legacy planner carries no per-row name and keeps naming rows from the statement, so its set-operator results are unchanged here. Signed-off-by: discord9 <discord9@163.com> * feat(query): execute native raw promql over real datanodes (#10150) * feat(promql): serialize raw series source bindings through Substrait Signed-off-by: discord9 <discord9@163.com> * feat(query): transport interleaved raw series fragments Signed-off-by: discord9 <discord9@163.com> * feat(promql): reconstruct interleaved raw series at repartition Signed-off-by: discord9 <discord9@163.com> * feat(query): plan distributed native raw series Signed-off-by: discord9 <discord9@163.com> * chore: satisfy clippy for the raw series transport The workspace clippy run rejects a redundant rebinding, a constant-size `chunks_exact`, and an implicit `String` clone in the tests these commits carry. No behavior changes. Signed-off-by: discord9 <discord9@163.com> * feat(query): execute native raw promql over real datanodes Plan a whole native statement as one fused node over raw series sources when the frontend reaches regions over the wire, including single-selector statements, while keeping the in-process split and segment shapes unchanged. Validate the whole tree with the runtime constructor before committing to that plan, so unsupported shapes still fall back to the legacy route. Bound the region reads of that topology with a query-wide permit budget of target_partitions, held until each region body is drained; other plan shapes keep unbounded reads rather than risk a body budget they could deadlock. Acceptance on a real two-datanode cluster with TCP frontend clients: time-partitioned series are reconciled before the fused node and match the unpartitioned control, with the DoGet peak at the target bound; series that no region shares keep contiguous per-series order and reach the fused node without a reconciling router. Signed-off-by: discord9 <discord9@163.com> * chore(deps): pin greptime-proto to the raw series transport PR The raw series Substrait message lives in greptime-proto PR #349, which is not merged, so pin its head commit instead of carrying a local path patch. Move the rev to the merge commit once #349 lands. https://github.com/GreptimeTeam/greptime-proto/pull/349 Signed-off-by: discord9 <discord9@163.com> * fix(promql): reconcile a discovered union of raw series A nameless selector reads its matches as one `Union`, and `UnionExec` reports the frame metadata of its last child. A time-partitioned metric sorted before a host-partitioned one therefore looked contiguous, and the fused node skipped the reconciliation of the fragmented member's series, silently folding region fragments as separate series. Lower the declaration on the fused edge to the weakest ordering any member declares, before the fused node reads it. The union itself is unchanged; the fused node's existing interleaved-input path inserts the router. A projection carries the lowered declaration because the pinned physical planner ignores a union's own schema. Cover it with a planner regression for both member orders and an all-complete control, and with a real two-datanode acceptance case that mixes a time-partitioned and a host-partitioned metric and checks the extrapolated increase per series. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover aggregates over discovered metrics A nameless selector's metric comes from its own frames, so a folding aggregate is a multi-input tree even with one selector: apply the same preflight and order-dependent refusals on the remote route. Cover `sum(increase(...))` and grouping by the metric name over the mixed discovery fixture. A grouping that names only `__name__` stays declined, since the output schema cannot name that group: here the metrics also differ by `site`, so grouping by the name and `site` exercises the two groups. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep remote multi-source refusals the split made Skipping the aggregate split and `segment_tree` over the wire must not drop their admission refusals. Two sources that fold groups by metric name would report groups that differ only by name under one label set, and an order-dependent operation over a discovered selector's union would answer in arrival order. Scope both refusals to the actual multi-source inputs rather than to the logical-table-id heuristic: a discovered selector reads several metrics through one selector, and a Mito table beside a metric one carries no logical id. Cover the Mito-plus-metric grouping refusal on a real two-datanode cluster, and cover a discovered `sum by (__name__)` over a raw selector (the name survives it) and a folding `sum(increase(...))`. Signed-off-by: discord9 <discord9@163.com> * docs: drop the local proto patch prerequisite The dependency is pinned to greptime-proto PR #349's commit, so the wire fixture no longer needs a local path patch. Signed-off-by: discord9 <discord9@163.com> * chore: finish the narthex rebase resolution Keep the upstream aggregate split (`FusedSeries::split_aggregate`) and pass the engine state through the native planner's callers, while the remote route still declines the split it cannot carry. Signed-off-by: discord9 <discord9@163.com> * test: pass the engine state to the native operand test The native operand planner now takes the engine state, which decides whether a statement is planned for remote regions. Keep the histogram operand contract test on that signature. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep the split and segment plans over the wire Remote planning disabled the aggregate split and segmentation because the split's producer read a bare scan. The producer reads whatever the statement prepared, and over the wire that is the raw series source: the partial half runs per partition on the frontend, the final half folds the exported states, and no aggregate state crosses the wire. Keep the split and let segmentation build evaluated segments from the raw sources instead of bare scans, so per-series window work keeps the scan width. Admit the resulting fused chain to the query-wide read budget, since each fused node polls its input while it is drained. Remove the recovery-projection wrapper: the analyzer no longer inserts that projection, and the physical planner consumes the frame boundary as it is. Serialization is now only the node's encoding: the codec no longer decides placement, and the metric-name binding is checked against the declared frames rather than the node types below. Signed-off-by: discord9 <discord9@163.com> * refactor(query): drop the in-process encodability exception A split aggregate encodes now, so the analyzer no longer needs a special case that skipped the encoding gate for it. The gate itself stays: every plan a region receives still has to encode. Signed-off-by: discord9 <discord9@163.com> * test: cover a repeated selector over one partitioned table Two occurrences of one time-partitioned metric keep their own raw source, time bounds and identity over the wire, so a ratio of two windows and a binary expression over two identical ones stay native and reconcile each occurrence's fragments before the fused node reads them. Compare both against the unpartitioned control. Signed-off-by: discord9 <discord9@163.com> * fix(table): refuse a scan that plans interleaved ordering A scan's planned ordering is a guarantee its own partitions keep. Interleaved is the transport annotation for fragments several producers contribute, so a scanner that planned it has no raw-series read whose frame would honour that declaration. Reject it in the scan conversion, while the frame codec keeps accepting interleaved raw frames from the router that reconciles them. Signed-off-by: discord9 <discord9@163.com> * test(promql): assert the metric name beside the value `sum by (__name__)` over a discovered selector was asserted as a bare sorted list of values, so a plan that grouped by the wrong metric name - or dropped the name and folded everything into one series - could produce those same numbers. Read `__name__` and `val` by column name (the result puts `__name__` last, and a fold that drops the name drops the column rather than emptying it) and compare the `(name, value)` pairs against the fixture's own metric names. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep the hybrid route for a partitioned pair A multi-selector tree over a partitioned table was admitted as one fused node for any pair of tables, not only for scans of one table. That preempted the frontend hybrid route, which copies the matcher's labels into each operand's scan and checks uniqueness above the join. `native_hybrid_binary_05_06_08` depends on exactly that plan: its partitioned RHS holds a duplicated `job="other"` group, so the whole-native binary reports the duplicate instead of the value the hybrid route returns. Refuse the whole-fused plan for that shape in process again; the remote raw-source admission is unchanged, since a remote multi-selector tree over a partitioned table is the point of this branch and the distributed acceptance tests read it. The hybrid route then has to behave the same way it does without native operands: `matching_filters::propagate` now runs for them too, and a rewritten operand is re-planned through `try_plan_native_operand` with its original `selector_matcher` preserved, falling back to the ordinary plan when the native route declines. The unpartitioned case, whose duplicate group the whole-native binary is expected to report, is unchanged. The two new re-plan call sites put the native route's large future inside the recursive planner frame at every nesting level (~178 KB became ~209 KB), which overflowed the 2 MiB test-thread stack in `test_parse_or_operator` even where the new branch never ran. Box the future in a non-async helper and move the re-plan into `replan_rewritten_operand`, which brings the frame back to the old size without changing the behaviour. The partitioned-pair unit test asserted the removed shape. It now asks for the remote engine state, where a cross-table pair really is one fused node over two raw sources, and asserts that the same pair in process keeps the hybrid route. Signed-off-by: discord9 <discord9@163.com> * chore(deps): pin greptime-proto to the merged raw series transport GreptimeTeam/greptime-proto#349 has been merged into `narthex-proto` as `f51cb5312bf7`. Move the rev from that PR's head commit to its merge commit, in `Cargo.toml` and `Cargo.lock` together, so the pin no longer points at an unmerged ref. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * test(query): cover series-frame completion policy selection (#10151) * test(query): pin the completion-policy choice for each eligible root Signed-off-by: discord9 <discord9@163.com> * test(query): pin fused roots without disjoint identities Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * perf(promql): keep the grid position in i64 instead of dividing in i128 (#10175) `grid_position` runs once per reported point and computed the position with `i128` arithmetic: `div_euclid` and `rem_euclid` on the same operands, which become two `__divti3` calls for a timestamp and a start that are both `i64`. Stay in `i64` when the subtraction does not overflow and the offset is not negative: `div` and `rem` on the same operands become one machine divide. Off-lattice timestamps, positions past the end, negative offsets and overflowing subtractions fall through to the `i128` path, which answers the same as before, error message included. The fast path is a strict subset of what the `i128` code accepted, so the answer cannot change; a wrapped subtraction is the one way it could, and a test pins that an overflowing offset still goes to the wide path. Another test pins that a lattice whose offsets do not fit in an `i64` at all still answers, so the fast path cannot quietly narrow what the function accepts, and a third pins the lattice itself. Measured on a step=1s range query over 28.8M grid points on the native PromQL path, retired instructions per query, alternating the two binaries: session A (3 rounds) before 51,233.33 / 50,677.21 / 50,795.70 M after 47,174.07 / 46,378.66 / 46,473.54 M session B (2 rounds) before 51,343.56 / 51,232.13 M after 45,803.16 / 45,942.42 M That is 8.5% to 10.6% fewer instructions, with every paired round moving in the same direction and no overlap between the two ranges. The two sessions do not share a baseline to better than about 1%, so the range is reported rather than one figure. The `perf` samples put `grid_position` at 3.99% of the profile and the divide at 3.6%, which understates this: `__divti3` is dozens of instructions per call, so a sampling share reads low where an instruction count does not. `cargo nextest run -p promql` passes 1123/1123. Signed-off-by: discord9 <discord9@163.com> * feat(query): place a native label-set merge above the regions (#10191) * feat(query): place the canonical merge above the regions A canonical producer merges the pieces of one label set that its own input partitions hold, and the canonical router FusedSeries::to_physical_plan inserts above it collects them from exactly those partitions. In process the producer reads the region's own scans, so the region holds every piece its router has to see and that placement is the only one it has. Over the wire the producer reads RawSeriesSource children instead - the wrapper that reconciles fragments several regions hold. Classifying that shape commutative shipped producer -> router as the region sub-plan, one producer and one router per region, each collecting only its own region's pieces, so a label set a time partition spread over several regions was answered from one region's share. Classify a canonical producer by its own contract only: commutative when every child is a bare scan, non-commutative otherwise, and never fall through to the per-series rules, which describe what a node computes and say nothing about where the pieces of one label set are. The analyzer then cuts at the raw source, so the frontend holds consumer -> SeriesRepartitionExec(CanonicalLabels) -> producer -> [raw router] -> MergeScan(RawSeriesSource(TableScan)) and the canonical router collects each label set from the producers of every region, while the fragments of each series are still reconciled below the producer by the raw-primary-key router the interleaved raw input asks for. Admission follows the placement: the in-process route still declines a canonical merge over a partitioned table, because a region-local producer is the only placement it has, and the remote route now admits it. Acceptance is a real two-datanode test over a three-partition metric table: the rows equal an unpartitioned control's, the producer and its canonical router are frontend nodes above the merge scans, and a collision two regions hold reports the Prometheus duplicate-labelset error that no single region can see. Signed-off-by: discord9 <discord9@163.com> * test(promql): partition the canonical acceptance table on a tag GreptimeDB has no implicit time partitioning: a table has more than one region only from a declared partition, and metric tables are normally partitioned on a tag. The acceptance fixture partitioned on the time index instead, which made the test read as if time partitioning were the everyday case. Partition on `host` in three ranges - `early`/`first`/`late`/`second` still land in different regions, so the merge pair and the collision pair keep their cross-region geometry - and rename the test accordingly. A partition on a primary-key column that excludes the time index also proves the regions hold disjoint series, so the two assertions that described fragmented series state what this fixture actually proves instead: the merge scan publishes whole series (`contiguous`), and no raw-key repartition sits below the frontend producer because only the label set crosses regions. Signed-off-by: discord9 <discord9@163.com> * refactor(query): ask the transport where a canonical merge runs `canonical_boundary_region_node` inferred "this execution reads the whole table" from the node's children: a canonical producer whose children were all bare scans was admitted inside a region sub-plan. Over the wire every selector input is a `RawSeriesSource`, so the inference happened to agree with the rule that matters, but a wire plan that ever held a bare scan under a producer would have been admitted silently and answered a label set from one region's share. The analyzer already holds the fact. `in_process_region_transport` is what it was built with, and it is exactly the condition under which a region read is the whole table. Pass it down to `Categorizer::check_plan` and `check_extension_plan` and require it instead of inspecting child shapes. Guard the hole the inference hid: a canonical producer over a bare table scan classifies `Commutative` in process and `NonCommutative` on the wire. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover a fragmented canonical merge too A partition on a primary-key column proves the regions hold disjoint series, so the tag-partitioned fixture could not exercise the other geometry the frontend merge has to read: fragments. In a metric table a tag is always a primary-key column and a field must be Float64, so the only declared partition that proves nothing about where a series lives is the time index. Run the same two fixture rows over both geometries in one loop. The tag case still publishes whole series and has no router below the producer; the time case declares interleaved and asserts exactly one RawPrimaryKey reconciling router between the merge scans and the frontend producer. Both keep the unpartitioned control's rows, the frontend placement of the producer and its canonical router, and the cross-region duplicate-labelset error. Signed-off-by: discord9 <discord9@163.com> * Revert "test(promql): cover a fragmented canonical merge too" This reverts commit8ff9f43031. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(mito2): expose columnar preparation and reader stage metrics (#10132) * perf(mito2): merge columnar samples with identity-only keys Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): instrument columnar sample read stages Signed-off-by: evenyag <realevenyag@gmail.com> * refactor(mito2): clarify reader timing and focus merge regression coverage Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): measure columnar discovery preparation stages Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): expose series discovery reader costs Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): cover first-field null recovery in identity merge Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): aggregate preparation counters once per batch Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): retain stage timing on failed and cancelled reads Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): coalesce bounded columnar sample reads (#10127) * perf(mito2): merge columnar samples with identity-only keys Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): instrument columnar sample read stages Signed-off-by: evenyag <realevenyag@gmail.com> * refactor(mito2): clarify reader timing and focus merge regression coverage Signed-off-by: evenyag <realevenyag@gmail.com> * perf(mito2): coalesce bounded sample reads across blocks Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): cover first-field null recovery in identity merge Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): fall back when sample read-ahead exhausts memory Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * feat(mito2): consolidate columnar samples into bounded daily generations (#10129) * perf(mito2): consolidate columnar samples into daily windows Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): isolate daily source coverage and version the local cache Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): use the exported index purge channel Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): exercise daily source groups across the merge limit Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): build stable daily groups from populated source windows Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): anchor daily coverage once per source group Signed-off-by: evenyag <realevenyag@gmail.com> * test(mito2): validate partial-day reads and grouped rebuild cleanup Signed-off-by: evenyag <realevenyag@gmail.com> * fix(mito2): skip daily sample readers outside query bounds Signed-off-by: evenyag <realevenyag@gmail.com> --------- Signed-off-by: evenyag <realevenyag@gmail.com> * feat(promql): match an empty on() and grouped cardinalities natively (#10223) The compiler already carries an empty `on()` and both grouped cardinalities, and the matcher kernel implements them; only the planner's narrow region-local allowlist refused them, so those queries fell back. Admit them: the pair is planned as one native binary over the two operands, matching above their sources. Admitting them exposed an output-schema bug the allowlist was hiding: both tag walks treated an empty `on()` as "keep every tag", so the output carried labels the kernel had dropped. They now keep only the specified labels, and a grouped match keeps the many side's labels and copies the included ones from the one side. Tests: the empty-`on()` subtraction and the `group_left()` form assert native execution with their original rows and labels, and four cases assert the kernel's cardinality errors - duplicate right under `on()` and `group_left()`, an implicit many-to-one under `on()`, and duplicate left under `group_right()`. The subquery case in the same loop keeps its fallback. Signed-off-by: discord9 <discord9@163.com> * fix(query): plan a data-free statement and a zero-match discovery natively (#10224) Three refusals kept statements off the native route in a distributed deployment, and one of them raised an Internal error rather than falling back: - `remote_native_raw_plan_supported` required a `RawSeriesSource` somewhere in the plan, so a statement that reads no table was re-planned without native execution and answered with legacy column names. The gate now also admits a `FusedSeries` chain whose leaves are all the typed empty input - followed through fused nodes only, so a scan, a raw source or any other extension still rejects - and the exact `strip_tsid_column` projection over such a chain. - A nameless selector that matches no metric produced a typed empty input, and on the distributed route that input fell through to "a prepared selector has no metric name". It now stays that input on both routes: never wrapped in a raw source, never bound to a metric. - A segmented shape such as `sort({job="api"})` did not recognize the empty child as an already-prepared explicit-frame input, so it declined. It is recognized next to a raw source now. The empty predicate checks the declared frame rather than only the `EmptyRelation` variant, so the guard's narrowness rests on a typed check. Tests cover `time()`, `vector(1)`, label rewrites including one that synthesizes `__tsid`, and `{job="api"}` / `sort` / `sum` / `absent` with no authorized metric, asserting native admission, the declared frame schema, `metric_name: None` and the actual rows and labels - including a two-datanode distributed case. Signed-off-by: discord9 <discord9@163.com> * feat(query): read a split-series table through a raw source (#10227) A table partitioned on a column that is not a tag splits one series across regions, so a bare scan inside one region holds a fragment: a window there evaluates over part of the series and a range that straddles the boundary produces no value at all. The single-selector route declined that shape in process, so the existing planner answered it. Read it through a raw source instead: `prepare_one_scan` reports whether the declared partition splits a series, that occurrence is wrapped like any other source-backed input, and the segment cut keeps the source so the prefix runs above the reconciliation. A partition on tags keeps every series whole in one region and keeps the bare-scan path. Signed-off-by: discord9 <discord9@163.com> * feat(query): match a partitioned multi-selector tree above its sources (#10226) * fix(query): match the whole operand instead of copying matchers A native binary must report what Prometheus reports: when one side holds two series under one matching label set, the query fails with "found duplicate series for the match group ... on the right hand-side". The legacy route answers a value instead, because `matching_filters::propagate` copies the matcher into the other operand's scan and the groups without a partner are dropped before the join - its own documentation says that hides the duplicate. This branch had started applying that rewrite to native operands as well, and had refused multi-selector trees over partitioned tables in process to force the hybrid topology back. Both kept a legacy behaviour the native route does not need: a native binary reads independent raw sources and checks the whole one-side groups itself. Drop the rewrite for native operands, and keep the refusal only for several scans of one partitioned table, whose node cannot run inside a region. The partitioned acceptance case now asserts the duplicate error and that the pair really runs as one native binary; the legacy value stays in the test as the contrast that documents the difference. Signed-off-by: discord9 <discord9@163.com> * test(promql): assert the native binary, not the hybrid join The hybrid cases were written when a cross-table pair over a partitioned table could only run as two region-local producers joined on the frontend. The pair now runs as one native binary over independent raw sources, so those shape assertions describe a topology that no longer exists: two fused nodes, a frontend join, direct region scans under it and a projection above it. Assert what the native plan actually promises instead: the binary is one fused node with more than one input, every operand reads its own source, and the duplicate-group and value assertions stay as they are. The per-scan-partition value check now applies to operand producers only - a matching binary routes by label set, so an input partition may contribute nothing to a given output one. Signed-off-by: discord9 <discord9@163.com> * test(promql): keep the operand metrics for a native binary The per-scan-partition value check ran over every fused node, which now means the binary itself: it routes by label set, so an output partition may legitimately hold nothing from a given input partition. Check the two operand metrics instead - the same assertion the unpartitioned pair already makes - so each operand still proves it registered its values on every partition it reads. Signed-off-by: discord9 <discord9@163.com> * feat(query): admit multi-selector trees the native binary can match Three refusals were left over from when a multi-selector tree could only run inside one region over bare scans, and each of them now only costs coverage: - The aggregate split and the segmentation were admission authority: a tree that needed placement and did not fit the single-selector split fell back, even though each selector occurrence can read its own raw source and the consumer can run above the collection. They are optimizations now. - `multi_input` meant "the metric logical ids differ", so ordinary tables, repeated selectors and mixed engines were treated as a single input. It now means what the code needs: more than one independent input, one per selector occurrence, each bound to its own source. - Several scans of one partitioned table were refused in process. That node cannot run inside a region, but the same tree has a frontend placement over per-occurrence raw sources, so only the cross-table refusal that keeps the hybrid route is left. Tests that asserted the fallback now assert the native plan and the per-source inputs; the value, label and duplicate-group assertions are unchanged, and the shapes the compiler genuinely cannot express stay refused. Signed-off-by: discord9 <discord9@163.com> * fix(query): keep the raw sources under an in-process cut A table partitioned on a column that is not a tag splits one series across regions. When such a tree is cut into segments in process, the cut could fall back to the bare scan, and then a per-region prefix evaluated a window over one region's fragments: `rate` never saw the samples the other region holds, so a window that straddles the boundary produced no value at all. Remote execution already kept the raw source under the cut; in process the flag said otherwise. Pass the boundary fact that matters - the cut must keep each source when the table is split into regions - so the evaluated segment runs the prefix above the reconciliation. An unpartitioned table's scans are whole in one region, so its cuts keep the bare-scan form and the two-aggregate pairs still plan as one execution. The regression puts the two samples of one series on either side of a time-partition boundary and compares the native answer with the existing plan's for a two- and a three-selector window; without this change both lose the value. Signed-off-by: discord9 <discord9@163.com> * test(promql): prove the window runs natively The time-boundary regression compared rows with the existing plan, which a fallback also satisfies. Require a fused node in the frontend tree as well, so the test fails if the planner quietly declines the shape. Signed-off-by: discord9 <discord9@163.com> * test(query): trim redundant gates and assertions A review of this branch found duplications rather than missing coverage: two identical metric-name gates, a `!multi_input` term that now implies its own `selector.len() == 1` partner, a duplicate aggregate-admission test, a redundant cooperative-decorator special case, a tautological region-input assertion, an exact-child-type assertion that pins an intermediate shape, and a window regression that accepted a region-side fused node as proof of frontend admission. Remove them; the behaviour assertions stay. Signed-off-by: discord9 <discord9@163.com> * test(promql): require the native binary for a partitioned pair The values equal the legacy route's, so a legacy frontend join reading the same regions could satisfy the assertions on their own. Require the fused node in the frontend tree as well, and drop a duplicated rustdoc paragraph. Signed-off-by: discord9 <discord9@163.com> * fix(query): drop the stale unconditional canonical refusal A rebase left both the old refusal (`any_partitioned && contains_canonical_merge`) and the transport-scoped one, so the older block declined every canonical merge over a partitioned table on the wire and the acceptance case fell back to the existing planner. Keep the scoped refusal only. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * perf(mito2): cache aligned sample payload blocks in the page cache (#10128) Cache aligned sample payload blocks within the shared page-cache budget with generation isolation and owned buffer accounting. Fall back to uncached block reads when aligned reservations exceed the scan budget. Validated bounded reads, cache isolation, cancellation and reservation release. * perf(mito2): retain batch-backed labels for native samples (#10134) Retain compacted metadata rows for new series candidates and materialize owned labels lazily. Preserve region-qualified identities, full physical-tag conflict checks and mixed-predicate fallback. Separate scan bindings from output labels and validate execution-time schemas. Validated cross-bucket retention and conflicts, filtered PromQL label binding, affected crate tests and strict Clippy. Sample-to-flat, merge and frame conversions remain. * perf(mito2): reuse sample decoders within a block (#10214) Reuse decoder context and output scratch during synchronous sample-block decoding, and borrow validated uncompressed payloads. Share checksum validation and release decoder scratch before boundary-read I/O waits. Preserve bounded decoding, corruption handling, timestamp-first pruning and block memory reservations. * perf(mito2): retain all-visible sample batches (#10215) Return the original sample batch when null-free sequence and timestamp bounds prove every row visible. Preserve schema validation and the mask path for partial visibility and null-containing batches. Cover snapshot, sequence and time boundaries, unordered timestamps and retained buffer identity. * feat(promql): evaluate dynamic scalar parameters natively (#10093) Evaluate scalar expressions per step in native topk/bottomk and histogram functions, including scalar(vector) parameters that read independent selectors. Reuse the existing kernels, preserve whole-vector placement and selector binding order, account for retained parameter values, and append expression wire tags without renumbering existing variants. Expression-column naming is intentionally outside this change. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): reuse canonical and segment trees (#10238) Signed-off-by: discord9 <discord9@163.com> * refactor(promql): remove duplicated planner facts (#10239) Signed-off-by: discord9 <discord9@163.com> * refactor(promql): share instant selection bounds (#10240) Signed-off-by: discord9 <discord9@163.com> * perf(mito2): reuse raw scan preparation per partition (#10241) Signed-off-by: discord9 <discord9@163.com> * refactor(promql): drop native runtime state at terminal (#10242) Signed-off-by: discord9 <discord9@163.com> * feat(promql): run subqueries through the native prefix (#10085) * feat(promql): run subqueries through the native prefix A subquery evaluates its inner expression on its own grid, so the native route now plans it instead of sending every statement containing one to the existing planner. - `collect_selectors` recurses into a subquery's expression, so its selectors are prepared like any other and each gets its scan bounds from `raw_scan_bounds`. - `calls_rate_or_increase` recurses too, so a delta-temporality table still keeps a rate or an increase inside a subquery on the existing planner. - A window whose input is already evaluated - a subquery - is admitted above the split aggregate when its declared grid equals its direct input's grid, and the suffix is rebuilt with it. A raw-sample window still cannot sit above the cut. - A `FusedSeries` whose root is such a window publishes on that window's output grid, which is not necessarily the statement's; the binding follows it at every construction site, and the split's partial state keeps the cut aggregate's own grid. An evaluated-input window does not need an owner router for its sources, and a segment whose root is one is cut on its own grid. Verified with `-p promql`, `-p query`, `tests-integration --lib` (native_promql) and clippy. Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep a subquery's aggregate operand and gate an evaluated cut Two shapes reached the native route and failed while planning instead of keeping the plan they had. A hybrid-binary operand folds a group one subquery down (`avg_over_time((sum by (job, host) (pm))[5m:1m]) + on(job, host) pn`): `single_selector_operand` counts the subquery's selector, so the operand looked admissible, while `contains_aggregate_expression` stopped at `PromExpr::Subquery` and never saw the aggregate. The admission then built a `FusedSeries` the physical planner could not convert (`No installed planner was able to convert the custom node to an execution plan ...`). The walk descends into a subquery again, and both statements keep the existing plan with the same rows. A window over an evaluated input was cut as a segment regardless of locality. For any such window whose input is not a bare `Input` - a raw window, a `label_replace` - `reads_across_series` is true and `pointwise_operand` false, so the `FusedSeries` arm of the dist analyzer answers `NonCommutative`: the segment stays above the `MergeScan` and nothing converts it (`sum by (job) (max_over_time(rate(pm[2m])[5m:1m]))` and two neighbours failed that way at instant and range evaluation). `region_local_segment` mirrors that arm's decision from the tree, and `cut_as_segment` declines an evaluated-input window it refuses, cutting the per-series prefix inside the window instead; where there is none, the statement keeps the plan it had. The analyzer is not extended: every range function but `last_over_time`/`first_over_time` drops the metric name, so such a window is genuinely cross-series and a region-local segment would publish two series under one label set. `build_evaluated_segment` stays, and so does its caller. The canonical pass inserts a merge under a label rewrite, and that boundary is only ever built from the frames the loop has published, so the cut needs the fallback; deleting it took every rewritten fold off the route, which is what `sum(label_replace(...))` and the histogram-over-rewrite boundary caught. The frames-bound segment itself is not the defect - the gate is: the evaluated-input window is declined before any cut is taken, so the fallback only sees cuts the analyzer places. Tests that asserted the older rejection are decided on evidence: `sum_over_time(rate(m[5m])[1h:])` is admitted now and its rows match the existing plan, so the plan-level test asserts the route and the integration case proves the rows; the aggregate-subquery case in `native_aggregate_complete_over_four_nonempty_mito_partitions` is answered by the split (one `Partial` producer, one frontend merge) and returns the same 15.0 on both routes, so it moved to the split cases rather than being dropped. Two fold-over-subquery shapes in `native_promql_subqueries_match_legacy` (`sum by (job) (max_over_time(rate(...)[5m:1m]))` and the fold above it) are answered natively for the same reason - the fallback builds their cut - and their rows equal the existing plan's, so they assert the route instead of the fallback; the rewrite shape still declines, because its window reads across series and there is no per-series prefix inside it to take instead. Signed-off-by: discord9 <discord9@163.com> * test(promql): assert anchored subqueries do not re-fold across steps Signed-off-by: discord9 <discord9@163.com> * test(promql): drop the unused fallback-case helper Signed-off-by: discord9 <discord9@163.com> * test(promql): update subquery expectations for the native route Signed-off-by: discord9 <discord9@163.com> * fix(promql): publish subquery segments on their declared grid Signed-off-by: discord9 <discord9@163.com> * refactor(promql): drop unreachable segment arms and pin subquery routes Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): answer subquery matrix roots natively (#10095) * feat(promql): answer a subquery matrix root on the native route A matrix-valued instant query whose root is a subquery (`m[5m:1m]`, with `offset` and `@`) now runs natively: the planner recognises the root, derives the subquery's child grid and compiles the inner expression on it, while the statement's own bounds stay where `@ start()` and `@ end()` resolve against them. No window node is added - the tree is the inner expression, and its rows carry the evaluation timestamps, which is what the HTTP encoder reports as `resultType: matrix`. A raw range selector still declines (raw samples have no evaluation grid to bind), and a range query with a matrix root declines so the existing planner's "range vector" rejection is what the caller sees. A pre-epoch statement (`TQL EVAL ('-60', '-60', '1m')`) rebuilds its bounds on the side of the epoch their sign names, and a statement whose grid cannot be built keeps the existing plan. `compile_statement_with_grid` / `compile_selectors_with_grid` take the grid explicitly; the grid is still derived lazily inside the compiler so an unsupported statement reports the reason it has no tree, not a grid complaint. Verified with `-p query`, `-p promql`, `tests-integration --lib` (the matrix-root cases) and the file-backed HTTP route test. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bind the subquery's child grid on every lowering path `compile_statement_with_grid` compiled a subquery root's tree on the child grid and the plain `FusedSeries::try_new` path bound that grid, but the split-aggregate, canonical-boundary and segment paths still received the statement grid. A matrix root whose inner expression folds as an aggregate therefore built a final node publishing on the statement grid over a tree compiled on the child grid, and `plan_split_aggregate` refused it with `FusedSeries output is not on the statement grid`: `sum(pm)[5m:1m]`, `(sum by (job) (rate(pm[2m])))[5m:1m]`, its `@ 600` form and its `* 2` form all failed instead of answering the five child-grid points. The effective grid is now chosen once, right after the statement grid is known - the child grid for a subquery root, the statement grid otherwise - and every lowering path binds that one. The per-site `unwrap_or_else` workarounds and `fused_publish_grid` go away with it: they were compensating for two halves that disagreed, and the binding is now the grid the tree was compiled on. The child-grid derivation itself is back in one function: `subquery_child_grid` in `native_compile.rs` feeds both the compiler (which binds it into the window node) and the planner (which binds the rows to it), using the checked `range_millis`/`millis` conversions and the compiler's zero-step refusal. The planner's inline copy used unchecked `as i64` and its own default step, so an overflowing range wrapped there while the compiler reported it. `native_promql_matrix_root_matches_legacy` covers the four shapes, asserting both the route and the child-grid timestamps for the split case. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover pre-epoch non-matrix routing Signed-off-by: discord9 <discord9@163.com> * fix(promql): publish recursive segments on their declared grid Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(promql): plan a zero-match selector beside another input (#10243) * fix(promql): plan a zero-match selector beside another input Signed-off-by: discord9 <discord9@163.com> * test(promql): cover a zero-match selector beside a real one in distributed Signed-off-by: discord9 <discord9@163.com> * fix(promql): bind a zero-match selector to its set-operand layout Signed-off-by: discord9 <discord9@163.com> * fix(promql): propagate empty set layouts through nested operands Signed-off-by: discord9 <discord9@163.com> * test(promql): cover empty operands beside arithmetic and non-bare sets Signed-off-by: discord9 <discord9@163.com> * fix(promql): record set layouts through subqueries Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(promql): replace the residual hybrid binaries and drop the 64-level depth cap (#10254) Remove the last hybrid composition: when a native statement is refused as a whole but each side is independently admissible, the sides are now compiled through the same native frame preparation, compiler and placement path the whole-native route uses and meet at a shallow native Binary, instead of the native operands being composed by the legacy planner's Join. Admission is decided by the composition itself - equal grids, the binder's matching/cardinality/fill support, the output column's kind, and the runtime execution state - rather than by a predicate that copied what the removed hybrid route used to accept. The artificial 64-level native depth cap is gone on both the construction and the decoding side, with no replacement cap, no depth-based splitting and no product stack configuration; the recursive walks that actually need it grow their stack on demand (validate, runtime build, runtime pull). Histogram binary results are preserved and their diagnostics aligned with Prometheus: an unsupported pairing synthesized by a fill now reports the same Info, and an incompatible bucket layout reports only the schema Warning instead of also reporting a reset-hint contradiction. The legacy histogram UDFs follow the same order so the two routes stay in step. Signed-off-by: discord9 <discord9@163.com> * feat(promql): compile absent_over_time on the native route (#10198) `absent_over_time(<selector>[<range>])` had no native kernel, so the statement declined to the existing planner; there a nameless selector has no metric name to look up, and the query failed instead of answering the label set Prometheus reports. Bind it to the whole-vector operation `absent` already uses, over a window read of the selector's range. The fold keeps the metric name: a presence fold that drops it would fold two metrics which differ only by name into one series and refuse the second value, while `absent` only asks whether the window held anything at all. Labels come from the same derivation `absent` uses, now also accepting a matrix selector. A statement holding a nameless selector that discovery expands into more than one metric table keeps declining: keeping the name would declare `__name__` without a bound metric name, and dropping it would merge the metrics. The typed empty input of a selector that matched no metric table is excluded from that decline, so a zero-match query plans natively and answers from it. The legacy planner is untouched. Signed-off-by: discord9 <discord9@163.com> * feat(query): run an embedded TQL statement on the native PromQL route (#10288) * refactor(query): enforce column requirements per node, not per plan root Signed-off-by: discord9 <discord9@163.com> * feat(query): run an embedded TQL statement on the native route Signed-off-by: discord9 <discord9@163.com> * fix(query): publish one CTE schema on both TQL routes Signed-off-by: discord9 <discord9@163.com> * fix(query): publish the CTE schema durably, including its metadata Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * test(promql): cover discovery under an aggregate on the standalone route (#10255) Signed-off-by: discord9 <discord9@163.com> * refactor(series): hold the frame layout marker at one value The series frame is the native PromQL path's internal transport, and that path lives on `narthex`, an experimental branch: it may break its own formats between revisions, so a frame revision number has no compatibility promise to protect. The marker becomes movable once the path reaches a release branch, where a producer and a consumer can legitimately be different revisions. The reader still refuses a frame that declares any other value, which turns a mismatched producer into an error instead of values decoded under the wrong columns. The two wire fixtures are renamed to `v1_metadata.json`, and the drift cases now use the value that is not current. * feat(promql): let `count` and `group` fold native histograms `count` and `group` fold native histogram samples in the native aggregate: neither reads a value, so a histogram is one present sample. `min`, `max`, `stddev` and `stdvar` read a float and now skip histogram samples the way Prometheus does, reporting what they skipped; `sum` and `avg` keep the existing plan until #10199. A group holding only histograms answers nothing under a skipping aggregate, and `quantile` keeps the existing plan because this runtime has no kernel for it. * test(promql): qualify native corpus partition parallelism (#10181) Use disjoint flushed ranges in the corpus and real-query fixtures, then assert every real SeriesScanExec reads on all four partitions. Assert every region-side fused prefix and partial aggregate publishes on all four partitions; require width-four frontend-raw nodes to do the same while leaving final combine nodes reported only. Signed-off-by: discord9 <discord9@163.com> * perf(promql): reduce repeated work in the native query path (#10212) * perf(promql): elide redundant tracking after name-dropping windows Signed-off-by: discord9 <discord9@163.com> * perf(promql): fold aggregate samples without staging buffers Signed-off-by: discord9 <discord9@163.com> * perf(promql): reuse clean labels when dropping metric names Signed-off-by: discord9 <discord9@163.com> * test(promql): cover literal arithmetic over histogram windows Signed-off-by: discord9 <discord9@163.com> * test(promql): resolve all-target clippy lints Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): support metric-name rewrites in native labels (#10176) Signed-off-by: discord9 <discord9@163.com> * refactor: remove dead native analysis and duplicate columnar filtering (#10314) * refactor(promql): drop unused native build sharing flag Signed-off-by: discord9 <discord9@163.com> * fix(promql): keep retained-label windows unified Signed-off-by: discord9 <discord9@163.com> * perf(mito2): skip exact columnar residual filters Signed-off-by: discord9 <discord9@163.com> * test(promql): pin nested window placement Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(mito2): identify series by their exact sparse key, not by tsid (#10330) * fix(mito2): identify series by their exact sparse key, not by tsid `(table_id, tsid)` is a hash, so distinct series can share it: 2000 label values already produce 20 colliding pairs and a 36k-series SST keeps only 27856 distinct tsids. The columnar series writer silently merged such pairs (first label set kept, row counts added) and the samples writer either reported time_regressed or, with increasing timestamps, attached one series' samples to another's labels. Every one of those decisions used the hash as identity. The SST already stores the exact sparse primary key, so nothing on the storage side changes: `tsid`, the hash function and the key layout are untouched. What changes is that the artifacts, their readers and the prepared read path now decide identity on the canonical sparse key bytes, and `(table_id, tsid)` is only the coarse, order-preserving prefix used for ordering, pruning and bucketing. - `ExactSeriesKey` is the new identity type: equality, ordering and hashing are defined on the key bytes alone, `id()` is documented as a derived prefix that is never compared. `from_sparse_key` validates the entire key, not just the prefix, and bounds it at 8 KiB. - Series format v2 keeps one row per exact key; the descriptor layout and the existing per-row tags already express this once the writer aggregates by key. Coarse page/block/part bounds may now touch, so readers prune conservatively. - Samples format v2 records the owning key per block, appends a `__primary_key` column, and lets a key change restart timestamps and ordinals while the same key keeps the monotonic rules. Exact selection travels in `SamplesReadRequest.keys` next to the coarse `ids`. - The prepared path keys candidates by `ExactSeriesKey`, re-encodes identity from the artifact's own tags, associates samples through `__primary_key`, and uses the exact key for the merge key and the direct-label path. - Both manifests carry a mandatory `identity_encoding` discriminator. Artifacts without it are structurally valid and perfectly ordered yet may contain an already merged row, so they are rejected and rebuilt from SSTs; maintenance rotates them out instead of reusing them, and the local cache version drops the rebuildable store. There is no dual reader and no migration. Verified: `cargo nextest run -p mito2` 1824 passed, 2 skipped (three times, identical); `cargo nextest run -p mito-codec` 57 passed; clippy `-D warnings` and rustfmt clean. Tests pin the real captured pair (`host-020078` / `host-029838`, both retained with their own labels), the silent-loss variant with globally increasing timestamps, sixteen distinct keys under one forced tsid in both PK encodings, candidate isolation end to end, and rejection of a frozen v1 fixture. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): close the exact-identity review findings - The two-phase series scan assumed candidate discovery had already enforced tag predicates through an "exact assigned-series set". An assignment is a `(table_id, tsid)` hash, so a colliding partner shares it without matching the predicate, and skipping tag filters returned its rows. Apply the predicates the precise filter already holds instead of assuming them. - `MAX_KEY_BYTES` was checked when reconstructing a key from an artifact but not when a writer built one, so the writer could publish a key the reader refused; a single 8 KiB label already encodes past the cap. Length is bounded by the containers that store a key (one key per block, descriptor, page and column limits), and long labels are real data, so drop the cap instead of enforcing it on both sides. - The `__primary_key` column copies one key per output row, but the read reservation budgeted a fixed 32 bytes per column and metadata pages did not count the per-block key heap: 8192 rows of 8 KiB keys allocated ~64 MiB against a ~1 MiB estimate. Budget the real bytes and count the heap. - `SamplesReadRequest` carried both `keys` and `ids`, which the only caller derived from the same candidates; selection is key-only now and the reader derives its coarse pruning set, so the two selectors cannot disagree. - Restore the unknown-field-codec projection coverage that the frozen v1 fixture used to carry, against a generated v2 artifact, and assert v1 rejection through the compatibility property rather than a field name. - Drop the redundant columnar increasing-timestamp test (that writer never reads timestamps) and correct the samples format doc: the five internal columns and `__primary_key` are non-null, value fields stay nullable. Verified: `cargo nextest run -p mito2` 1830 passed, 2 skipped; clippy `-D warnings` and rustfmt clean. Each new test was run with its fix reverted first: the two-phase test returned the colliding partner's rows, the long-key tests failed with "series key exceeds 8192 bytes", and the 4 MiB pool test read 8192 rows of 1 KiB keys while allocating ~8 MiB. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): budget the exact key column exactly and drop stale skip-tag claims The read reservation charged the exact-key column its logical bytes, but the column was built with `BinaryArray::from_iter_values`, whose value buffer grows geometrically: measured on a 2135-row fixture it retained 4,989,432 bytes for 2,551,325 bytes of key data (1.956x), so a pool sized from the reservation was oversubscribed. `BinaryArray::new_repeated` allocates the offsets once and reserves the key bytes once (1.003x on the same fixture), which is what the reservation already assumes. The new test asserts the pool covers what the yielded batch retains, that the column keeps no growth slack, and that the reservation is released on drop; 2135 rows sits just past a doubling step so a growing builder fails it. Also make the documentation match the mechanism and the encoder: - `read/pruner.rs` still told readers the data phase skips tag filtering because candidate discovery had applied the predicates exactly once. Assignments are `(table_id, tsid)` hashes, so a colliding partner shares the identifier without matching the predicate, and the data phase does apply tag predicates. - The initial-window fallback test anchored on `reads[5]`, which is the second payload window; it now identifies the initial window by its payload-header offset and asserts the window spans 128 blocks, so a traversal change cannot quietly point it at another read. - The samples format descriptor sizes are recomputed from the encoder (`48 + 44 * C + key_length`): `224`, `45,236`, and with the leaf prefix `45,248`, each `+ key_length`; the page-fit sentence now states the enforced constraint (descriptor and leaf prefix inside one page) instead of claiming the widest descriptor always fits. Verified: `cargo nextest run -p mito2` 1831 passed, 2 skipped; clippy `-D warnings` and rustfmt clean. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): budget each projected sample array's fixed overhead The read reservation charged per-row bytes plus the payload sizes, but not the fixed cost of the arrays it builds: Arrow's `get_array_memory_size` is the array struct plus its buffer capacities, so a one-row, key-only projection reserved `key_length + 72` for the 1344 bytes it actually retained. Add `ARRAY_HEADER_BYTES` (`size_of::<BinaryArray>()`) plus `BUFFER_ALIGNMENT` per projected column, as their own term, and cover the one-row key-only case in `exact_key_output_reservation_covers_the_retained_array`: the pool must cover the batch's reported memory size while it is alive and be empty after drop. Verified: `cargo nextest run -p mito2` 1831 passed, 2 skipped; clippy `-D warnings` and rustfmt clean. Signed-off-by: discord9 <discord9@163.com> * chore(mito2): pin the series-index cache token to 1 The branch inherits `2` from an earlier layout change. This branch is experimental and has no deployments, so it pins the token at `1`: whatever a different build wrote into the rebuildable local store is discarded on startup and rebuilt from the SSTs. The token is not the compatibility boundary on its own. Artifacts are rejected on open when they lack the mandatory `identity_encoding` discriminator, so a hash-only artifact is never served even when the reset has not run yet (a read that precedes it, or an artifact outside this cache). Signed-off-by: discord9 <discord9@163.com> * feat(mito2): keep exact series keys out of the samples descriptor page A block descriptor used to embed the whole exact key, and a descriptor shares a 65,536-byte metadata page with its leaf prefix. That put an accidental ceiling on key length: 65,344 bytes with no value fields, 65,300 with one, and 20,288 with 1,024 fields. Valid SST primary keys can be longer, so their samples builds failed with "sample descriptor exceeds leaf limit" even though the key itself was accepted. The key now lives in a per-part key area and the descriptor carries a reference: part = [header 16][column payloads][key area][leaf pages / root][trailer 120] trailer = root ref 72 | depth 4 | version 4 | file_length 8 | payload_end 8 | key_end 8 (body 104), magic 8, XXH64 over the preceding 112 bytes 8 block = table_id u32 | tsid u64 | key offset u64 | key length u32 | min i64 | max i64 | ordinal u64 | rows u32 | columns u32 (56 bytes, fixed) Descriptor size no longer depends on key length (232 bytes for one present field, 45,244 for 1,024), so the ceilings are gone. Keys are written once per series, back to back in block order and without padding, so an equal reference means "same exact series" and a key may exceed any page limit; a reference is validated against `key_end` with a checked add, an overlap between consecutive new series is rejected, and a resolved key whose `(table_id, tsid)` disagrees with its descriptor is refused before any row is emitted. Reads stay lazy: only blocks that survive coarse selection fetch a key, at most once per series, merged per page and bounded by `MAX_READ_BYTES`, reused from the part's aligned cache when one is configured. Measured on the 260-series fixture: 260 per-series key reads before, 1 merged read after, with the fetched byte count asserted to be exactly the key bytes. The read contract also stops materializing one key per row: `SamplesBatch { batch, key }` carries the block's key once, the exact-key column is refused in projections, and `prepared` attributes a whole batch with a single binary search. For an 8,192-row block with a 1 KiB key the reservation drops from 8,388,608 B to 1,120 B (~7,490x), which is what lets a 4 MiB pool read it; `Candidate` keeps one owned copy of the key instead of two, and `retained_rows` is gone in favour of the `prepare_retained_rows` metric. No version bump: the layout changes in place. Artifacts written by an earlier shape of this branch (112-byte trailer, or keys inside descriptors) are unreadable and must be rebuilt, which the cache token and the required `identity_encoding` discriminator already bring about. One user-visible cost: keys retained by a scan are charged to its memory pool, so a scan that used to fit in 16 KiB needs ~14 KB more for 128 series. The fixture that pinned 16 KiB is raised to 64 KiB with the arithmetic in a comment. Verified: `cargo test -p mito2 --lib -- series_index::samples series_scan::prepared series_index::identity` 72 passed / 0 failed / 2 ignored on six consecutive runs; clippy `-D warnings` and rustfmt clean. Failing-before evidence, both produced by reverting the relevant hunk: - restoring `48 + 44 * C + key_len` fails the >64 KiB round-trip with "sample descriptor exceeds leaf limit"; - the 260-series coalescing assertion fails against per-series reads. Signed-off-by: discord9 <discord9@163.com> * test(mito2): assert the duplicate-drop on the preparation's own rows `overlapping_buckets_retain_only_new_label_rows` compared the deltas of two process-global counters (`prepare_unique_series`, `prepare_retained_rows`). Every preparation in the process increments both, so under parallel test execution the two deltas do not pair up and the test failed intermittently - it always passed in isolation. Assert the property the pairing was standing in for, on this preparation's own rows: read every series of the prepared source and require that no series keeps two rows at the same timestamp. A surviving duplicate from the overlapping bucket would repeat a timestamp; the counters can no longer make the result depend on what else the test binary happens to be running. Signed-off-by: discord9 <discord9@163.com> * test(mito2): drop the now-unused preparation counter helper The duplicate-drop assertion no longer reads the process-global counters, so `prepared_count` has no callers and `-D warnings` rejects the dead function in `cargo check` and `cargo clippy` CI. Remove it. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): scope key references per part, bound key reads, checksum keys Review of the key-area change found three defects that ordinary data can hit and three smaller ones. All six are fixed with a test that fails beforehand. Key references are file-local offsets, and the ordering state kept them across parts: a series continuing into another part looked like an overlapping reference (or a new series with a non-zero ordinal), and two different series in structurally identical parts could be mistaken for one because their offsets and lengths coincided. Reference ordering is now scoped to a part; continuation across a boundary is decided on the exact key bytes plus time/ordinal, and the loaded keys must be nondecreasing, a repeated key must continue its series. A key prefetch fetched the whole window and only then grew the reservation, and the per-key fallback charged after its read, so a small pool could read and assemble a page of long keys before reporting exhaustion. The peak (fetched entry + owned key + alignment/assembly) is now reserved before the read; on refusal the reader drops alignment first, then halves the window, and a returned key is cloned only after the block reserved for it. A test asserts that an unpayable prefetch issues no key read at all. The key area had no integrity check, so flipping one byte of a label - leaving framing and `(table_id, tsid)` intact - could silently change which series a block belongs to. Every stored key now carries its XXH64, excluded from the reference length and verified when fetched. The manifest discriminator now names the layout (`exact-sparse-key-area` for samples; the series index keeps `exact-sparse-key`), so an artifact with inline keys is refused at open instead of being marked reusable by maintenance and failing later at a part read. No version number changes anywhere. A key copy is also counted correctly when a series spans a metadata rollover: the "first copy of this part" decision is taken after the rollover, not before. Verified: `series_index::samples` 51 passed, `series_scan::prepared` 27 passed, `series_index::identity` 4 passed; clippy `-D warnings` and rustfmt clean. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): charge the key peak on every path and chain the order check Four follow-ups from the confirmation review of the key-area change. The per-key fallback reserved only the retained and stored bytes and then fetched through the aligned payload cache, whose aligned/assembly peak it never charged, so a leftover key could read a whole aligned block the pool had not paid for. It now reserves the same peak as the page prefetch: aligned budget first, and on refusal an explicitly cache-less reader with the unaligned peak, before any read. The key carried across a part boundary was a deep copy taken while the per-part reservation was being released, so it lived on uncharged until the next part. It is now held by its own pool consumer, charged before the copy and released when it is replaced or when the boundary falls behind the scan. The content-order check was chained over the last *traversed* block, which an unloaded block overwrote, so a block pruned by selection could hide reversed or restarted keys - and could drop the boundary key entirely when a part ended on a pruned block. It is now chained over the last *loaded* key, with adjacency taken from "the last traversed block is the last loaded one", so a gap still requires increasing order and a strictly greater ordinal but not exactly +1. Finally, the key-area read counter in the tests only saw reads fully inside the key area, missing aligned reads that start before it; it now counts reads that intersect, and the cached-read test is documented as a cache-behaviour guard rather than a failing-before proof for the budget work. Verified: `series_index::samples` 55 passed, `series_scan::prepared` 27 passed, `series_index::identity` 4 passed; clippy `-D warnings` and rustfmt clean. Failing-before evidence: a 16384-byte key-area read issued with only 15080 reserved; a boundary key with 0 of its 1195 bytes charged; reversed keys hidden behind a skipped block; and a pruned block hiding the boundary key. Signed-off-by: discord9 <discord9@163.com> * docs(mito2): qualify the ordinal rule to one exact key The samples format said a loaded key's ordinal must still grow, which reads as if ordinals had to increase across different series too. They do not: only an equal exact key continues, an adjacent block of that key requires +1, and a different key starts at zero. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(mito2): keep main's cache split unless the columnar format is enabled The merge reserved a quarter of `sst_meta_cache_size` for the native-reader metadata tier unconditionally, which silently halved main's decoded tier (1/2 -> 1/4) on every deployment, including the ones that never enable the columnar series-index format. Gate that reservation on `experimental_series_index_format == Columnar`, so the default split stays exactly what main ships and `columnar_meta_cache` is not even constructed. Tests that exercise the columnar tier now opt in explicitly. Signed-off-by: discord9 <discord9@163.com> * fix(mito2): drop a needless borrow in series-index reconciliation `files` is already a reference after the merge, so `&files` tripped clippy::needless_borrow and failed CI's `-D warnings`. Signed-off-by: discord9 <discord9@163.com> * fix(mito-codec): register reserved columns in the sparse label fixtures main enforces (`fix!: enforce sparse primary key schema`) that a sparse primary key starts with `(__table_id, __tsid)` and that every primary-key column id exists in the schema. The label-decoding fixtures built a sparse key that satisfied neither, so `RegionMetadataBuilder::build()` panicked and the workspace `test` job failed. Same adaptation as the promql source fixtures. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): read binary operators' kernel operations from one table (#10393) * refactor(promql): drop the Go math port and use the standard library The pointwise kernels called a port of Go's `math` functions as they behave on amd64. Results are compared within a tolerance, and the port reproduced amd64 assembly quirks that Go on arm64 does not share. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): read every binary operator's kernel operation from one table `BinaryOp::kind` maps an operator to the arithmetic or comparison the map kernels implement. The vector-vector kernel, the scalar broadcast and the compiler's constant fold use it instead of their own tables and their own copies of the arithmetic. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): use BinaryOp::is_comparison for the hand-written comparison checks Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): info() ACL targets, per-series routing, reset collisions (#10385) * fix(sql): include the table PromQL info() reads in extracted tables `info(v)` and `info(v, {label="x"})` read `target_info`, which is not written as a selector in the expression, so table-level permission targets missed it. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): keep per-series provenance behind CooperativeExec `EnsureCooperative` wraps the `SeriesScanExec` leaf and rebuilds `RawSeriesSourceExec` over the wrapper, which cleared `per_series_scan` and left `SeriesFrameOutput` on the merge-inputs router. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(promql): drop histogram pairs whose counter reset hints contradict Prometheus returns the collision as the error of `+`/`-` and skips the pair before counting its match. The native path kept the sample and counted it. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * fix(frontend): keep info() label selectors out of metric discovery The table extractor now claims `target_info` only for the selector shape the planner reads it with; other shapes stay unresolved. `MetricDiscoveryVisitor` skips the label selector of `info`, which the planner never discovers with, so an unresolved one is no longer answered by the caller's discoverable tables. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * test(promql): expect the dropped pair on a histogram reset hint collision Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): share NativeNode child traversal across crates (#10391) Move `node_children` and `with_node_children` from the query planner to `NativeExpr::children` and `NativeExpr::with_children`, add `NativeNode::{any, inputs, is_data_free}`, and replace the hand-written structural walks over `NativeExpr` with them. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): derive native output columns and run-time labels with one walk (#10394) The planner's `native_output_tags` was a copy of `fused_output_tags` in `promql::native::plan` read over tag columns instead of run-time label sets. The planner calls `fused_output_tags`, which takes over the one rule the copy had on its own: `or` reports the metric name of each row. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * refactor(promql): drop the Go math port and use the standard library (#10392) * refactor(promql): drop the Go math port and use the standard library The pointwise kernels called a port of Go's `math` functions as they behave on amd64. Results are compared within a tolerance, and the port reproduced amd64 assembly quirks that Go on arm64 does not share. Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * docs(promql): stop claiming map_arithmetic follows Go's math functions Signed-off-by: Dennis Zhuang <killme2008@gmail.com> --------- Signed-off-by: Dennis Zhuang <killme2008@gmail.com> * perf(mito-codec): index sparse label columns by id once at bind time (#10419) The sparse-label audit walked the physical primary key once per label: column() and position() were linear scans over the described columns, so decoding a key with N labels over M primary-key columns cost O(N·M) per chunk. Build an id→encoding-position index once in bind() and use it for both lookups, so the cost drops to O(N). The full structural audit still runs before any value is read, and error text and error-selection order are unchanged. Signed-off-by: discord9 <discord9@163.com> * fix(promql): declare the per-row name column on every native rows answer A native rows result now always declares `__name__`, a nullable `Utf8` column appended after the labels and marked as the metric name, and each row carries the name of the series it was read from. A row whose value is computed rather than read (a math kernel, a folding aggregate, a range function) carries null there. The name is part of what the statement answers, not of how a response is displayed: the walk that derives a node's tags reports the name of a discovered source and of an `or` unconditionally, so `sum by (__name__)` groups on the identity of the series rather than collapsing every series into one group. `with_row_name_column` appends the column when the root is a samples root. It moves an existing name column to the end rather than adding a second one, because neither a set operation nor a discovered source leaves an existing name last: `or` keeps the order of the left operand and appends only the tags of the right side it has not seen, while a discovered source sorts its tags, which puts the name wherever its bytes fall. Every rows layout then answers one order - the time index, the value fields, the labels, then the name. A `label_replace(..., "__name__", ...)` result is therefore not declared twice, and a scalar root keeps its two columns. The collision check runs after the column is appended, so a name that would clash with a label still declines the layout, and a split's terminal schema declares the column while the frame producers keep the tags they were compiled with. A CTE answered natively publishes the column too, after the existing planner's columns and only when the answer declares one: `publish_legacy_schema` keeps the metadata-carrying name column out of its type-based pairing, so a label cannot claim it, and validates the published schema column by column. `abs(a or b)` now reports no `__name__` at all instead of the statement's name on every row: the operator drops the name, so the declared column's values are null. Shapes that keep the name (plain selection, filtering comparison, `or`, `topk`/`sort`, `first/last_over_time`, `sum by (__name__)`) carry it per row. Signed-off-by: discord9 <discord9@163.com> * chore(deps): point greptime-proto back at the upstream repository (#10370) `narthex` was pinned to a personal fork branch because the `RawSeriesSource` Substrait extension only existed there: GreptimeTeam/greptime-proto#355 was still open when the back-merge landed. #355 has since been merged as `5fc04135b`, so point the pin at that upstream commit. The generated bindings are identical; only the source repository changes, and the branch no longer depends on a fork staying available. `Cargo.lock` regenerated with `cargo metadata`. Verified: `cargo check --workspace` passes. Signed-off-by: discord9 <discord9@163.com> * perf(promql): avoid two copies on the native binary path (#10338) * perf(promql): write single-field binary results in one pass A merge of one field has nothing to merge: the field filed every label set's rows already sorted by point, and already refused two rows at one point. Writing them straight into the builder drops the per-label-set map, the triples table, its sort and the row buffer that the multi-field merge needs, and bills the same columns that merge bills. Profile shares of one 20s workload on a six-thousand-series shape put merge_fields at 6.1% of samples before and 3.2% after; the query result is byte-identical. Wall-clock comparison on that host could not resolve the difference: session drift there is larger than the effect. Signed-off-by: discord9 <discord9@163.com> * perf(promql): move a chunk into its only runtime input One source feeding one runtime input is the common shape, and the chunk was cloned for it and then dropped. Moving it removes that copy. Several inputs still clone per input, and a producer state batch stays refused either way: it carries the charge for its whole payload and belongs to a different handover. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * test(query): pin the native PromQL option default to off (#10371) The native route is gated by two halves: the engine-wide `experimental_native_promql` option and the per-request `query.experimental_native_promql` extension. The extension half is already covered by the `native_promql_requested_*` tests in `query::promql::planner::native`, and the plan-shape no-op is covered by `SeriesFrameOutput`'s `a_plan_without_a_frame_declaration_is_untouched`. What was not pinned is the default of the engine option itself. Flipping that `false` to `true` would expose the native route to every query that sets the extension, and no test would fail. Assert it directly so the opt-in property cannot regress silently. Signed-off-by: discord9 <discord9@163.com> * perf(promql): route proven per-series chains disjointly and forward explicit child frames (#10413) perf(promql): keep per-series provenance and let identity-preserving windows route disjointly RawSeriesSourceExec re-derived per_series_scan by downcasting the child directly, so EnsureCooperative's wrapper silently dropped the proof and the root router fell back to MergeInputs. Peel CooperativeExec before identifying SeriesScanExec, and check the child's bound tags cover the primary key the same way a bare scan is checked. FusedSeriesExec now accepts a RawSeriesSourceExec input, and a Window whose function keeps the metric name and whose child preserves partition identity, so last_over_time/first_over_time over a per-series scan can publish each identity as soon as its chain closes. When the child already publishes this node's frame, RawSeriesSourceExec forwards it 1:1 instead of unpack→relabel→pack. Signed-off-by: discord9 <discord9@163.com> * fix(promql): ignore histogram samples in scalar() and share one kernel (#10426) * fix(promql): ignore histogram samples in scalar() and share one kernel Prometheus' funcScalar counts only float samples: histogram samples are ignored silently, so they neither supply a value nor make a point hold more than one element. The select kernel rejected them instead, while the native ScalarOf runtime kept its own inline loop that ignored them, so scalar(histogram_metric) answered differently depending on the route. The kernel now ignores histogram samples and the runtime calls it, deleting the inline copy. A point with one float answers that float, with only histograms or with several floats answers the Go NaN. The kernel builds its answer as one dense run over the grid: a Vec<f64> seeded with the Go NaN, where the first float at a point writes its value and a second writes NaN back, plus the counts the caller already reserves. That buffer becomes the result's Float64Array by move, so the per-point peak is the 8 bytes of values plus 1 of counts the reservation already counts. Staging through Vec<Option<f64>> and GridSeriesBuilder would have held about 33 bytes per point against a 9-byte reservation. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): resolve the evaluation grid once in scalar() grid_points already resolves and validates the grid, so asking for the schema's grid again right after could only disagree with what was just checked. Signed-off-by: discord9 <discord9@163.com> * chore(compat): move the from-versions window to v1.3.1 v1.3.1 has published release assets, so the compatibility check asks for it and fails on every branch that still names v1.3.0. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * refactor: drop two helpers whose production callers are gone (#10427) * refactor(promql): drop the uncalled merge_exact_series helper The helper carried #[allow(dead_code)] and a comment saying the fused series stack would call it once that caller landed on this branch. No caller exists: no references in src, tests-integration, tests-fuzz or tests, and no re-export. Its only dependency, merge_same_labelset, is a shared grid_series helper with other users and stays. Signed-off-by: discord9 <discord9@163.com> * refactor(datatypes): drop StateFrameRow::to_state_series Only three promql tests called it, and each asserted frame content -- labels, grid length, per-point state values and presence -- after the conversion rather than the conversion itself. They now read the row's fields() and time axis directly, so the unpack and declaration-validation path is still exercised and no assertion was dropped. The private state_float helper went with it; StateSeries itself stays, still produced by pack_aggregate_state and the repartition fixtures. Signed-off-by: discord9 <discord9@163.com> * chore(compat): move the from-versions window to v1.3.1 v1.3.1 has published release assets, so the compatibility check asks for it and fails on every branch that still names v1.3.0. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * refactor(promql): drop four kernel entries the native runtime replaced (#10429) * refactor(promql): drop four kernel entries the native runtime replaced Each of these had no caller left outside tests, and each has a live replacement the runtime already uses. The golden cases move to that replacement rather than being deleted with the entry, so the inputs they covered are still covered. FloatMerger::merge/merge_budgeted/merge_series -> merge_row, which reads a StateRow instead of a PartialAggregate. The merge tests now encode partials into rows and drive merge_row, keeping the fold order, the shuffled partition orders, the NaN and signed-zero cases and the admission-before-insert assertions. One test goes away: the spare capacity of an input partial's nested Vec has no counterpart in a row, whose memory is charged as Arrow buffers by the caller and whose shared parent buffer the router charges separately. map_negate -> -1 * x, which is how the compiler already lowers unary minus. NaN bit patterns differ between negation and multiplication (the sign and quiet bits are not specified by IEEE), so the assertion is that the answer is still a NaN carrying its payload; staleness is decided at instant evaluation and a Map's holes are validity bits, so neither reads that payload. Prometheus's neg cases pass unchanged. map_compare -> map_compare_literal/map_compare_series, which is what production already called. The histogram cases now assert that kernel's existing drop-and-report behaviour instead of the dead entry's whole-query error; production behaviour is unchanged. scalar_arithmetic/scalar_compare -> the compile-time constant folding the compiler performs, asserted through constant_series. ScalarFunction and map_scalar_function stay: removing them depends on the parameterized math variants another change adds. Signed-off-by: discord9 <discord9@163.com> * chore(compat): move the from-versions window to v1.3.1 v1.3.1 has published release assets, so the compatibility check asks for it and fails on every branch that still names v1.3.0. Signed-off-by: discord9 <discord9@163.com> * test(promql): spell the state kind out in the merge-row encoder The encoder stands in for the executor that hands merge_row its input, and it was calling native::state::state_kind to name the kind. #10408 deletes that helper along with the other production-dead items in its scope, so depending on it makes these two changes fail to compile when they land together. The mapping is eight lines and belongs to the encoder anyway: it is the one place that has to agree with what the runtime would derive. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): answer max_of and min_of over two scalars natively (#10431) * feat(promql): answer max_of and min_of over two scalars natively Prometheus defines both as two scalars in, one scalar out (experimental), and the pinned promql-parser carries the same signature, so an instant-vector argument is already a parse error. The ScalarFunction kernel implementing Go's math.Max/math.Min -- an infinity of the function's own sign beats NaN, NaN beats any other value, +0 beats -0 -- existed with its golden cases but was never reachable from a query. The call now binds through the existing parameterized-map tower: compile_call -> scalar_function_call -> ParameterizedOp::MaxOf/MinOf -> ParameterizedMath -> PointMath::Scalar -> ScalarFunction::apply, executed by map_math_with_parameters. Only MaxOf/MinOf take the scalar-in/scalar-out shape; round and clamp* keep their vector contract, and clamp's max < min emptiness rule moved into PointMath verbatim. A constant first argument is folded and materialized as the one chunk it stands for, so max_of(1, 2) answers 2 without reading input, and two scalars on different grids are refused rather than answered wrongly. The 64-case golden now runs through NativeExecutor for both functions instead of the kernel alone, and the by-position pairing test was un-ignored and pointed at the parameterized path. map_scalar_function, whose only caller was that test, is removed. The legacy planner is untouched: neither name was implemented there. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): keep the call dispatch's comment beside the check it describes Signed-off-by: discord9 <discord9@163.com> * chore(compat): move the from-versions window to v1.3.1 v1.3.1 has published release assets, so the compatibility check asks for it and fails on every branch that still names v1.3.0. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * refactor(promql): let the legacy histogram path read the native kernel (#10420) * refactor(promql): read the legacy histogram estimators from the native kernel `prom_native_histogram_quantile` and `prom_native_histogram_fraction` estimated from `common_query`'s `NativeHistogram` bucket walk: exponential bucket bounds computed as `2^x`, and a forward walk from the lowest bucket only. The native kernel in `histogram_eval` walks the same histogram the way Prometheus does -- the bound table in `bounds`, and a walk from the highest bucket down once a finite-sum quantile reaches the median -- so one histogram had two answers that differ in their last places. Read the `NativeHistogram` through the borrowed `HistogramView` both representations share and return the kernel's answer, mapping its outcome back onto the NaN-observation notes the legacy UDFs record. Their signatures and the notes are unchanged; only the arithmetic behind them moves. The `2^x` estimator in `common_query::native_histogram` stays for that crate's public API and is annotated as such: no PromQL path reaches it any more. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): delegate the legacy histogram arithmetic to the native kernel `prom_native_histogram_add`, `_sub`, `_mul_scalar`, `_scalar_mul`, `_div_scalar`, `_neg`, the sum/avg accumulators, `delta`/`idelta`/`rate`/`increase`, and the weighted mean that merges partial states all scaled and combined `NativeHistogram`s with that type's own reconciliation: its own zero-bucket widening, schema reduction and custom-bound intersection, over `2^x` bounds. `FloatHistogram::add`/`sub`/`mul`/`div` already implement Prometheus's rules (`addBuckets`, `reconcileZeroBuckets`, `CopyToSchema`, `intersectCustomBucketBounds`) and the native kernel's golden tests cover them, so this keeps one implementation of the semantics. `AddOutcome` folds into the existing semantics rather than being dropped: `custom_bounds_reconciled` is the intersection the kernel keeps in `custom_values`, which the callers already announce from the operands, and `counter_reset_collision` is the contradiction the kernel answers with the unknown hint the legacy arithmetic derived from two hints that disagree; both are asserted in debug builds. The public `NativeHistogram` signatures are unchanged, the sums are compacted as before so `promql_eq` and the serialized spans keep their answers, and unary minus goes through the kernel's multiplication like the other scalings. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the legacy delegation's observable answers Comparing the bridge against the kernel it calls only shows they agree today; it cannot show what either answer means. These tests pin the answers themselves. - quantile with a NaN sum over several buckets answers 32.0 with NaNSkew, because the NaN walk leaves the last bucket for the interpolation; below the rank it answers NaN with NaNResult. - an exact tie answers 1.0 through the legacy walk and 2.0 through the kernel, on a fixture with an empty bucket between the two, and neither records a note. - assert_same_payload now compares every field, including the start timestamp policy, custom values, the complete span segmentation and the bucket bits. - round-tripping preserves reset hints, custom values, zero-length spans and gaps. - add/sub reconcile the reset hint and the custom bounds, compact cancelled buckets, and keep promql_eq's expanded-index equality. - scale/divide_by keep the field-by-field fallback for an unreadable layout -- mismatched counts, a backwards span, an overflowing index, a negative length -- and preserve its start timestamp; add/sub answer None for the same layouts. Zero, negative and NaN factors are pinned. - rate/increase/delta/idelta/irate clear the start timestamp of a derived histogram, while a single-sample sum aggregate keeps its stored one. A layout whose later span steps backwards is refused before the kernel sees it: the legacy bucket_indices rejected it, while side_from_view would have accepted repeated indices. Signed-off-by: discord9 <discord9@163.com> * test(http): pin the legacy histogram route's rate, NaN quantile and derived windows The delegation changes what three kinds of well-formed data answer, so assert it where a user sees it. Every request runs without the native hint and asserts !executes_fused_series on the observed plan, which proves the legacy route rather than assuming it from the missing hint. - rate and increase over a raw sample with a start timestamp inside the window still extrapolate from the synthetic zero: count 8/3 and sum 10/3 for a rate, 8 and 10 for an increase, with no infos or warnings. - histogram_quantile(0.5) over schema 0, buckets [8, 1], count 10 and a NaN sum answers 32.0 and reports the NaN-observation info, matching Prometheus's walk that leaves the last bucket for the interpolation. The previous estimator answered 2^-0.375. - rate over a raw window answers one series while the same window over h*1 answers none: the derived sample carries no start timestamp, so it has no synthetic zero to extrapolate from. Both phases are covered, memtable and flushed SST. The native-histogram test now installs the route interceptor the way its sibling tests do, so the plan can be observed; all of its original assertions are unchanged. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * test(promql): stop deriving budget expectations from the estimator (#10409) About fourteen accounting/reservation tests computed their expected figure, pool limit, or 'exactly fits' budget from operand_chunk_bytes / evaluated_bytes or a copied row-size constant, so a wrong formula stayed green. They now assert an independent behavioural property instead: a charge appears and is released to zero, an oversized operand is refused by the pool, a refused chunk leaves nothing reserved, or a bound stated in the bytes the fixture's own data holds. Ablation proof: temporarily doubling operand_chunk_bytes now fails 9 tests instead of 3, so these tests can actually catch a wrong formula. The ablation was reverted; promql 1209/1209 green, clippy clean. Signed-off-by: discord9 <discord9@163.com> * chore: drop a PR description that was committed by accident (#10463) `pr-histshared-body.md` is the body draft for #10420 and was committed along with that change. The repository root only carries the shared docs (AGENTS, CONTRIBUTING, README, SECURITY, AUTHOR), so this file has no reason to be here. Signed-off-by: discord9 <discord9@163.com> * chore(promql): drop production-dead state and sample helpers (#10408) - native/state.rs: remove ensure_bound_state and its only call site, plus the now-dead state_kind/state_components helpers (about 60 lines). - instant_eval.rs: remove the strictly-increasing re-check in select_instants; RawTimestamps::try_new already enforces the order. - native/split.rs: the Window arm declines on input_grid.is_none(); the declared-vs-input grid equality is already enforced when the window is bound (native/plan.rs). - datatypes/series/samples.rs: remove Samples::into_dense and its arrow_result helper; only datatypes tests called it. The eight densification tests existed only to exercise it and go with it. Verified: promql 1209/1209, datatypes 402/402, clippy -D warnings clean. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): move the segmentation engine into the promql crate (#10418) Lands the segmentation-engine move together with the uniform native-PromQL topology it builds on (#10321), which this branch carries as its base. * refactor(promql): share the extrapolation factor between float and histogram windows (#10425) * refactor(promql): share the extrapolation factor between float and histogram windows A native histogram counter can carry a start timestamp inside its window, which the histogram range path turned into a synthetic zero and extrapolated from with its own inline millisecond-domain formula. The float path already computed the same factor in extrapolation_factor, so the two routes could drift apart: the histogram branch counted the synthetic zero as an extra sample interval and extrapolated towards zero from a negative first count. The factor now takes an ExtrapolationSpan with two anchors -- sampled_from, where the increase was sampled, and average_from, where the average sample distance is measured. A float window sets both to its first sample; a histogram window starts the sampled interval at the synthetic zero and keeps the average on the real samples. A synthetic zero is the counter's zero point, so it is expressed as zero_point = Some(0.0), which reproduces the removed duration_to_start = 0.0 exactly. The sampled_interval == 0 divergence is deliberate and documented: a float window keeps its increase with a factor of 1, while the histogram window answers no value, since its buckets are all zero and an Inf or NaN rate would only poison its consumer. Signed-off-by: discord9 <discord9@163.com> * test(promql): make the two-anchor extrapolation tests able to fail Each of these could only pass: the route-equality table gave both fillings the same anchors, and the synthetic-zero geometry kept its ends under the threshold with the average anchor taken either way, so an anchor swap answered the same 1.375. The table now also carries a window whose anchors differ, pinned to 1.5 for the histogram filling and 1.75 for the float one, so collapsing the sampled anchor onto the average fails. The synthetic-zero test uses zero 1000, samples 2000/3000, eval 4500, range 4000: correct is 1.25, and measuring the average from the zero gives 1.75. Both numbers are asserted, and a temporary anchor swap was confirmed to fail the test before it was reverted. Signed-off-by: discord9 <discord9@163.com> * test(promql): give the synthetic-zero range test anchors it can tell apart The 1.375 geometry answered the same with the average anchor measured from the synthetic zero, so the end-to-end test agreed with itself either way. It now uses zero 1000, samples 2000/3000, eval 4500, range 4000: the count is (4 - 2) + 2 = 4, the factor 1.25, so an increase answers 5.0 and a rate 1.25, while a swapped anchor answers 7.0 and 1.75. The swap was applied to the production call site temporarily and failed the test with "Increase over two samples: 7 vs 5" before it was reverted. Signed-off-by: discord9 <discord9@163.com> * test(promql): give the two-anchor window geometry that can fail both ways The previous geometry had its end inside both thresholds, so an average interval read from the sampled anchor answered the same 1.5 as the correct one; only a sampled interval read from the average anchor changed the answer. With zero point 2000, average 2500 and last 4500 the end is past the correct threshold (2.2s) and inside the wrong one (2.75s), so it truncates one way and not the other: the correct answer is 1.4, an average anchor read from sampled gives 2.0, and a sampled anchor read from average gives 1.5. Both mutants are pinned as assertions, and both were applied to the production formula to confirm this test fails on them. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * refactor(mito2): drop the unreachable samples builder and the unused prepared-series contract (#10430) * refactor(mito2): drop the unreachable per-SST samples builder Production only ever constructs the columnar samples format: SeriesFormats::from_config is reached from with_format with experimental_series_index_format, where Legacy yields no samples backend and Columnar yields ColumnarSamplesFormat. The other SamplesFormat impl is cfg(test). So the per-SST branch of the maintenance task could never run, and build_samples had no caller but its own test. The daily columnar body is now unconditional, and the former branch position holds an explicit UnsupportedOperation error so an unknown backend fails loudly instead of building nothing. The two fake-format lifecycle tests were duplicates of real_samples_reconcile_reopen_and_retire, which drives the same build/reuse/reopen/ catalog-failure/purge scenario against the real format; the abort test moved to build_sample_windows, and a new test pins the refusal. The compatibility fixtures are untouched and still pass. Signed-off-by: discord9 <discord9@163.com> * test(mito2): cover retirement after a successful samples rebuild format_skeleton_build_reopen_and_retire was the only test of the retirement that follows a successful rebuild; real_samples_reconcile_reopen_and_retire covered the failed-publish path only. Removing the samples loop's mark_deleted() from publish_index_version left every other series_index and series_scan test green, which is what made the gap invisible. The real-format test now also rebuilds a day by deleting one of its objects, checks that the superseded generation is no longer in the published snapshot, that nothing is purged while the old snapshot and its handle are alive, and that its objects are purged once they are dropped. With mark_deleted() commented out, all four cases fail on that last assertion. Signed-off-by: discord9 <discord9@163.com> * test(mito2): pin the purge to the last reader handle, not the snapshot Dropping the published snapshot was allowed to release a superseded generation as long as one of its handles was still held elsewhere, which no test covered: the retirement assertions only checked that nothing was purged while the snapshot lived, then dropped every handle at once. The test now holds a reader handle on every generation the superseded snapshot published before releasing it, so that release must purge nothing, and asserts that between the two drops. A rebuild replaces several generations of a source group at once, so holding only the one the test tracks would let its siblings be released legitimately and the assertion would fail for a reason unrelated to the lifecycle under test. A mutation that purges on snapshot drop -- ignoring live reader handles -- fails this new assertion in all four cases and none of the later ones. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * docs(promql): trim design-narration comments in native planner and runtime (#10421) Comment-only cleanup on top of the segmentation move (#10418) and the topology it carries (#10321). * test(query): pin the plan shapes the uniform topology builds (#10466) * test(query): pin the aggregate plan shapes the uniform topology builds Four native-aggregate integration tests have failed on `narthex` since the uniform native PromQL topology landed (#10418): their plan-shape helpers demanded the pre-topology chains, panicked before the native-vs-legacy comparison ran, and nextest's fail-fast then left most of the suite unexecuted. Both shapes the helpers now see are the topology's own: - a Partial producer the analyzer keeps above the regions reads the `MergeScanExec` through one `SeriesRepartitionExec` that widens the region stream to `target_partitions` with `RawPrimaryKey`, so each stored key still reaches exactly one owner; - a single-owner Final reads the Partial producer itself through its state router, instead of a region merge scan, because both halves are planned in the frontend tree now. Pin each chain exactly rather than accepting any exchange, and run the legacy comparison before the shape assertions so a shape regression can no longer hide the result check. Verified: native_aggregate 6/6, native_promql 90/94 (the four `integration_http_s3*` cases abort for environment reasons), clippy and fmt clean. Signed-off-by: discord9 <discord9@163.com> * test(query): read one raw source per selector occurrence in the CTE case `cte_native_statement_runs_the_fused_plan` asserted that one logical table keeps both occurrences of a repeated selector region-local, so no raw source appears in the plan. The uniform topology reads every selector through its own raw source, so the statement now names two. Pin that instead: both occurrences still read their own region scan, and each does it through a raw source of its own. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * fix(test): stop requiring every scan partition to be non-empty (#10469) `SeriesRepartitionExec` routes a series by hashing its label set, so the eight series this test writes over four partitions can legitimately leave one empty: the fixture happened to hash evenly before, and it no longer does (`{0: 0, 1: 3, 2: 3, 3: 2}` on `narthex`). Requiring every partition to be non-empty asserts a property of the hash, not of the topology. What the test actually needs is that the series are spread over more than one partition - otherwise the merge it exists for is never exercised - and that routing loses none of them. Assert those instead, and keep the existing "all four partitions reported" check. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover unequal-width owner routing and scalar broadcasts (#10039) Signed-off-by: discord9 <discord9@163.com> * test(query): prove a default engine option keeps native requests on the legacy route (#10459) The engine-wide `experimental_native_promql` option is the outer gate. #10371 pinned its default, but nothing showed what that default does to a request that explicitly asks for the native route — which is the case that actually matters when the branch is merged back: a client can always send the per-request extension, and the engine option is the only thing left deciding. `plan_native_promql_with_query_options` always sets `query.experimental_native_promql=true` on the request, so passing `QueryOptions::default()` covers exactly that combination. The assertion looks at the rendered plan for both `FusedSeries` and `RawSeriesSource`, so a future change that lets the request alone admit the route fails here. Signed-off-by: discord9 <discord9@163.com> * feat(promql): name native result columns from expressions (#10231) Use the statement expression for native value column names, resolve legacy value columns by type rather than by name, and reject label-function destination collisions instead of dropping a value. Keep matrix roots named after the whole statement, preserve an Int64 __tsid value, and propagate schema-collision errors from canonical boundaries. Signed-off-by: discord9 <discord9@163.com> * refactor(promql): decide native admission with an enumerable predicate (#10424) Admission to the native PromQL route was decided by trial-building the whole runtime tree and discarding it, at five call sites of NativeExecutionState::try_new(...).is_err(). That is where the refusal lived, not anywhere enumerable. Replace those calls with native_tree_supported(&tree), a predicate on the compiled tree's shapes that builds no runtime: it declines the nine shape classes RuntimeNode::build rejects (raw-sample roots, interleaved inputs, scalar() over a multi-field vector, non-performable broadcasts, quantile aggregates, value-field groupings, vector ops over multi-field vectors, top-k variants, and unsupported window modifiers). try_new keeps its construction-time validation for the refusals that are not shapes. Which queries reach the native route is unchanged; the new tests assert both the predicate's verdict and that the runtime agrees. Verified: promql 1211/1211, query 1130/1130, native_promql 93/93, clippy -D warnings clean. Signed-off-by: discord9 <discord9@163.com> * feat(promql): fold pi() and answer quantile as a complete aggregate (#10433) * feat(promql): fold pi() and answer quantile as a complete aggregate pi() folds through constant_value like any other constant, so pi() * x, clamp_max(x, pi()) and quantile(pi()/4, x) all compile natively. The value is std::f64::consts::PI on both routes. Note this is wider than the legacy planner, which does not treat a call as a literal and so rejects those parameter positions; it is an extension of constant support, not a narrowing. quantile now binds a Complete fold that retains the group's input and answers with the existing aggregate_quantile kernel. A quantile has no partial kernel, so split.rs and the state binding are untouched and a Partial/Final quantile cannot exist: validate refuses it and check_cut declines the cut. A partitioned input therefore gathers above per-series prefixes instead of folding per partition, which is the only correct distributed shape for a non-associative aggregate -- the raw-source boundary keeps fragments from being read as whole series, and the router merges a raw identity once every input reaches EOF. The retained input is not a fixed-width state: a quantile keeps every group until EOF and cannot spill, so it is bounded by pool admission, which the module doc now states. Its parameter is sparse, covering the grid positions the input actually holds rather than the window they span. Two points 100k positions apart used to allocate an 800KB dense parameter before any admission; now the parameter and the kernel's position/value copy are charged by row bound before allocation, and retaining a series reserves the Vec capacity it is about to grow to rather than one slot. A test runs two distant points under a 64KiB pool and finishes with nothing left reserved. quantile over a histogram no longer falls back: the legacy planner groups it with min, max, stddev and stdvar, skipping histogram samples and reporting an info, so the admission check now refuses only sum and avg, which fold the payload. The native runtime asserts the same info as min over a histogram-only chunk. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bill a quantile's retained chunks the way a binary operand is billed series_bytes charges the whole Arrow parent buffer a slice points into, and every histogram table it references, so a series handed over as many slices of one buffer was charged once per chunk: two thousand one-row slices of a 16 KB array came to ~32 MB against a 4 MiB pool and were refused around the 260th, while min over the same input answered. Retained chunks are now billed as a binary operand bills its operand: operand_chunk_bytes measures what each chunk holds on its own, with the parent buffer counted once across its slices, and unbilled_tables bills each histogram table once, remembered by allocation address. QuantileInput::bytes() reports real residency -- its own size, the vector's capacity and the folded held bytes -- instead of a per-chunk sum, so every resize settles on what the node actually keeps. The capacity pre-booking stays and is kept out of held, so a vector slot is not charged twice. The regression hands one array over as 2000 single-row slices under a 4 MiB pool and asserts min and quantile answer the same and both return their reservation. Restoring the old billing makes it fail with ResourcesExhausted, which is the failure it exists to catch. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bill a quantile's retained input once per allocation The previous change stopped charging every chunk for the whole parent buffer, but the figure was still not self-consistent in three ways. operand_chunk_bytes subtracted the whole of fields_bytes() and added back only the row bytes of the slice, so a small slice of a big buffer was billed as small while the whole allocation stayed resident, and a validity bitmap was not counted at all. Retained chunks are now billed per Arrow allocation, keyed on the buffer's data pointer and charged at capacity, the same way unbilled_tables bills histogram tables. The no-identity alternative -- bill every chunk for the whole buffer -- over-estimates and would refuse a legal query, which is the reported bug mirrored. series_bytes includes size_of::<Series>(), and QuantileInput::bytes() also counted every vector slot, so each used slot paid for its Series twice. The chunk figure now carries only what sits beside the samples and the struct is left to the vector. pending() returned the incoming chunk's figure for every fold, but the quantile retainer books its own figure before the push, so that backing was reserved twice and could refuse a query before any memory was actually held. finish_quantile also settled on the output while its input was still alive by value; it now drops the input first. Billing only; no answer changes. A 2000-chunk input goes from 1,757,960 to 1,181,968 bytes (the 2000 x 288 of double-counted structs plus one 16 KB allocation billed once), and every quantile billing test ends with the pool empty. Five mutations -- rows-only figure, no buffer dedup, per-chunk series_bytes, grid-wide parameter, struct added back per chunk -- each fail the test that covers them. Signed-off-by: discord9 <discord9@163.com> * test(promql): cover a quantile over no input and drop its redundant guards A quantile whose input holds no sample in range has no positions to build a parameter from, so it hands the kernel an empty scalar and answers nothing. No test reached that: replacing the fallback with an error left every quantile and aggregate test green. The new one runs the node without pushing a chunk at all and asserts an empty answer with the pool back to zero. new_quantile also re-checked the stage, the kind and the grid. validate already refuses a Partial or Final quantile -- aggregate_state_binding has no state for one -- and the node's schema is the tree's validated output, so those checks could not fire. The quantile is now passed in from the arm that destructured it. The billing test's comment described the operand_chunk_bytes model; the quantile bills chunk_bytes_beside_samples plus the Arrow allocations its slices point into. Signed-off-by: discord9 <discord9@163.com> * test(promql): answer a quantile over a multi-input tree instead of declining it quantile stopped being a kind the runtime refuses, so the query that pinned that refusal now answers natively. It moved out of the declines test into its own case, which asserts the existing plan answers 3/16, that the route plans a fused node for it, and that the native rows equal the legacy ones. The grouping-by-a-value-field case stays where it was. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * feat(promql): show the native tree as plan lines with per-node metrics (#10202) feat(promql): draw the native tree as plan lines with per-node metrics The fused node prints its own compiled tree instead of echoing the PromQL text it was built from: one node per line inside a `native_tree=[ ... ]` block, with each node's figures on its own line when the statement ran. A split aggregate's two halves therefore show the trees they compute rather than the same statement, and EXPLAIN/ANALYZE of a native statement reads like the plan it runs. The statement text stays on the node as data: it is what names the value columns (`expression_field_names`), so it has to survive to execution and over the wire where a node is rebuilt from its envelope. What changes is that it is no longer what the node prints. The tree's registrations sit in the node's own metric set, so a reader that keys by name reads that set; `ExecutionPlan::metrics` leaves them out because a flat set cannot say which node recorded what. Signed-off-by: discord9 <discord9@163.com> * perf(promql): cut per-series fixed costs in decoding, packing and accounting (#10416) Signed-off-by: discord9 <discord9@163.com> * feat(promql): take the native route's switch from the query options (#10262) The unified query option mechanism is already in this branch's base, so what is left is the native route reading it: the switch resolves once in apply_query_options as request over session SET over the engine default, and both the planner and SHOW read that resolved value instead of combining the engine option with the request extension themselves. The engine-wide option therefore stops being a gate a request also has to pass and becomes the default a request or a session states over, which is what the other query options in this crate already do. What that costs is stated rather than implied: an operator can no longer switch the experimental route off for clients that set query options, and none of the entry points (HTTP hints, gRPC context, SET) carries an authorization check of its own. Data permissions are unaffected - the statement still plans through the same scanners and the same per-table checks. #10459 asserted the old gate; its test is rewritten here to pin the new contract in both directions instead of being dropped. Metric discovery stops keying off the request extension for the same reason: a session SET or the engine default can turn the route on without one. It reads the switch through the same resolver planning reads, so a query that leaves the route off is not bounded for discovery and pays no per-table grant for it. Signed-off-by: discord9 <discord9@163.com> * fix(test): render the schema view in the quantile fold test (#10479) #10202 changed what `display_indent` shows: plan lines with per-node metrics, without the statement. `native_fused_quantile_is_never_folded_per_partition` asserts the statement is still named by the quantile it wrote, so it now reads `display_indent_schema`, which keeps rendering it. This is the only assertion in the file that depends on the statement text; the other `display_indent` call sites assert plan structure. Every PR based on `narthex` currently fails this test. Signed-off-by: discord9 <discord9@163.com> * feat(promql): fold and average native histograms in the native aggregate (#10199) * feat(promql): carry a native histogram in aggregate state `sum` and `avg` over native histograms need a partial state whose payload is variable width, which the numeric state family cannot express. Add two kinds, `histogram_sum` and `histogram_avg`, whose components are a live histogram, a layout-carrying compensation, and the evidence a merge records. A position's payload is one `StatePayload`, either the numeric components a float kind carries or a boxed histogram state, so absence stays a single `None` and a field never holds both families. The numeric encoding is byte for byte what it was, and a histogram component nests the same struct a histogram sample frame already uses. The compensation must carry the live value's bucket layout: the kernel indexes it by the value's positions, so a placeholder without bucket indices would be an out-of-bounds read rather than a loss of precision. Both the producer and the decoder check the schema, the zero threshold, the custom bounds and the expanded logical bucket indices, which accepts two spellings of the same buckets and refuses two different layouts. State accounting charges the payload's real width instead of a fixed slot, so a wide bucket layout is paid for. `HistogramSum` cannot declare `incremental_mean`, which is checked structurally: a sum has no mean mode. No admission, split or runtime wiring yet; nothing produces these states until the aggregate kernels land. Signed-off-by: discord9 <discord9@163.com> * feat(promql): fold native histograms into a `sum` aggregate `sum` over a native histogram now folds in the native aggregate: the first sample at a grid position establishes the accumulator from a layout-carrying zero compensation, and every later one is added with a compensated add whose receiver is the live value. The evidence the final answer needs is recorded as it appears: set when a merge reconciled custom bucket bounds, and both reset-hint bits when samples reported a reset and reported that none happened. Two layouts that cannot be added - exponential and custom buckets in one position - poison the point, which the final answer drops instead of answering a partial sum. A numeric overflow is not a fault and does not poison anything: `sum` answers `Inf` when its cumulative sum saturates, exactly as the kernel's own sum does. `avg` keeps refusing a histogram: its mean mode needs the merge rules, which are not part of this change. A group that kept histogram payloads now refuses to export a partial numeric state rather than exporting an empty one. Signed-off-by: discord9 <discord9@163.com> * feat(promql): average native histograms in the native aggregate `avg` over a native histogram folds the same way the v3.15.0 kernel averages a range: sum with compensation while the sum fits, then switch to a running mean once the next add would overflow. The switch keeps the answer finite where the sum would not be: two histograms whose scalar sum is `1e308` each average to `1e308`, not to `Inf`. It starts the mean from the sum accumulated so far divided by the samples that produced it, and weights every later sample by the fraction of samples it represents, so the compensation is scaled by the same weight as the value it belongs to. The complete answer divides both the sum and its compensation by the sample count, or answers the mean with its compensation. `start_timestamp` is cleared and the payload compacted, as every other derived histogram is. No operation refuses a histogram sample any more, so the refusal variant is gone rather than left unused: what a fold accepts is decided by its arithmetic, not by the sample's type. Signed-off-by: discord9 <discord9@163.com> * feat(promql): merge native histogram state across a split A split aggregate exports its partial state and folds it somewhere else, so a histogram fold has to travel. The binding now says which layout a node carries: `aggregate_state_binding(kind, field_kind)` picks the histogram family for a histogram input and the numeric family otherwise, and `BoundAggregate` records the kind its direct input answers with, decided where the node is bound. The partial half exports the live histogram, the compensation that carries its bucket layout, and the evidence the merge needs; a sum cannot claim a mean mode because its kind has no such component. The final half merges two partials the way the v3.15.0 kernel merges contributions: two compensated adds for a sum, and a mean path that converts each side, turns its count into a weight, and scales before adding so that a pair of `1e308` histograms still averages to `1e308`. A sum/sum pair first runs the same trial the complete fold runs, and only keeps it when it does not overflow. An unreconcilable layout poisons the point in either partial: the merge keeps it poisoned and never revives it, and the answer drops that point. Evidence is merged bit by bit, including from a poisoned side, so which annotation fires does not depend on the merge order. The node that finishes the answer is the only one that reports: `Complete` and `Final` speak after their output is queued, `Partial` stays silent because its evidence travels in the state. A poisoned point suppresses its reconciliation info, which is what makes the message set order-independent. Signed-off-by: discord9 <discord9@163.com> * feat(promql): admit a native `sum` and `avg` over histograms A payload-folding aggregate is now admitted exactly when it binds histogram state: `sum` and `avg` over a native histogram fold and merge their own state, so the gate that refused every such input now asks what the node will build rather than what its input carries. Their answer column is the canonical histogram struct; `count`, `group`, `min`, `max`, `stddev` and `stdvar` keep answering floats whatever they read. The split may carry a histogram answer when the cut aggregate exports histogram state. That is also what makes the state schema's value column count follow the kind, which a histogram split otherwise failed against. A histogram fold the split declines is not segmented. Segmentation answers a group by folding each segment and appending the pieces, so a point whose contributions are spread over partitions would be folded once per segment - a sum would merge histograms that never met, an average would average averages. The whole statement therefore keeps the plan it had, which also covers an aggregate above an aggregate and a whole-vector ranking above a fold: neither can cross the split boundary, and cutting them would answer a piece no segment owns. Multi-input histograms and a histogram behind a canonical merge keep their refusals: the state crossing a canonical boundary has no execution coverage. Signed-off-by: discord9 <discord9@163.com> * test(promql): read a native histogram sum and average over HTTP Three cases write native histograms through Remote Write 2.0 and read the answer back through the Prometheus query API. Each one asserts the native route really executed: the observer records the split's two fused producers, and the one publishing a histogram column is the final consumer, so a statement that fell back to the existing plan cannot satisfy the test. `sum` and `avg` answer the values the v3.15.0 kernels produce, and both are compared against the same query without the native hint. That comparison uses a relative tolerance for `avg` and an exact one for `sum`, because the existing plan averages by weighting each sample (`12 * (1/3)` is one ulp below `12 / 3`) while the native fold divides at the end - the difference this change documents rather than hides. The partitioned case flushes after every write so the scan really splits, then asserts the partial producer reported output in more than one partition and that the same query at parallelism one answers the same JSON. Two layouts in one metric remove the group and report it: the answer is empty and the response's warnings name the incompatible layouts, asserted after the native nodes are known to have run. Signed-off-by: discord9 <discord9@163.com> * fix(promql): decide a reset collision per point and pin the avg merge weights The contradictory-reset warning was decided from the two evidence bits OR-ed across every group and every point, so sum by (job) (h) with CounterReset only in job a and NotCounterReset only in job b warned, as did one series crossing its reset over a range. Prometheus checks counterResetSeen && notCounterResetSeen per group per step, so the bit is now decided per accumulator and only the decision is OR-ed across the answer. The state layout is untouched: it still carries the two raw bits, and the collision is settled when the answer is. Nothing caught a swapped pair of avg merge weights: the existing overflowing-pair test gives both partitions one sample and the same mean, so both weightings answer 1e308. The new case merges a two-sample partition that switched to a mean with a six-sample one that still sums, weights 2/8 and 6/8, and asserts 7 * 2^1019; swapping the weights answers 13 * 2^1019 and fails. Signed-off-by: discord9 <discord9@163.com> * test(promql): merge histogram partials through the accumulator, not a row encoder The eight histogram merge tests drove their partials through a test-side encoder that writes numeric state rows, so they panicked the moment a state carried a histogram payload. That encoder never produced a histogram row for anyone: the merge they want to check is the one HistogramAccumulator::merge_state performs, and the row path is the executor's. They now merge the payloads directly -- from_payload for the first, merge_state for the rest -- and read the answer through finished_histogram and the evidence through the production summary. Every assertion keeps its value and strength: the unequal-count case still asserts 7 * 2^1019, so swapping the merge weights answers 13 * 2^1019 and fails, and the evidence case still fails when the merge order decides the result. Signed-off-by: discord9 <discord9@163.com> * test(promql): drive histogram state rows through merge_row The cross-partition merge reads each partition's state frame as a StateRow, and merge_histogram_row is the code that decodes a histogram payload out of one. No test reached it: the numeric row encoder panics on a histogram, and the histogram merge cases go through the accumulator instead, so a bug in that decode -- a swapped component, a poison bit lost, a field index off by one -- would have left every test green. These construct StateFieldsBatch rows directly and merge them. Sum and the average's mean path assert the same bits the accumulator answers for the same payloads, so the two paths cannot drift; a poisoned row is asserted to poison the point; a row missing a component and a row whose compensation carries another bucket layout are asserted to be refused rather than answer something. Dropping the poison bit, not decoding the mean mode, and reversing the field index each fail one of them. Signed-off-by: discord9 <discord9@163.com> * fix(promql): bind an aggregate's state from the statement's own field kind The rebase replayed the compiler call with a literal Some(FieldKind::Float) for the statement's source kind, so every aggregate bound float state: sum over a native-histogram column asked the gate whether it folds a payload, answered yes, and the statement fell back to the legacy plan with prom_native_histogram_agg_sum in it. The call now passes statement_kind, the kind the prepared scans report for the statement's fields. The duplicate guard on the segmentation path -- which refused every histogram fold rather than only the ones the split declined -- is removed, and the mutation scripts the earlier commits picked up are dropped. Signed-off-by: discord9 <discord9@163.com> * test(http): register the three native histogram aggregate cases Splicing the range test and this branch's cases together during the rebase kept the function bodies but dropped their http_tests! entries, so the three cases existed without ever running. Signed-off-by: discord9 <discord9@163.com> * test(promql): identify the histogram column by type, not by name Native result columns are named after their expressions now, so the three admission tests that looked for a column called greptime_native_histogram found none in a plan that answered exactly the histogram they meant to check. They look for the histogram value type instead, which is what the assertions were about. Signed-off-by: discord9 <discord9@163.com> * test(http): find the histogram answer by type and allow an empty scan partition `answer_consumer` looked for a column named `greptime_native_histogram`, which the answer is no longer called now that result columns take their expression's name (#10231). It reads the histogram value type instead, and only the schema's own fields: a state frame keeps its histogram inside `fields`, so a top-level type check still finds the consumer and not the producer. The partition case also required every scan partition to hold rows. Routing hashes each series' label set, so eight series over four partitions can leave one empty; #10469 stopped asking for non-empty partitions elsewhere and `test_remote_write_v2_histogram_native_range_function` already reads the same fixture this way. The producer still has to run on more than one partition, and the answer still has to count every series once. Signed-off-by: discord9 <discord9@163.com> * fix(promql): carry the histogram fold onto #10433's bound aggregate Rebasing onto #10433 left three things behind. `BoundAggregate` gained `field_kind`, which the quantile tests construct without; the value is `Float` because those fixtures hand the fold float samples, and the one call to `aggregate_state_binding` now names the kind it asks about. `native_composed_binary_admits_complex_operands` also expected `hist * on(tag_0) sum by (tag_0) (hist)` to fall back, for a reason this branch made false: it said `sum` has no histogram state to fold into. It has one now, so the pair composes. `histogram * histogram` is not an error in Prometheus - only `+` and `-` apply and any other operator removes the element with an info annotation - so the composed pair is admitted and keeps the legacy float layout for the answer no sample can fill. The test asserts that shape instead, and the refusal it still checks (`sum(sum(hist))`) is named for what refuses it: the split cannot carry an aggregate above a split aggregate. Signed-off-by: discord9 <discord9@163.com> * fix(promql): carry the histogram fold onto #10202's plan-line display `BoundAggregate.field_kind` again: the display test's `sum(rate(...))` builds one without the field, and its input is a histogram, so the field says so. `native_fused_quantile_is_never_folded_per_partition` looked for the statement's text in the display to show the fold is still named by the quantile it wrote. #10202 renders the tree as plan lines instead, so the quantile is named by its own line - `Aggregate: quantile 0.5` - and that is what the assertion reads now. Signed-off-by: discord9 <discord9@163.com> * style(http): keep the answer-column doc off a list item The first line of the histogram sentence ended on a hyphen, so the next line began with one and clippy read it as an unindented list item. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * test(promql): pin the existing route when a fixture defaults to native (#10484) The three native-route tests turn `experimental_native_promql` on in the standalone's query options, so the "legacy" request that follows the native one also takes the native route. The comparison then checks the native answer against itself, and the observer collects both runs: `sum_and_avg` expects the split's two nodes and saw four. Ask for the existing route explicitly with `x-greptime-hints: query.experimental_native_promql=false`. Signed-off-by: discord9 <discord9@163.com> * perf(promql): stop building label-set tables where they cannot collide (#10412) * perf(promql): stop building label-set tables where they cannot collide A `Window` node used to hold an Emitted table of the label sets it had already published, so that a statement dropping the metric name could still keep two series apart when their remaining labels were identical. Every window paid for that table whether or not it could ever collide: a plain `rate()` over a table whose tag columns are nullable had to collect and merge for its whole life, because the table could not prove two series would not fold into one. The table is gone. The proof moved to plan time: a drop that cannot collide - one metric, and no `__type__`/`__unit__` tag to lose - needs no `Merge`, and any other shape gets a canonical `Merge` inserted where the drop happens. The canonical merge kernel already answers the collision, so the runtime no longer carries an occupancy set to detect one. A decline now records why it declined, which is what tells the two paths apart in metrics. Signed-off-by: discord9 <discord9@163.com> * test(promql): pin that a drop above a name-dropping kernel needs no merge `rate(x[5m]) * 2` plans one window and one broadcast, and `abs(abs(rate(x[5m])))` one window and two maps; neither plans a merge, because the metadata labels are all the drop can lose and the labels proof covers them. The review asked for these two shapes by name: with the labels proof forced to answer `false` the test reports `left: 0, right: 2` for the first, which is the count it planned before. Signed-off-by: discord9 <discord9@163.com> * fix(promql): make the metadata drop's proof ask the storage keys `drop_metric_name` also drops an empty label value (`map.rs:367-368`), so two stored series that differ only in `{zone=""}` versus no `zone` become one label set after a name-dropping kernel. The labels alone cannot see that pair, so the proof was incomplete: a nullable key column let the pass insert no `Merge`, and the runtime then emitted two series of one label set instead of reporting `vector cannot contain metrics with the same labelset`. The proof now asks `keys_survive_metadata_drop` - the rule the physical scan already reads - and a `Merge` at or below the drop answers its empty-value half, so a chain of drops over a nullable table pays one collection at the bottom rather than one per drop. Every GreptimeDB tag column is nullable today, so that boundary is what a real table gets. A canonical merge carrying histogram frames was the one pairing nothing exercised, and the extra boundary made it reachable: the gate that declined it is gone. A histogram statement now crosses the boundary - a producer per partition, a consumer above the router - on the merge kernel's own `SampleRef::Histogram` arm, which is where the duplicate this fix is about is reported. That crossing is covered by an HTTP case over a nullable tag, and by `Merge` coverage for complementary positions, overlapping positions, missing samples and sliced payloads, the evaluated frame's histogram and mixed encodings through producer, router and consumer, a float-producing histogram function below a nested boundary, and the segmented plan. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <discord9@163.com> * revert(promql): revert #10412, merged without approval (#10495) Revert "perf(promql): stop building label-set tables where they cannot collide (#10412)" This reverts commit1fd9069418. * revert(promql): restore #10412, undoing the revert (#10497) Revert "revert(promql): revert #10412, merged without approval (#10495)" This reverts commit3f8d718a30. * revert(promql): revert #10412 again, unreviewed changes included (#10500) Revert "revert(promql): restore #10412, undoing the revert (#10497)" This reverts commit405c2f9016. * test(promql): read the partition producer's node metrics from the plan's own set (#10501) `test_remote_write_v2_histogram_avg_native_partitions` read the producer's per-partition `native.root.output_values` through `ExecutionPlan::metrics`. `FusedSeriesExec::metrics` drops node metrics on purpose - `is_node_metric` covers `native.root.*`, so the operator's set reports only its own figures - and the map stayed empty. The assertion then saw zero partitions where the statement asks for four. Read the plan's own set through `node_metric_set`, which is how the other node-metric assertions in this file already do it. Signed-off-by: discord9 <discord9@163.com> --------- Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> Signed-off-by: discord9 <discord9@163.com> Signed-off-by: discord9 <discord9@users.noreply.github.com> Signed-off-by: WenyXu <wenymedia@gmail.com> Signed-off-by: Dennis Zhuang <killme2008@gmail.com> Signed-off-by: evenyag <realevenyag@gmail.com> Co-authored-by: Weny Xu <wenymedia@gmail.com> Co-authored-by: Dennis Zhuang <killme2008@gmail.com> Co-authored-by: Yingwen <realevenyag@gmail.com>
Sqlness Test
Sqlness manual
Case file
Sqlness has two types of file:
.sql: test input, SQL only.result: expected test output, SQL and its results
.result is the output (execution result) file. If you see .result files is changed,
it means this test gets a different result and indicates it fails. You should
check change logs to solve the problem.
You only need to write test SQL in .sql file, and run the test.
Case organization
The root dir of input cases is tests/cases. It contains several subdirectories stand for different test
modes. E.g., standalone/ contains all the tests to run under greptimedb standalone start mode.
Under the first level of subdirectory (e.g. the cases/standalone), you can organize your cases as you like.
Sqlness walks through every file recursively and runs them.
Kafka WAL
Sqlness supports Kafka WAL. You can either provide a Kafka cluster or let sqlness to start one for you.
To run test with kafka, you need to pass the option -w kafka. If no other options are provided, sqlness will use conf/kafka-cluster.yml to start a Kafka cluster. This requires docker and docker-compose commands in your environment.
Otherwise, you can additionally pass the your existing kafka environment to sqlness with -k option. E.g.:
cargo sqlness bare -w kafka -k localhost:9092
In this case, sqlness will not start its own kafka cluster and the one you provided instead.
Run the test
Unlike other tests, this harness is in a binary target form. You can run it with:
cargo sqlness bare
It automatically finishes the following procedures: compile GreptimeDB, start it, grab tests and feed it to
the server, then collect and compare the results. You only need to check if the .result files are changed.
If not, congratulations, the test is passed 🥳!