You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> NOTE: Auto-sharding requires [Manticore Buddy](../../Installation/Manticore_Buddy.md). If auto-sharding doesn't work, make sure Buddy is installed and running.
4
+
5
+
Manticore allows for the creation of **sharded tables**, a special table type (`type='shard'`) that transparently fans out reads and writes across multiple underlying physical shards. This feature proves invaluable when scaling your data. You can create both local sharded tables on a single server and replicated sharded tables on a multi-node replication cluster to optimize data distribution.
6
+
7
+
Sharded tables offer several key benefits for high-performance applications:
8
+
- They deliver superior write performance by writing data to multiple shards in parallel, utilizing system resources more efficiently. This parallel writing capability enables higher indexing throughput compared to a single large table.
9
+
- Sharded tables support replication out of the box, enhancing high availability. You don't need to handle replication manually. Simply set the replication factor when creating the sharded table, and the system manages everything. This built-in replication ensures continuous data accessibility even if some nodes fail.
10
+
11
+
#### Options
12
+
13
+
-`shards='N'` — number of physical shards to create. Required. Must be a positive integer, with a maximum of 3000.
14
+
-`rf='M'` — replication factor: the number of copies kept for each shard. Required. On a single node it must be `1`; on a replication cluster it must be between 1 and the number of nodes in the cluster.
15
+
-`timeout='S'` — how long (in seconds) to wait for shard preparation during creation. Defaults to `30`. Increase it when creating many shards across many nodes.
16
+
17
+
Values must be quoted (`shards='10'`, not `shards=10`). Option names are case-insensitive.
18
+
19
+
#### Creating a Local Sharded Table
20
+
21
+
To create a local sharded table, create a table as you normally would and add `shards='N'` and `rf='1'`. `shards` is the number of physical shards that will be created behind the table. `rf` is the replication factor. On a single server it must be `1`.
22
+
23
+
Here's an example that creates a table with 10 shards, with data automatically distributed across them:
24
+
25
+
```sql
26
+
CREATETABLElocal_sharded shards='10' rf='1'
27
+
```
28
+
29
+
After this query you get a single sharded table with all its shards already set up. The underlying physical shards live under the `system` database and are hidden from `SHOW TABLES`; you interact with the sharded table by its public name and the system routes operations to the appropriate shards automatically.
30
+
31
+
#### Creating a Replicated Sharded Table
32
+
33
+
To protect against server outages, set up a replication cluster across the nodes you want to participate. Throughout this documentation we'll assume the cluster you created is named `c`. Add all desired nodes by following the [replication](../../Creating_a_cluster/Setting_up_replication/Setting_up_replication.md) instructions, then create the table with the desired replication factor.
34
+
35
+
For example, let's assume you have a 3-node replication cluster and want a table sharded into 10 shards with one copy of each shard on every node. With three nodes participating you set `rf='3'`:
36
+
37
+
```sql
38
+
CREATETABLEc:cluster_sharded shards='10' rf='3'
39
+
```
40
+
41
+
After that you can work with the table by its plain name on any cluster node — `INSERT`, `SELECT`, `UPDATE`, and `DELETE` do not require the cluster prefix. The cluster prefix (`c:`) is only used for DDL such as `CREATE TABLE` and `DROP TABLE`.
42
+
43
+
The default timeout to wait for all processes of shard preparation during creation is 30 seconds. Sometimes, when creating many shards on a replication cluster with multiple nodes, it takes a bit longer due to network latency. If needed, you can increase this timeout via the `timeout` option:
If the timeout is exceeded, the table creation will fail, and you'll need to retry with a longer timeout value.
50
+
51
+
#### Dropping a Sharded Table
52
+
53
+
To drop a sharded table, use the standard `DROP TABLE` command. In a clustered environment, specify the cluster name in the table name to properly target the table you want to drop. `IF EXISTS` is supported.
54
+
55
+
To delete a local sharded table:
56
+
57
+
```sql
58
+
DROPTABLE local_sharded
59
+
DROPTABLE IF EXISTS local_sharded
60
+
```
61
+
62
+
To delete a replicated sharded table:
63
+
64
+
```sql
65
+
DROPTABLE c:cluster_sharded
66
+
DROPTABLE IF EXISTS c:cluster_sharded
67
+
```
68
+
69
+
#### Inspecting Sharded Tables
70
+
71
+
`DESC <table>` returns the user-facing field schema of a sharded table (the columns you declared).
72
+
73
+
`SHOW CREATE TABLE <table>` returns the user-facing definition with `shards='N' rf='M'` — the internal `type='shard'` topology (the per-shard `local=`/`agent=` clauses and md5-named replication cluster) is intentionally hidden. To inspect the resolved internal topology for diagnostics, use `SHOW CREATE TABLE <table> OPTION force=1`.
74
+
75
+
Two extra commands are provided to inspect the state of the sharding subsystem:
76
+
77
+
-`SHOW SHARDING STATUS [[<cluster>:]<table>]` — lists per-shard placement and health. Without arguments it lists all sharded tables; with a table name (optionally cluster-prefixed) it filters to that table. Returned columns: `table`, `shard`, `node`, `status` (`active`/`inactive`), `cluster`, `replication_cluster`, `rf`, and `rf_status` (`ok`/`degraded`/`broken`).
78
+
79
+
```sql
80
+
SHOW SHARDING STATUS
81
+
SHOW SHARDING STATUS cluster_sharded
82
+
SHOW SHARDING STATUS c:cluster_sharded
83
+
```
84
+
85
+
-`SHOW SHARDING MASTER` — shows which node currently runs the sharding master process and whether it's `active` or `inactive`.
0 commit comments