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:

  1. Use MySQL cli to connect to Frontend.
  1. mysql -h 127.0.0.1 -P 4002
  1. Create a distributed table via CREATE statement.
  1. CREATE TABLE dist_table(
  2. ts TIMESTAMP DEFAULT current_timestamp(),
  3. n INT,
  4. row_id INT,
  5. PRIMARY KEY(n),
  6. TIME INDEX (ts)
  7. )
  8. PARTITION ON COLUMNS (n) (
  9. n < 5,
  10. n >= 5 AND n < 9,
  11. n >= 9
  12. )
  13. engine=mito;

The result looks like the following:

  1. mysql> CREATE TABLE dist_table(
  2. -> ts TIMESTAMP DEFAULT current_timestamp(),
  3. -> n INT,
  4. -> row_id INT,
  5. -> TIME INDEX (ts)
  6. -> PRIMARY KEY(n),
  7. -> )
  8. -> PARTITION ON COLUMNS (n) (
  9. -> n < 5,
  10. -> n >= 5 AND n < 9,
  11. -> n >= 9
  12. -> )
  13. -> engine=mito;
  14. Query OK, 3 rows affected (0.09 sec)

The dist_table is distributed among the Datanodes. You can refer to “Table Sharding” for more details.

  1. Insert some data via INSERT statement.
  1. INSERT INTO dist_table(n, row_id) VALUES (1, 1);
  2. INSERT INTO dist_table(n, row_id) VALUES (2, 2);
  3. INSERT INTO dist_table(n, row_id) VALUES (3, 3);
  4. INSERT INTO dist_table(n, row_id) VALUES (4, 4);
  5. INSERT INTO dist_table(n, row_id) VALUES (5, 5);
  6. INSERT INTO dist_table(n, row_id) VALUES (6, 6);
  7. INSERT INTO dist_table(n, row_id) VALUES (7, 7);
  8. INSERT INTO dist_table(n, row_id) VALUES (8, 8);
  9. INSERT INTO dist_table(n, row_id) VALUES (9, 9);
  10. INSERT INTO dist_table(n, row_id) VALUES (10, 10);
  11. INSERT INTO dist_table(n, row_id) VALUES (11, 11);
  12. INSERT INTO dist_table(n, row_id) VALUES (12, 12);
  1. Execute some queries via SELECT statement:
  1. SELECT * FROM dist_table ORDER BY n LIMIT 5;
  1. +---------------------+------+--------+
  2. | ts | n | row_id |
  3. +---------------------+------+--------+
  4. | 2022-11-14 12:02:32 | 1 | 1 |
  5. | 2022-11-14 12:02:32 | 2 | 2 |
  6. | 2022-11-14 12:02:32 | 3 | 3 |
  7. | 2022-11-14 12:02:32 | 4 | 4 |
  8. | 2022-11-14 12:02:32 | 5 | 5 |
  9. +---------------------+------+--------+
  10. 5 rows in set (0.081 sec)
  1. SELECT MAX(n) FROM dist_table;
  1. +-------------------+
  2. | MAX(dist_table.n) |
  3. +-------------------+
  4. | 12 |
  5. +-------------------+
  6. 1 row in set (0.057 sec)
  1. SELECT MIN(n) FROM dist_table;
  1. +-------------------+
  2. | MIN(dist_table.n) |
  3. +-------------------+
  4. | 1 |
  5. +-------------------+
  6. 1 row in set (0.079 sec)
  1. SELECT * FROM dist_table WHERE n > 2 AND n < 10 ORDER BY row_id;
  1. +---------------------+------+--------+
  2. | ts | n | row_id |
  3. +---------------------+------+--------+
  4. | 2022-11-14 12:02:32 | 3 | 3 |
  5. | 2022-11-14 12:02:32 | 4 | 4 |
  6. | 2022-11-14 12:02:32 | 5 | 5 |
  7. | 2022-11-14 12:02:32 | 6 | 6 |
  8. | 2022-11-14 12:02:32 | 7 | 7 |
  9. | 2022-11-14 12:02:32 | 8 | 8 |
  10. | 2022-11-14 12:02:32 | 9 | 9 |
  11. +---------------------+------+--------+
  12. 7 rows in set (0.02 sec)
  1. SELECT * FROM dist_table WHERE row_id = 10;
  1. +---------------------+------+--------+
  2. | ts | n | row_id |
  3. +---------------------+------+--------+
  4. | 2022-11-14 12:02:32 | 10 | 10 |
  5. +---------------------+------+--------+
  6. 1 row in set (0.03 sec)