Environment
- YugabyteDB
Issue
In YugabyteDB, the data is distributed across tablets and you may want to know how many rows are in each tablet. This can be useful for debugging certain issues, finding hotspots, or for general monitoring.
This guide will show you how to get the count of rows per tablet.
Overview
To get the count of rows per tablet, first you need to get the partition start and end keys. Then, you can use partition_hash()
for YCQL and yb_hash_code()
for YSQL and get the count of rows per tablet.
Getting partition start and end keys and Hash Columns
To get the partition start and end keys, you can follow the steps below:
- Go to Master UI
- You can either use the YBA UI
- Click Nodes then click on the Master node (This will open the Master UI)
- Or you can use the Master UI directly
- Go to
http://<master-node-ip>:7000/
- Go to
- You can either use the YBA UI
- Click on Tables on the left side
- Click on the table you want to get the number of rows.
- Look for the tablet you want to get the number of rows and you should see below information shown in the image below: (For example: 5a527c282f9040dab14d01539cf1e075)
- 0x5555 - Partition start key
- 0xAAA9 - Partition end key
-
id
andfname
are partition hash columns
Converting partition start and end keys to decimal
To convert the partition start and end keys to decimal, you can use the below command or use any online converter.
$ echo $((0x5555))
21845
$ echo $((0xAAA9))
43689
Getting the count of rows per tablet
YCQL
- Connect to the YCQL shell or any YCQL client
- Run the below query to get the count of rows per tablet
- Note that you need to specify all the partition hash columns in the
partition_hash()
function
- Note that you need to specify all the partition hash columns in the
SELECT COUNT(*) FROM <table-name> WHERE partition_hash(<partition,hash,columns>) >= 21845 AND partition_hash(<artition,hash,columns>) <= 43689;
Example
ycqlsh> use k1;
ycqlsh:k1> SELECT count(*) FROM t4 WHERE partition_hash(id,fname) >= 21845 AND partition_hash(id,fname) <= 43689;
count
-------
3289
(1 rows)
ycqlsh:k1>
YSQL
- Connect to the YSQL shell or any YSQL client
- Run the below query to get the count of rows per tablet
- Note that you need to specify all the partition hash columns in the
yb_hash_code()
function
- Note that you need to specify all the partition hash columns in the
SELECT COUNT(*) FROM <table-name> WHERE yb_hash_code(<artition,hash,columns>) >= 21845 AND yb_hash_code(<artition,hash,columns>) <= 43689;
Example
yugabyte=# SELECT count(*) FROM t4 WHERE yb_hash_code(id,fname) >= 21845 AND yb_hash_code(id,fname) <= 43689;
count
-------
3289
(1 row)
Comments
0 comments
Please sign in to leave a comment.