Files
greptimedb/tests-integration/tests
dennis zhuang 2916062cc4 feat(promql): answer an instant query of a range selector natively (#10672)
* feat(promql): answer an instant query of a range selector natively

An instant query whose root is a range selector, such as `x[5m]`,
declined with matrix_root_without_a_grid. Prometheus and the existing
plan answer it with the samples of the window, keeping their own
timestamps and dropping stale markers.

Those samples are exactly the points of a one-millisecond subquery over
the same window at which the bare selector, read with no lookback,
finds a sample. The planner now compiles such a root that way, reusing
the subquery-root path, so `offset` and `@` place the window as they
do for a subquery. A range query with a range-vector root still
declines and fails as before.

A zero-lookback instant selection now walks the samples instead of the
grid points, and bounds its workspace by the sample count, so the fine
grid costs no more than the samples it answers.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test(promql): cover the HTTP matrix of a native range selector root

The instant query API now answers `x[5m]` on both routes with the same
matrix, and a series with no sample in the window is omitted. The
range selector finder also gets its own doc comment back.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): keep a range selector root's null rows and leave sub-millisecond windows to the existing plan

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): drop a range selector root's rows stale in any field

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): leave histogram range selector roots with an offset to the existing plan

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* refactor(promql): keep any-field staleness specific to range selector roots

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): answer histogram range selector roots with an offset natively

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix(promql): leave range selector roots over sub-millisecond time indexes to the existing plan

A range selector root runs as a one-millisecond subquery with no
lookback. On a microsecond or nanosecond time index, a zero lookback
selects only a sample exactly on a millisecond, so a sample between two
grid points would be missing from the window. Decline the rewrite there.

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* style(promql): format the range selector root time unit decline

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
2026-12-02 04:10:20 +00:00
..
2026-06-30 07:37:31 +00:00