PromQL: timestamp sample-time and label_join duplicate-labelset compatibility gaps
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):
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, here60seconds, not the query time.timestamp(abs(m))returns the resulting sample's timestamp, here120seconds, not the input's numeric value.- If
label_joinmaps distinct series onto the same labelset at the same evaluation instant, PromQL rejects the vector withvector cannot contain metrics with the same labelset, rather than returning two indistinguishable series.
What did you see instead?
- The planner constructs the
timestamp()value assample_time + offset_msinsrc/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) expects120.0for bothtimestamp(m offset 60s)andtimestamp(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 wrappingabs()call. The generaltimestampfunction branch forwards its input value instead (planner.rs,prom_call_expr_to_plan/create_function_expr). Thustimestamp(abs(m))returns the numericabs(m)result, e.g.7, rather than120.label_joinrewrites the destination label without a resulting-labelset uniqueness check (planner.rs,label_joinbranch). The checked-intests/cases/standalone/common/promql/at_modifier.sqlat case 11 and generated.resultdemonstrate two rows per step withhost=""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.
Source: GreptimeTeam/greptimedb