mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-06 12:02:26 +00:00
* fix(promql): preserve native timestamps through sample selection Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): retain column indices in instant plan ordering Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): update native precision plan expectations Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): preserve selector output column order Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): verify preserved selector output order Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): refresh native timestamp explain expectations Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix: apply PromQL offsets without native timestamp overflow Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test: cover negative PromQL offsets at native timestamp bounds Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * feat: allow native precision instant LastRow selection Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor: discard unused bounds for empty range intersections Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix: preserve native time bounds independently for LastRow Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test: verify native LastRow predicates and overflow through SQL Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * docs: explain native PromQL selection and scan invariants Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * fix(promql): address timestamp helper and stream review feedback Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * refactor(promql): pass selector offsets explicitly from planner Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): retain explicit offset in payload overflow regression Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> * test(promql): record inner-offset subquery SQL results Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com> --------- Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
114 lines
3.9 KiB
SQL
114 lines
3.9 KiB
SQL
CREATE TABLE host_sec (
|
|
ts timestamp(0) time index,
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
);
|
|
|
|
INSERT INTO TABLE host_sec VALUES
|
|
(0, 'host1', 1),
|
|
(0, 'host2', 2),
|
|
(5, 'host1', 3),
|
|
(5, 'host2', 4),
|
|
(10, 'host1', 5),
|
|
(10, 'host2', 6),
|
|
(15, 'host1', 7),
|
|
(15, 'host2', 8);
|
|
|
|
CREATE TABLE host_micro (
|
|
ts timestamp(6) time index,
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
);
|
|
|
|
INSERT INTO TABLE host_micro VALUES
|
|
(0, 'host1', 1),
|
|
(0, 'host2', 2),
|
|
(5000000, 'host1', 3),
|
|
(5000000, 'host2', 4),
|
|
(10000000, 'host1', 5),
|
|
(10000000, 'host2', 6),
|
|
(15000000, 'host1', 7),
|
|
(15000000, 'host2', 8);
|
|
|
|
CREATE TABLE host_nano (
|
|
ts timestamp(9) time index,
|
|
host STRING PRIMARY KEY,
|
|
val DOUBLE,
|
|
);
|
|
|
|
INSERT INTO TABLE host_nano VALUES
|
|
(0, 'host1', 1),
|
|
(0, 'host2', 2),
|
|
(5000000000, 'host1', 3),
|
|
(5000000000, 'host2', 4),
|
|
(10000000000, 'host1', 5),
|
|
(10000000000, 'host2', 6),
|
|
(15000000000, 'host1', 7),
|
|
(15000000000, 'host2', 8);
|
|
|
|
-- Test on Timestamps of different precisions
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') host_sec{host="host1"};
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') avg_over_time(host_sec{host="host1"}[5s]);
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') host_micro{host="host1"};
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') avg_over_time(host_micro{host="host1"}[5s]);
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') host_sec{host="host1"} + host_micro{host="host1"};
|
|
|
|
-- SQLNESS SORT_RESULT 3 1
|
|
TQL EVAL (0, 15, '5s') avg_over_time(host_sec{host="host1"}[5s]) + avg_over_time(host_micro{host="host1"}[5s]);
|
|
|
|
-- Verify that PromQL time predicates on non-millisecond time indexes are
|
|
-- pushed into the scan as native timestamp range filters.
|
|
-- Instant selection compares raw timestamps before millisecond output conversion:
|
|
-- host = "host1" AND ts_us > -300000000us AND ts_us <= 10000000us.
|
|
-- SQLNESS REPLACE (RoundRobinBatch.*) REDACTED
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (Hash.*) REDACTED
|
|
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
|
|
-- SQLNESS REPLACE host_micro.__table_id\s*=\s*UInt32\(\d+\) host_micro.__table_id=UInt32(REDACTED)
|
|
-- SQLNESS REPLACE host_nano.__table_id\s*=\s*UInt32\(\d+\) host_nano.__table_id=UInt32(REDACTED)
|
|
TQL EXPLAIN (0, 10, '5s') host_micro{host="host1"};
|
|
|
|
-- The same exclusive-lower, inclusive-upper window applies to nanosecond indexes.
|
|
-- Expected native bounds: ts_ns > -300000000000ns AND ts_ns <= 10000000000ns.
|
|
-- SQLNESS REPLACE (RoundRobinBatch.*) REDACTED
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (Hash.*) REDACTED
|
|
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
|
|
-- SQLNESS REPLACE host_nano.__table_id\s*=\s*UInt32\(\d+\) host_nano.__table_id=UInt32(REDACTED)
|
|
TQL EXPLAIN (0, 10, '5s') host_nano{host="host1"};
|
|
|
|
-- Range selectors use their range window instead of the default lookback.
|
|
-- Native range selector filter for [5s]:
|
|
-- host = "host1" AND ts_us > -5000000us AND ts_us <= 10000000us
|
|
-- SQLNESS REPLACE (RoundRobinBatch.*) REDACTED
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (Hash.*) REDACTED
|
|
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
|
|
-- SQLNESS REPLACE host_micro.__table_id\s*=\s*UInt32\(\d+\) host_micro.__table_id=UInt32(REDACTED)
|
|
TQL EXPLAIN (0, 10, '5s') avg_over_time(host_micro{host="host1"}[5s]);
|
|
|
|
-- Range membership also retains nanosecond precision.
|
|
-- Expected native bounds: ts_ns > -5000000000ns AND ts_ns <= 10000000000ns.
|
|
-- SQLNESS REPLACE (RoundRobinBatch.*) REDACTED
|
|
-- SQLNESS REPLACE (peers.*) REDACTED
|
|
-- SQLNESS REPLACE (Hash.*) REDACTED
|
|
-- SQLNESS REPLACE (RepartitionExec:.*) RepartitionExec: REDACTED
|
|
-- SQLNESS REPLACE host_nano.__table_id\s*=\s*UInt32\(\d+\) host_nano.__table_id=UInt32(REDACTED)
|
|
TQL EXPLAIN (0, 10, '5s') avg_over_time(host_nano{host="host1"}[5s]);
|
|
|
|
DROP TABLE host_sec;
|
|
|
|
DROP TABLE host_micro;
|
|
|
|
DROP TABLE host_nano;
|