Cluster

Create a cluster

Please refer to Kubernetes to get the infomation 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.

    shell

    1. mysql -h 127.0.0.1 -P 4002
  2. Create a distributed table via CREATE statement.

    SQL

    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 BY RANGE COLUMNS (n) (
    9. PARTITION r0 VALUES LESS THAN (5),
    10. PARTITION r1 VALUES LESS THAN (9),
    11. PARTITION r2 VALUES LESS THAN (MAXVALUE),
    12. )
    13. engine=mito;

    The result looks like the following:

    shell

    1. mysql> 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 BY RANGE COLUMNS (n) (
    9. -> PARTITION r0 VALUES LESS THAN (5),
    10. -> PARTITION r1 VALUES LESS THAN (9),
    11. -> PARTITION r2 VALUES LESS THAN (MAXVALUE),
    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.

  3. Insert some data via INSERT statement.

    SQL

    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);
  4. Execute some queries via SELECT statement:

    sql

    1. SELECT * FROM dist_table ORDER BY n LIMIT 5;

    sql

    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)

    sql

    1. SELECT MAX(n) FROM dist_table;

    sql

    1. +-------------------+
    2. | MAX(dist_table.n) |
    3. +-------------------+
    4. | 12 |
    5. +-------------------+
    6. 1 row in set (0.057 sec)

    sql

    1. SELECT MIN(n) FROM dist_table;

    sql

    1. +-------------------+
    2. | MIN(dist_table.n) |
    3. +-------------------+
    4. | 1 |
    5. +-------------------+
    6. 1 row in set (0.079 sec)

    sql

    1. SELECT * FROM dist_table WHERE n > 2 AND n < 10 ORDER BY row_id;

    sql

    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)

    sql

    1. SELECT * FROM dist_table WHERE row_id = 10;

    sql

    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)

    You can also use SQL in REPL which can directly connect to the Datanode. In this way, you can verify that the queries from Frontend are actually been executed distributed. For more details about distributed querying, please see this document.