Number of shards
Crate supports sharding natively, it even uses 5 shards by default if not further defined.
The number of shards can be defined by using the CLUSTERED INTO <number> SHARDS statement on
table creation. Example:
cr> create table my_table5 (
... first_column int
... ) clustered into 10 shards
Note
The number of shards can only be set on table creation, it cannot be changed later on.
Routing
The column used for routing can be freely defined using the CLUSTERED BY (<column>)
statement and is used to route a row to a particular shard. Example:
cr> create table my_table6 (
... first_column int primary key,
... second_column string
... ) clustered by (first_column)
By default Crate is using the primary keys for routing the request to the involved shards. So
following two examples resulting in the same behaviour:
cr> create table my_table7 (
... first_column int primary key,
... second_column string
... )
cr> create table my_table8 (
... first_column int primary key,
... second_column string
... ) clustered by (first_column)
If no primary is defined an internal generated unique id is used for routing.
Note
It is currently not supported to define a column for routing which is not a primary key or
member of a composite primary key.
Example for combining custom routing and shard definition:
cr> create table my_table9 (
... first_column int,
... second_column string
... ) clustered by (first_column) into 10 shards