Files
greptimedb/tests/cases/standalone/common/truncate/truncate.result
T
Chenglong Zheng 9f9b35c270 feat: support wait and timeout options for TRUNCATE TABLE (#9753)
* feat: support wait and timeout options for TRUNCATE TABLE

* fix: address review feedback for truncate DDL options

* fix: address review feedback for truncate DDL options
2026-10-21 07:57:16 +00:00

194 lines
5.6 KiB
Plaintext

TRUNCATE TABLE not_exists_table;
Error: 4001(TableNotFound), Table not found: greptime.public.not_exists_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;
+----+------+-----+--------+
| ts | host | cpu | memory |
+----+------+-----+--------+
+----+------+-----+--------+
-- truncate with time range
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
ADMIN FLUSH_TABLE('monitor');
+------------------------------+
| ADMIN FLUSH_TABLE('monitor') |
+------------------------------+
| 0 |
+------------------------------+
INSERT INTO monitor(ts, host, cpu, memory) VALUES
(1700000000111, 'host42', 66.6, 1024);
Affected Rows: 1
ADMIN FLUSH_TABLE('monitor');
+------------------------------+
| ADMIN FLUSH_TABLE('monitor') |
+------------------------------+
| 0 |
+------------------------------+
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 |
| 2023-11-14T22:13:20.111 | host42 | 66.6 | 1024.0 |
+-------------------------+--------+------+--------+
TRUNCATE monitor FILE RANGE (0, 1700000000000), (1700000000111, 1700000000200);
Affected Rows: 0
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
+----+------+-----+--------+
| ts | host | cpu | memory |
+----+------+-----+--------+
+----+------+-----+--------+
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 WITH (wait = true, timeout = '30s');
Affected Rows: 0
SELECT ts, host, cpu, memory FROM monitor ORDER BY ts;
+----+------+-----+--------+
| ts | host | cpu | memory |
+----+------+-----+--------+
+----+------+-----+--------+
TRUNCATE monitor WITH (wait = 'invalid');
Error: 1004(InvalidArguments), Invalid SQL, error: invalid DDL option 'wait': 'invalid'
TRUNCATE monitor WITH (timeout = 'invalid');
Error: 1004(InvalidArguments), Invalid SQL, error: invalid DDL option 'timeout': 'invalid': expected number at 0
TRUNCATE monitor WITH (ttl = '1d');
Error: 2000(InvalidSyntax), Invalid SQL, error: invalid DDL option 'ttl': ''1d''
-- SQLNESS REPLACE ([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}) PROC_ID
TRUNCATE monitor WITH (wait = false, timeout = '30s');
+--------------------------------------+
| Procedure ID |
+--------------------------------------+
| PROC_ID |
+--------------------------------------+
-- Keep a synchronous truncate in the same case to check the original result.
TRUNCATE monitor;
Affected Rows: 0
DROP TABLE monitor;
Affected Rows: 0
CREATE TABLE "MoNiToR" ("hOsT" STRING PRIMARY KEY, "tS" TIMESTAMP TIME INDEX, "cPu" DOUBLE DEFAULT 0);
Affected Rows: 0
TRUNCATE "MoNiToR";
Affected Rows: 0
DROP TABLE "MoNiToR";
Affected Rows: 0
CREATE TABLE MoNiToR (hOsT STRING PRIMARY KEY, tS TIMESTAMP TIME INDEX, cPu DOUBLE DEFAULT 0);
Affected Rows: 0
TRUNCATE MoNiToR;
Affected Rows: 0
DROP TABLE MoNiToR;
Affected Rows: 0