#9307·greptimedb

PromQL: NULL and empty-string tag values are treated as different labels

Author: killme2008Created Sep 22, 2026Updated Sep 24, 2026
LabelsC-bug

Prometheus has one representation for "this series has no label l": the empty value. labels.Labels drops empty values, l="" matches series without l, and a signature over on()/ignoring() labels reads an absent label as "".

GreptimeDB stores tags as nullable columns, so a tag has three states a query can tell apart: a value, '', and NULL. PromQL evaluation compares the raw columns, so NULL and '' are two label values and two series.

Where it shows

Aggregate grouping. In tests/cases/standalone/common/promql/matching_groups.result, matching_groups_right holds ('', 'a', 0, 8) and (NULL, 'a', 0, 10). max by(host)(matching_groups_right) returns two groups, 8 and 10. Prometheus returns one group, 10.

Binary matching. Same case, recorded output:

TQL EVAL (0, 0, '1s') matching_groups_left{host!="y"} / on(host) group_left max by(host)(matching_groups_right);

| host | ts                  | ... |
|      | 1970-01-01T00:00:00 | 6.0 |
|      | 1970-01-01T00:00:00 | 6.0 |

Two rows carry the same rendered label set. A client that keys on the label set — Grafana, Alertmanager, any Prometheus-compatible reader — drops or mishandles one of them. Same defect class as #9209, different cause. (With the labels unified the query returns 4.8 and 6.0, from a single max group of 10.)

A match label only one side carries. binary_join_key_columns (src/query/src/promql/planner.rs) forces an empty join when the reduced key sets differ, e.g. on(host) where the right operand has no host column at all. Prometheus reads the absent label as "" and matches the left series whose host is empty.

Cardinality check. The vector matching checks added in #9306 partition by the same raw columns, so a match group split by NULL vs '' is not seen as a duplicate.

This is an internal inconsistency, not a trade-off

or already implements the Prometheus rule. It builds its match keys through normalized_match_key_expr in the same file: coalesce(cast(<col>), ''), and a literal '' when the column is absent. The arithmetic and comparison join path and the aggregations do not use it.

Scope of a fix

Normalize inside PromQL evaluation only: join keys, aggregate grouping keys (by/without), the cardinality-check partition, and the projected result labels. The stored columns are untouched, so SQL keeps distinguishing NULL from ''.

A Prometheus-shaped write path leaves an absent label as NULL, so the mixed state needs a second writer: SQL INSERT or the gRPC ingest path can put '' in the same column.