Files
greptimedb/src/query/Cargo.toml
T
discord9 1fd9069418 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>
2026-11-18 01:39:50 +08:00

100 lines
2.6 KiB
TOML

[package]
name = "query"
version.workspace = true
edition.workspace = true
license.workspace = true
[lints]
workspace = true
[features]
default = ["ai_functions"]
ai_functions = ["common-function/ai_functions"]
enterprise = ["sql/enterprise"]
[dependencies]
ahash.workspace = true
api.workspace = true
arrow.workspace = true
arrow-schema.workspace = true
async-recursion = "1.0"
async-stream.workspace = true
async-trait.workspace = true
bytes.workspace = true
catalog.workspace = true
chrono.workspace = true
common-base.workspace = true
common-catalog.workspace = true
common-datasource.workspace = true
common-error.workspace = true
common-function.workspace = true
common-macro.workspace = true
common-meta.workspace = true
common-plugins.workspace = true
common-query.workspace = true
common-recordbatch.workspace = true
common-runtime.workspace = true
common-stat.workspace = true
common-telemetry.workspace = true
common-time.workspace = true
datafusion.workspace = true
datafusion-common.workspace = true
datafusion-expr.workspace = true
datafusion-expr-common.workspace = true
datafusion-functions.workspace = true
datafusion-optimizer.workspace = true
datafusion-pg-catalog.workspace = true
datafusion-physical-expr.workspace = true
datafusion-proto.workspace = true
datafusion-sql.workspace = true
datatypes.workspace = true
futures.workspace = true
futures-util.workspace = true
greptime-proto.workspace = true
itertools.workspace = true
jsonb.workspace = true
lazy_static.workspace = true
log-query.workspace = true
meter-core.workspace = true
meter-macros.workspace = true
object-store.workspace = true
once_cell.workspace = true
partition.workspace = true
prometheus.workspace = true
promql.workspace = true
promql-parser.workspace = true
prost.workspace = true
rand.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
session.workspace = true
snafu.workspace = true
sql.workspace = true
sqlparser.workspace = true
stacker.workspace = true
store-api.workspace = true
substrait.workspace = true
table.workspace = true
tokio.workspace = true
tracing.workspace = true
uuid.workspace = true
[dev-dependencies]
arrow.workspace = true
cache.workspace = true
catalog = { workspace = true, features = ["testing"] }
common-function.workspace = true
common-macro.workspace = true
common-procedure.workspace = true
common-query = { workspace = true, features = ["testing"] }
fastrand = "2.0"
moka = { workspace = true, features = ["future"] }
nalgebra.workspace = true
paste.workspace = true
pretty_assertions.workspace = true
rand.workspace = true
store-api.workspace = true
table = { workspace = true, features = ["testing"] }
toml.workspace = true