#9351·greptimedb

PromQL: timestamp sample-time and label_join duplicate-labelset compatibility gaps

Author: discord9Created Sep 24, 2026Updated Sep 24, 2026

What type of bug is this?

Incorrect result (PromQL compatibility).

What subsystems are affected?

Query Engine.

Minimal reproduce step

Create a metric with two samples for host a (at 60 s and 120 s) and one for host b (at 120 s):

sql
CREATE TABLE promql_gap (ts TIMESTAMP TIME INDEX, val DOUBLE, host STRING, PRIMARY KEY(host));
INSERT INTO promql_gap VALUES (60000, 3, 'a'), (120000, 7, 'a'), (120000, 9, 'b');

TQL EVAL (120, 120, '1s') timestamp(promql_gap{host="a"} offset 60s);
TQL EVAL (120, 120, '1s') timestamp(abs(promql_gap{host="a"}));
TQL EVAL (120, 120, '1s') label_join(promql_gap, "host", "", "");

@ can expose the same timestamp/offset discrepancy (for example timestamp(m @ 300 offset 1m) when the selected sample is at 240 s); this follow-up concerns the timestamp value calculation, not the selector anchoring in #9224.

What did you expect to see?

  • timestamp(m offset 60s) returns the selected sample's actual timestamp, here 60 seconds, not the query time.
  • timestamp(abs(m)) returns the resulting sample's timestamp, here 120 seconds, not the input's numeric value.
  • If label_join maps distinct series onto the same labelset at the same evaluation instant, PromQL rejects the vector with vector cannot contain metrics with the same labelset, rather than returning two indistinguishable series.

What did you see instead?

  • The planner constructs the timestamp() value as sample_time + offset_ms in src/query/src/promql/planner.rs (currently around lines 2127-2140). An existing query test (src/query/src/promql/planner/test/delta.rs, delta_offsets_survive_optimized_plan_serialization) expects 120.0 for both timestamp(m offset 60s) and timestamp(m offset -60s) at evaluation time 120 s, despite those selectors choosing samples at 60 s and 180 s respectively.
  • timestamp() propagates a special flag to its argument's planner, but that flag is consumed by a direct vector selector, not by a wrapping abs() call. The general timestamp function branch forwards its input value instead (planner.rs, prom_call_expr_to_plan / create_function_expr). Thus timestamp(abs(m)) returns the numeric abs(m) result, e.g. 7, rather than 120.
  • label_join rewrites the destination label without a resulting-labelset uniqueness check (planner.rs, label_join branch). The checked-in tests/cases/standalone/common/promql/at_modifier.sql at case 11 and generated .result demonstrate two rows per step with host="" and different values; that case intentionally verifies that replay does not lose rows, not that the final duplicate-labelset behavior is valid PromQL.

These are separate pre-existing compatibility gaps, not requested changes to #9224's narrow @-selector/range-call promotion. The broad PromQL compliance tracker #6703 lists historical timestamp(expr) and label_join problems, but does not track these exact current repros. Related #9330 concerns subquery-level offset being ignored, not the timestamp value of a selected instant-vector sample. Fix and test these without widening #9224.

What operating system did you use?

Linux x86_64.

What version of GreptimeDB did you use?

Observed in the code/tests at #9224 head 69b316193f0313f0ddd973499753c1aab5d95b53 (2026-09-24). The issue combines an existing offset regression assertion and sqlness result with code inspection of the timestamp(abs(...)) path; no new standalone runtime repro was executed for that path in this report.