Skip to content

Top-k results drop the item columns (port/job); heavy-hitter candidates resolve columns by name #672

Open

Description

@zzylol

Problem

A ranked top-k query loses the columns that say which items are ranked.

Related problem in candidate composition (#575)

The top-k sketch update in composition uses the sample value as its weight, and the composed heavy-hitter candidate (e.g. CmsWithHeap on the top-k target) resolves its item and value columns by name:

  • with an Int64 key or several keys (GROUP BY host, port), composition fails with "summary input column does not resolve";
  • with a key column named value, the summary would read the key as the value.

Expected

The top-k output schema is [partition keys.., item columns.., ranked value], with the original names (SQL: port, c; PromQL: the labels plus value).

  • Canonicalization keeps the item columns.
  • Composition's sketch update takes its item from the item columns and its weight from the ranked measure (the count or sum), not by name.
  • Physical ASAP-aware optimization (exact Sort + Limit) and every summary candidate return that same schema.

Done when

  • The SQL and PromQL queries above return the item columns in every candidate, and the results match DataFusion and Prometheus semantics.
  • Heavy-hitter sketch candidates compose for Int64 keys, multi-column keys, and a key named value.

Found in the #576 review. Related: #575, #576, #645, #669 (top-k membership guarantee).

Activity

  1. zzylol commented on Oct 13, 2026

    @zzylol
    ContributorAuthor

    Related, found in the #576 review: when the top-k promotion in canonicalize.rs rewrites a sorted query, it discards the sort's NULL ordering. DataFusion's ORDER BY s DESC is NULLS FIRST, but physical ASAP-aware optimization rebuilds the exact sort with nulls_first: false.

    Example: in SELECT host, SUM(lat) AS s FROM t GROUP BY host ORDER BY s DESC LIMIT 5 with a nullable lat, a group whose sum is NULL comes first in the real query, but last (or not at all) in the exact candidate.

    Fix in canonicalization: either refuse to promote when the ranked measure can be NULL, or carry the null ordering into the top-k so every candidate keeps it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions