Is it possible to know for a specific row on which tablet it resides?
I have found the hash value of the primary key against a record using yb_hash_code()
. Assuming the value is 44277.
I have also checked that hash range of one tablet is [0xAAA8, 0xD551] -> [43688, 54609]. Hence, I can conclude that the row belongs to this tablet only.
Is this correct?
Yes, you can use yb_hash_code
https://docs.yugabyte.com/preview/api/ysql/exprs/func_yb_hash_code/ on hash-sharded tables. A row can only belong to 1 tablet (and it’s peers).
The same logic is used by yb-tserver underneath, and smart clients (only in YCQL for now).
One thing to note about yb_hash_code
is that it can return a different value depending on the data type passed to it:
yugabyte=# SELECT yb_hash_code(44277::INT), yb_hash_code('44277'::VARCHAR);
yb_hash_code | yb_hash_code
--------------+--------------
62204 | 32757
(1 row)
Therefore you should use the exact column types as in the primary key of the table.