mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-07 05:42:57 +00:00
feat: distribute truncate table in region server (#2414)
* feat: distribute truncate table * chore: add metrics for truncate table * test: add sqlness test * chore: cr * test: add multi truncate * chore: add trace id to the header
This commit is contained in:
76
tests/cases/standalone/common/truncate/truncate.result
Normal file
76
tests/cases/standalone/common/truncate/truncate.result
Normal file
@@ -0,0 +1,76 @@
|
||||
TRUNCATE TABLE not_exits_table;
|
||||
|
||||
Error: 4001(TableNotFound), Table not found: greptime.public.not_exits_table
|
||||
|
||||
CREATE TABLE monitor (host STRING, ts TIMESTAMP, cpu DOUBLE DEFAULT 0, memory DOUBLE, TIME INDEX (ts), PRIMARY KEY(host));
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
INSERT INTO monitor(ts, host, cpu, memory) VALUES
|
||||
(1695217652000, 'host1', 66.6, 1024),
|
||||
(1695217652000, 'host2', 66.6, 1024),
|
||||
(1695217652000, 'host3', 66.6, 1024),
|
||||
(1695217654000, 'host1', 77.7, 2048),
|
||||
(1695217654000, 'host2', 77.7, 2048),
|
||||
(1695217654000, 'host3', 77.7, 2048),
|
||||
(1695217656000, 'host1', 88.8, 4096),
|
||||
(1695217656000, 'host2', 88.8, 4096),
|
||||
(1695217656000, 'host3', 88.8, 4096);
|
||||
|
||||
Affected Rows: 9
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
+---------------------+-------+------+--------+
|
||||
| ts | host | cpu | memory |
|
||||
+---------------------+-------+------+--------+
|
||||
| 2023-09-20T13:47:32 | host1 | 66.6 | 1024.0 |
|
||||
| 2023-09-20T13:47:32 | host2 | 66.6 | 1024.0 |
|
||||
| 2023-09-20T13:47:32 | host3 | 66.6 | 1024.0 |
|
||||
| 2023-09-20T13:47:34 | host1 | 77.7 | 2048.0 |
|
||||
| 2023-09-20T13:47:34 | host2 | 77.7 | 2048.0 |
|
||||
| 2023-09-20T13:47:34 | host3 | 77.7 | 2048.0 |
|
||||
| 2023-09-20T13:47:36 | host1 | 88.8 | 4096.0 |
|
||||
| 2023-09-20T13:47:36 | host2 | 88.8 | 4096.0 |
|
||||
| 2023-09-20T13:47:36 | host3 | 88.8 | 4096.0 |
|
||||
+---------------------+-------+------+--------+
|
||||
|
||||
TRUNCATE monitor;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
++
|
||||
++
|
||||
|
||||
INSERT INTO monitor(ts, host, cpu, memory) VALUES
|
||||
(1695217660000, 'host1', 88.8, 4096),
|
||||
(1695217662000, 'host2', 88.8, 4096),
|
||||
(1695217664000, 'host3', 88.8, 4096);
|
||||
|
||||
Affected Rows: 3
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
+---------------------+-------+------+--------+
|
||||
| ts | host | cpu | memory |
|
||||
+---------------------+-------+------+--------+
|
||||
| 2023-09-20T13:47:40 | host1 | 88.8 | 4096.0 |
|
||||
| 2023-09-20T13:47:42 | host2 | 88.8 | 4096.0 |
|
||||
| 2023-09-20T13:47:44 | host3 | 88.8 | 4096.0 |
|
||||
+---------------------+-------+------+--------+
|
||||
|
||||
TRUNCATE monitor;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
++
|
||||
++
|
||||
|
||||
DROP TABLE monitor;
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
33
tests/cases/standalone/common/truncate/truncate.sql
Normal file
33
tests/cases/standalone/common/truncate/truncate.sql
Normal file
@@ -0,0 +1,33 @@
|
||||
TRUNCATE TABLE not_exits_table;
|
||||
|
||||
CREATE TABLE monitor (host STRING, ts TIMESTAMP, cpu DOUBLE DEFAULT 0, memory DOUBLE, TIME INDEX (ts), PRIMARY KEY(host));
|
||||
|
||||
INSERT INTO monitor(ts, host, cpu, memory) VALUES
|
||||
(1695217652000, 'host1', 66.6, 1024),
|
||||
(1695217652000, 'host2', 66.6, 1024),
|
||||
(1695217652000, 'host3', 66.6, 1024),
|
||||
(1695217654000, 'host1', 77.7, 2048),
|
||||
(1695217654000, 'host2', 77.7, 2048),
|
||||
(1695217654000, 'host3', 77.7, 2048),
|
||||
(1695217656000, 'host1', 88.8, 4096),
|
||||
(1695217656000, 'host2', 88.8, 4096),
|
||||
(1695217656000, 'host3', 88.8, 4096);
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
TRUNCATE monitor;
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
INSERT INTO monitor(ts, host, cpu, memory) VALUES
|
||||
(1695217660000, 'host1', 88.8, 4096),
|
||||
(1695217662000, 'host2', 88.8, 4096),
|
||||
(1695217664000, 'host3', 88.8, 4096);
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
TRUNCATE monitor;
|
||||
|
||||
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
|
||||
|
||||
DROP TABLE monitor;
|
||||
Reference in New Issue
Block a user