Difference between ysql_num_tablets & ysql_num_shards_per_tserver flags in YugabyteDB

103 Views Asked by At

[Question posted by a user on YugabyteDB Community Slack]

Does the ysql_num_tablets G-flag replace the ysql_num_shards_per_tserver G-flag? ysql_num_tablets seems to be currently absent from the online documentation.

2

There are 2 best solutions below

0
On BEST ANSWER

expanding on the answer given already, so if your ysql_num_tablets = -1 (default), then

number of tablets = ysql_num_shards_per_tserver * number of tservers you have.

If however, during your DDL statement to create the table you have already specified the number of tablets then that takes precedence over these params. Here is an example of creating a table with two columns odd and even - with 5 shards.

CREATE TABLE yuga_mannual_split ( odd int, even int ) SPLIT INTO 5 TABLETS ;

Then if you want to insert data

INSERT INTO  yuga_mannual_split  ( SELECT generate_series ( 1,20,2 ) as "odd", generate_series ( 2,20,2) as "even" ) ;
0
On

All gflags are explained also in the source code. ysql_num_tablets is explained here https://github.com/yugabyte/yugabyte-db/blob/b5aa25686b8444d171bd8d89c57342bf4e5b12a7/src/yb/client/client.cc#L220.

It defines the "total" number of tablets for a table or index cluster-wide. While ysql_num_shards_per_tserver defines the number of tablets for each yb-tserver.