mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-05-16 04:50:38 +00:00
* feat/change-tsid-gen: perf(metric-engine): replace mur3 with fxhash for faster TSID generation - Switches from mur3::Hasher128 to fxhash::FxHasher for TSID hashing - Pre-computes label-name hash when no nulls are present, avoiding redundant work - Adds fast-path for rows without nulls; falls back to slow path otherwise - Updates Cargo.toml and lockfile to reflect dependency change Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * feat/change-tsid-gen: fix: only check primary-key labels for null when re-using cached hash - Rename has_null() → has_null_labels() and restrict the check to the primary-key columns so that non-label NULLs do not force a full TSID re-computation. - Update expected hashes in tests to match the new logic. Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * feat/change-tsid-gen: test: add comprehensive TSID generation tests for label ordering and null handling Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * feat/change-tsid-gen: bench: add criterion benchmark for TSID generator - Compare original mur3 vs current fxhash fast/slow paths - Test 2, 5, 10 label sets plus null-value slow path - Add mur3 & criterion dev-deps; register bench target Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * feat/change-tsid-gen: test: stabilize metric-engine tests by fixing non-deterministic row order - Add ORDER BY to SELECTs in TTL tests to ensure consistent output - Update expected __tsid values after hash function change - Swap expected OTLP metric rows to match new ordering Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> * feat/change-tsid-gen: refactor: simplify Default impls and remove redundant code - Replace manual Default for TsidGenerator with derive - Remove unnecessary into_iter() call - Simplify Option::unwrap_or_else to unwrap_or Signed-off-by: Lei, HUANG <mrsatangel@gmail.com> --------- Signed-off-by: Lei, HUANG <mrsatangel@gmail.com>
188 lines
5.6 KiB
Plaintext
188 lines
5.6 KiB
Plaintext
CREATE TABLE phy (ts timestamp time index, val double) engine=metric with ("physical_metric_table" = "");
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE t1 (ts timestamp time index, val double, host string primary key) engine = metric with ("on_physical_table" = "phy");
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO t1 VALUES ('host1',0, 0), ('host2', 1, 1,);
|
|
|
|
Affected Rows: 2
|
|
|
|
SELECT * from t1;
|
|
|
|
+-------+-------------------------+-----+
|
|
| host | ts | val |
|
|
+-------+-------------------------+-----+
|
|
| host2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
| host1 | 1970-01-01T00:00:00 | 0.0 |
|
|
+-------+-------------------------+-----+
|
|
|
|
CREATE TABLE t2 (ts timestamp time index, job string primary key, val double) engine = metric with ("on_physical_table" = "phy");
|
|
|
|
Affected Rows: 0
|
|
|
|
SELECT * from t2;
|
|
|
|
++
|
|
++
|
|
|
|
INSERT INTO t2 VALUES ('job1', 0, 0), ('job2', 1, 1);
|
|
|
|
Affected Rows: 2
|
|
|
|
SELECT * from t2;
|
|
|
|
+------+-------------------------+-----+
|
|
| job | ts | val |
|
|
+------+-------------------------+-----+
|
|
| job1 | 1970-01-01T00:00:00 | 0.0 |
|
|
| job2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
+------+-------------------------+-----+
|
|
|
|
DROP TABLE t1;
|
|
|
|
Affected Rows: 0
|
|
|
|
DROP TABLE t2;
|
|
|
|
Affected Rows: 0
|
|
|
|
DESC TABLE phy;
|
|
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
| Column | Type | Key | Null | Default | Semantic Type |
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
|
|
| val | Float64 | | YES | | FIELD |
|
|
| __table_id | UInt32 | PRI | NO | | TAG |
|
|
| __tsid | UInt64 | PRI | NO | | TAG |
|
|
| host | String | PRI | YES | | TAG |
|
|
| job | String | PRI | YES | | TAG |
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
|
|
SELECT ts, val, __tsid, host, job FROM phy;
|
|
|
|
+-------------------------+-----+----------------------+-------+------+
|
|
| ts | val | __tsid | host | job |
|
|
+-------------------------+-----+----------------------+-------+------+
|
|
| 1970-01-01T00:00:00.001 | 1.0 | 7947983149541006936 | host2 | |
|
|
| 1970-01-01T00:00:00 | 0.0 | 13882403126406556045 | host1 | |
|
|
| 1970-01-01T00:00:00 | 0.0 | 6248409809737953425 | | job1 |
|
|
| 1970-01-01T00:00:00.001 | 1.0 | 12867770218286207316 | | job2 |
|
|
+-------------------------+-----+----------------------+-------+------+
|
|
|
|
DROP TABLE phy;
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE phy (
|
|
ts timestamp time index,
|
|
val double
|
|
) engine = metric with (
|
|
"physical_metric_table" = "",
|
|
"memtable.type" = "partition_tree",
|
|
"memtable.partition_tree.primary_key_encoding" = "sparse"
|
|
);
|
|
|
|
Affected Rows: 0
|
|
|
|
CREATE TABLE t1 (ts timestamp time index, val double, host string primary key) engine = metric with ("on_physical_table" = "phy");
|
|
|
|
Affected Rows: 0
|
|
|
|
INSERT INTO t1 VALUES ('host1',0, 0), ('host2', 1, 1,);
|
|
|
|
Affected Rows: 2
|
|
|
|
SELECT * from t1;
|
|
|
|
+-------+-------------------------+-----+
|
|
| host | ts | val |
|
|
+-------+-------------------------+-----+
|
|
| host2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
| host1 | 1970-01-01T00:00:00 | 0.0 |
|
|
+-------+-------------------------+-----+
|
|
|
|
CREATE TABLE t2 (ts timestamp time index, job string primary key, val double) engine = metric with ("on_physical_table" = "phy");
|
|
|
|
Affected Rows: 0
|
|
|
|
SELECT * from t2;
|
|
|
|
++
|
|
++
|
|
|
|
INSERT INTO t2 VALUES ('job1', 0, 0), ('job2', 1, 1);
|
|
|
|
Affected Rows: 2
|
|
|
|
SELECT * from t2;
|
|
|
|
+------+-------------------------+-----+
|
|
| job | ts | val |
|
|
+------+-------------------------+-----+
|
|
| job1 | 1970-01-01T00:00:00 | 0.0 |
|
|
| job2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
+------+-------------------------+-----+
|
|
|
|
ADMIN flush_table('phy');
|
|
|
|
+--------------------------+
|
|
| ADMIN flush_table('phy') |
|
|
+--------------------------+
|
|
| 0 |
|
|
+--------------------------+
|
|
|
|
-- SQLNESS ARG restart=true
|
|
INSERT INTO t2 VALUES ('job3', 0, 0), ('job4', 1, 1);
|
|
|
|
Affected Rows: 2
|
|
|
|
SELECT * from t1;
|
|
|
|
+-------+-------------------------+-----+
|
|
| host | ts | val |
|
|
+-------+-------------------------+-----+
|
|
| host2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
| host1 | 1970-01-01T00:00:00 | 0.0 |
|
|
+-------+-------------------------+-----+
|
|
|
|
SELECT * from t2;
|
|
|
|
+------+-------------------------+-----+
|
|
| job | ts | val |
|
|
+------+-------------------------+-----+
|
|
| job3 | 1970-01-01T00:00:00 | 0.0 |
|
|
| job1 | 1970-01-01T00:00:00 | 0.0 |
|
|
| job4 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
| job2 | 1970-01-01T00:00:00.001 | 1.0 |
|
|
+------+-------------------------+-----+
|
|
|
|
DROP TABLE t1;
|
|
|
|
Affected Rows: 0
|
|
|
|
DROP TABLE t2;
|
|
|
|
Affected Rows: 0
|
|
|
|
DESC TABLE phy;
|
|
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
| Column | Type | Key | Null | Default | Semantic Type |
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
| ts | TimestampMillisecond | PRI | NO | | TIMESTAMP |
|
|
| val | Float64 | | YES | | FIELD |
|
|
| __table_id | UInt32 | PRI | NO | | TAG |
|
|
| __tsid | UInt64 | PRI | NO | | TAG |
|
|
| host | String | PRI | YES | | TAG |
|
|
| job | String | PRI | YES | | TAG |
|
|
+------------+----------------------+-----+------+---------+---------------+
|
|
|
|
DROP TABLE phy;
|
|
|
|
Affected Rows: 0
|
|
|