Cluster
Create a cluster
Please refer to Kubernetes to get the information about creating a Kubernetes cluster.
Distributed Read/Write
SQL
You can follow the steps to use SQL to play with distributed insertions and queries:
Use MySQL cli to connect to Frontend.
mysql -h 127.0.0.1 -P 4002
Create a distributed table via
CREATE
statement.CREATE TABLE dist_table(
ts TIMESTAMP DEFAULT current_timestamp(),
n INT,
row_id INT,
PRIMARY KEY(n),
TIME INDEX (ts)
)
PARTITION ON COLUMNS (n) (
n < 5,
n >= 5 AND n < 9,
n >= 9
)
engine=mito;
The result looks like the following:
mysql> CREATE TABLE dist_table(
-> ts TIMESTAMP DEFAULT current_timestamp(),
-> n INT,
-> row_id INT,
-> TIME INDEX (ts)
-> PRIMARY KEY(n),
-> )
-> PARTITION ON COLUMNS (n) (
-> n < 5,
-> n >= 5 AND n < 9,
-> n >= 9
-> )
-> engine=mito;
Query OK, 3 rows affected (0.09 sec)
The
dist_table
is distributed among theDatanode
s. You can refer to “Table Sharding” for more details.Insert some data via
INSERT
statement.INSERT INTO dist_table(n, row_id) VALUES (1, 1);
INSERT INTO dist_table(n, row_id) VALUES (2, 2);
INSERT INTO dist_table(n, row_id) VALUES (3, 3);
INSERT INTO dist_table(n, row_id) VALUES (4, 4);
INSERT INTO dist_table(n, row_id) VALUES (5, 5);
INSERT INTO dist_table(n, row_id) VALUES (6, 6);
INSERT INTO dist_table(n, row_id) VALUES (7, 7);
INSERT INTO dist_table(n, row_id) VALUES (8, 8);
INSERT INTO dist_table(n, row_id) VALUES (9, 9);
INSERT INTO dist_table(n, row_id) VALUES (10, 10);
INSERT INTO dist_table(n, row_id) VALUES (11, 11);
INSERT INTO dist_table(n, row_id) VALUES (12, 12);
Execute some queries via
SELECT
statement:SELECT * FROM dist_table ORDER BY n LIMIT 5;
+---------------------+------+--------+
| ts | n | row_id |
+---------------------+------+--------+
| 2022-11-14 12:02:32 | 1 | 1 |
| 2022-11-14 12:02:32 | 2 | 2 |
| 2022-11-14 12:02:32 | 3 | 3 |
| 2022-11-14 12:02:32 | 4 | 4 |
| 2022-11-14 12:02:32 | 5 | 5 |
+---------------------+------+--------+
5 rows in set (0.081 sec)
SELECT MAX(n) FROM dist_table;
+-------------------+
| MAX(dist_table.n) |
+-------------------+
| 12 |
+-------------------+
1 row in set (0.057 sec)
SELECT MIN(n) FROM dist_table;
+-------------------+
| MIN(dist_table.n) |
+-------------------+
| 1 |
+-------------------+
1 row in set (0.079 sec)
SELECT * FROM dist_table WHERE n > 2 AND n < 10 ORDER BY row_id;
+---------------------+------+--------+
| ts | n | row_id |
+---------------------+------+--------+
| 2022-11-14 12:02:32 | 3 | 3 |
| 2022-11-14 12:02:32 | 4 | 4 |
| 2022-11-14 12:02:32 | 5 | 5 |
| 2022-11-14 12:02:32 | 6 | 6 |
| 2022-11-14 12:02:32 | 7 | 7 |
| 2022-11-14 12:02:32 | 8 | 8 |
| 2022-11-14 12:02:32 | 9 | 9 |
+---------------------+------+--------+
7 rows in set (0.02 sec)
SELECT * FROM dist_table WHERE row_id = 10;
+---------------------+------+--------+
| ts | n | row_id |
+---------------------+------+--------+
| 2022-11-14 12:02:32 | 10 | 10 |
+---------------------+------+--------+
1 row in set (0.03 sec)
当前内容版权归 GreptimeDB 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 GreptimeDB .