mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-01-06 13:22:57 +00:00
feat: implement multi-dim partition rule (#3409)
* generate expr rule Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * implement show create for new partition rule Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * implement row spliter Signed-off-by: Ruihang Xia <waynestxia@gmail.com> * fix: fix failed tests Signed-off-by: WenyXu <wenymedia@gmail.com> * chore: fix lint issues Signed-off-by: WenyXu <wenymedia@gmail.com> * chore: ignore tests for deprecated partition rule * chore: remove unused partition rule tests setup * test(sqlness): add basic partition tests * test(multi_dim): add basic find region test * address CR comments Signed-off-by: Ruihang Xia <waynestxia@gmail.com> --------- Signed-off-by: Ruihang Xia <waynestxia@gmail.com> Signed-off-by: WenyXu <wenymedia@gmail.com> Co-authored-by: WenyXu <wenymedia@gmail.com>
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) (
|
||||
a < 1000,
|
||||
a >= 1000 AND a < 2000,
|
||||
a >= 2000
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id |
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
| greptime | public | my_table | p0 | (a) VALUES LESS THAN (MAXVALUE) | ID |
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
+---------------+---------+-----------+--------+
|
||||
| region_id | peer_id | is_leader | status |
|
||||
+---------------+---------+-----------+--------+
|
||||
| REGION_ID | PEER_ID | Yes | ALIVE |
|
||||
+---------------+---------+-----------+--------+
|
||||
|
||||
DROP TABLE my_table;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) (
|
||||
a < 1000,
|
||||
a >= 1000 AND a < 2000,
|
||||
a >= 2000
|
||||
);
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
DROP TABLE my_table;
|
||||
170
tests/cases/standalone/common/partition.result
Normal file
170
tests/cases/standalone/common/partition.result
Normal file
@@ -0,0 +1,170 @@
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) (
|
||||
a < 1000,
|
||||
a >= 1000 AND a < 2000,
|
||||
a >= 2000
|
||||
);
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
|
||||
| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id |
|
||||
+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
|
||||
| greptime | public | my_table | p0 | (a) VALUES LESS THAN (PartitionExpr { lhs: Column("a"), op: Lt, rhs: Value(Int32(1000)) }) | ID |
|
||||
| greptime | public | my_table | p1 | (a) VALUES LESS THAN (PartitionExpr { lhs: Column("a"), op: GtEq, rhs: Value(Int32(2000)) }) | ID |
|
||||
| greptime | public | my_table | p2 | (a) VALUES LESS THAN (PartitionExpr { lhs: Expr(PartitionExpr { lhs: Column("a"), op: GtEq, rhs: Value(Int32(1000)) }), op: And, rhs: Expr(PartitionExpr { lhs: Column("a"), op: Lt, rhs: Value(Int32(2000)) }) }) | ID |
|
||||
+---------------+--------------+------------+----------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+-----------------------+
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
+---------------+---------+-----------+--------+
|
||||
| region_id | peer_id | is_leader | status |
|
||||
+---------------+---------+-----------+--------+
|
||||
| REGION_ID | PEER_ID | Yes | ALIVE |
|
||||
| REGION_ID | PEER_ID | Yes | ALIVE |
|
||||
| REGION_ID | PEER_ID | Yes | ALIVE |
|
||||
+---------------+---------+-----------+--------+
|
||||
|
||||
INSERT INTO my_table VALUES
|
||||
(100, 'a', 1),
|
||||
(200, 'b', 2),
|
||||
(1100, 'c', 3),
|
||||
(1200, 'd', 4),
|
||||
(2000, 'e', 5),
|
||||
(2100, 'f', 6),
|
||||
(2200, 'g', 7),
|
||||
(2400, 'h', 8);
|
||||
|
||||
Affected Rows: 8
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
+------+---+-------------------------+
|
||||
| a | b | ts |
|
||||
+------+---+-------------------------+
|
||||
| 100 | a | 1970-01-01T00:00:00.001 |
|
||||
| 200 | b | 1970-01-01T00:00:00.002 |
|
||||
| 1100 | c | 1970-01-01T00:00:00.003 |
|
||||
| 1200 | d | 1970-01-01T00:00:00.004 |
|
||||
| 2000 | e | 1970-01-01T00:00:00.005 |
|
||||
| 2100 | f | 1970-01-01T00:00:00.006 |
|
||||
| 2200 | g | 1970-01-01T00:00:00.007 |
|
||||
| 2400 | h | 1970-01-01T00:00:00.008 |
|
||||
+------+---+-------------------------+
|
||||
|
||||
DELETE FROM my_table WHERE a < 150;
|
||||
|
||||
Affected Rows: 1
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
+------+---+-------------------------+
|
||||
| a | b | ts |
|
||||
+------+---+-------------------------+
|
||||
| 200 | b | 1970-01-01T00:00:00.002 |
|
||||
| 1100 | c | 1970-01-01T00:00:00.003 |
|
||||
| 1200 | d | 1970-01-01T00:00:00.004 |
|
||||
| 2000 | e | 1970-01-01T00:00:00.005 |
|
||||
| 2100 | f | 1970-01-01T00:00:00.006 |
|
||||
| 2200 | g | 1970-01-01T00:00:00.007 |
|
||||
| 2400 | h | 1970-01-01T00:00:00.008 |
|
||||
+------+---+-------------------------+
|
||||
|
||||
DELETE FROM my_table WHERE a < 2200 AND a > 1500;
|
||||
|
||||
Affected Rows: 2
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
+------+---+-------------------------+
|
||||
| a | b | ts |
|
||||
+------+---+-------------------------+
|
||||
| 200 | b | 1970-01-01T00:00:00.002 |
|
||||
| 1100 | c | 1970-01-01T00:00:00.003 |
|
||||
| 1200 | d | 1970-01-01T00:00:00.004 |
|
||||
| 2200 | g | 1970-01-01T00:00:00.007 |
|
||||
| 2400 | h | 1970-01-01T00:00:00.008 |
|
||||
+------+---+-------------------------+
|
||||
|
||||
DELETE FROM my_table WHERE a < 2500;
|
||||
|
||||
Affected Rows: 5
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
++
|
||||
++
|
||||
|
||||
DROP TABLE my_table;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) ();
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
| table_catalog | table_schema | table_name | partition_name | partition_expression | greptime_partition_id |
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
| greptime | public | my_table | p0 | (a) VALUES LESS THAN (MAXVALUE) | ID |
|
||||
+---------------+--------------+------------+----------------+---------------------------------+-----------------------+
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
+---------------+---------+-----------+--------+
|
||||
| region_id | peer_id | is_leader | status |
|
||||
+---------------+---------+-----------+--------+
|
||||
| REGION_ID | PEER_ID | Yes | ALIVE |
|
||||
+---------------+---------+-----------+--------+
|
||||
|
||||
INSERT INTO my_table VALUES
|
||||
(100, 'a', 1),
|
||||
(200, 'b', 2),
|
||||
(1100, 'c', 3),
|
||||
(1200, 'd', 4),
|
||||
(2000, 'e', 5),
|
||||
(2100, 'f', 6),
|
||||
(2200, 'g', 7),
|
||||
(2400, 'h', 8);
|
||||
|
||||
Affected Rows: 8
|
||||
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
+------+---+-------------------------+
|
||||
| a | b | ts |
|
||||
+------+---+-------------------------+
|
||||
| 100 | a | 1970-01-01T00:00:00.001 |
|
||||
| 200 | b | 1970-01-01T00:00:00.002 |
|
||||
| 1100 | c | 1970-01-01T00:00:00.003 |
|
||||
| 1200 | d | 1970-01-01T00:00:00.004 |
|
||||
| 2000 | e | 1970-01-01T00:00:00.005 |
|
||||
| 2100 | f | 1970-01-01T00:00:00.006 |
|
||||
| 2200 | g | 1970-01-01T00:00:00.007 |
|
||||
| 2400 | h | 1970-01-01T00:00:00.008 |
|
||||
+------+---+-------------------------+
|
||||
|
||||
DROP TABLE my_table;
|
||||
|
||||
Affected Rows: 0
|
||||
|
||||
71
tests/cases/standalone/common/partition.sql
Normal file
71
tests/cases/standalone/common/partition.sql
Normal file
@@ -0,0 +1,71 @@
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) (
|
||||
a < 1000,
|
||||
a >= 1000 AND a < 2000,
|
||||
a >= 2000
|
||||
);
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
INSERT INTO my_table VALUES
|
||||
(100, 'a', 1),
|
||||
(200, 'b', 2),
|
||||
(1100, 'c', 3),
|
||||
(1200, 'd', 4),
|
||||
(2000, 'e', 5),
|
||||
(2100, 'f', 6),
|
||||
(2200, 'g', 7),
|
||||
(2400, 'h', 8);
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
DELETE FROM my_table WHERE a < 150;
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
DELETE FROM my_table WHERE a < 2200 AND a > 1500;
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
DELETE FROM my_table WHERE a < 2500;
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
DROP TABLE my_table;
|
||||
|
||||
CREATE TABLE my_table (
|
||||
a INT PRIMARY KEY,
|
||||
b STRING,
|
||||
ts TIMESTAMP TIME INDEX,
|
||||
)
|
||||
PARTITION ON COLUMNS (a) ();
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) ID
|
||||
SELECT table_catalog, table_schema, table_name, partition_name, partition_expression, greptime_partition_id from information_schema.partitions WHERE table_name = 'my_table' ORDER BY table_catalog, table_schema, table_name, partition_name;
|
||||
|
||||
-- SQLNESS REPLACE (\d{13}) REGION_ID
|
||||
-- SQLNESS REPLACE (\d{1}) PEER_ID
|
||||
SELECT region_id, peer_id, is_leader, status FROM information_schema.greptime_region_peers ORDER BY peer_id;
|
||||
|
||||
INSERT INTO my_table VALUES
|
||||
(100, 'a', 1),
|
||||
(200, 'b', 2),
|
||||
(1100, 'c', 3),
|
||||
(1200, 'd', 4),
|
||||
(2000, 'e', 5),
|
||||
(2100, 'f', 6),
|
||||
(2200, 'g', 7),
|
||||
(2400, 'h', 8);
|
||||
|
||||
SELECT * FROM my_table;
|
||||
|
||||
DROP TABLE my_table;
|
||||
@@ -35,11 +35,13 @@ SHOW CREATE TABLE system_metrics;
|
||||
| | PRIMARY KEY ("id", "host") |
|
||||
| | ) |
|
||||
| | PARTITION ON COLUMNS ("id") ( |
|
||||
| | |
|
||||
| | id < 5, |
|
||||
| | id >= 9, |
|
||||
| | id >= 5 AND id < 9 |
|
||||
| | ) |
|
||||
| | ENGINE=mito |
|
||||
| | WITH( |
|
||||
| | regions = 1, |
|
||||
| | regions = 3, |
|
||||
| | ttl = '7days', |
|
||||
| | write_buffer_size = '1.0KiB' |
|
||||
| | ) |
|
||||
|
||||
Reference in New Issue
Block a user