# Querying proper instance(leader) based on parition key

**URL:** https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495
**Category:** General
**Created:** [June 10, 2025, 5:15pm UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495 "2025-06-10T17:15:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![TimurMannapov](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimurMannapov](https://forum.yugabyte.com/u/TimurMannapov)
#### Post date: [June 10, 2025, 5:15pm UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495/1 "2025-06-10T17:15:11Z")

</div>

Hello!  
We are researching possibility to use Yugabyte(YSQL) and found out that there is a lot of data transfered between nodes if query is executed not against leader. In our benchmarks difference is nearly 2x.  
When random node is queried we have 2.3 GB/s, when leader is queried - 5.5GB/s

Query is quite simple - it reads all data by partition key

```auto
SELECT customerid, blob
	FROM filters.customersdefault
	WHERE tenantid = @tenantId AND partitionid = @partitionId

```

Table structure is: tenant\_id, partition\_id, id, blob\_data. PK ((tenant\_id, partition\_id), id).

Is there are a way to query tablet leaders, so connection with proper host will be constructed by application?  
So fаr we can obtain hash\_split value and tablets per node, but can’t find how to identify leader of tablet (unless using UI at :7000).  
yb\_hash\_code - to get hash value  
yb\_local\_tablets - to get all tablet “ranges”

Thanks in advance!

---

<div class="post-metadata">

### Author: ![Jim\_Knicely](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/jim_knicely/32/668_2.png) [@Jim\_Knicely](https://forum.yugabyte.com/u/Jim_Knicely)
#### Post date: [June 10, 2025, 5:53pm UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495/2 "2025-06-10T17:53:27Z")

</div>

Maybe explore [Follower Reads](https://docs.yugabyte.com/preview/explore/going-beyond-sql/follower-reads-ysql/#follower-reads)?

Maybe this is helpful too?  
[Map a Table Row to the Tablet Leader Node](https://yugabytedb.tips/map-a-table-row-to-the-tablet-leader-node/)

---

<div class="post-metadata">

### Author: ![Jim\_Knicely](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/jim_knicely/32/668_2.png) [@Jim\_Knicely](https://forum.yugabyte.com/u/Jim_Knicely)
#### Post date: [June 10, 2025, 5:54pm UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495/3 "2025-06-10T17:54:42Z")

</div>

Or this one?  
[Display Tablet Leader/Follower Status on a Node](https://yugabytedb.tips/display-tablet-leader-follower-status-on-a-node/)

---

<div class="post-metadata">

### Author: ![TimurMannapov](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@TimurMannapov](https://forum.yugabyte.com/u/TimurMannapov)
#### Post date: [June 11, 2025, 8:44am UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495/4 "2025-06-11T08:44:31Z")

</div>

Using follower readers will be a little trade off, which I would like to avoid if possible.  
It’s sad that there is no simple YSQL query for this, but at least there is a way to get this data.  
Thank you!

---

<div class="post-metadata">

### Author: ![kannan](https://yyz1.discourse-cdn.com/flex027/user_avatar/forum.yugabyte.com/kannan/32/18_2.png) [@kannan](https://forum.yugabyte.com/u/kannan)
#### Post date: [June 11, 2025, 8:55pm UTC](https://forum.yugabyte.com/t/querying-proper-instance-leader-based-on-parition-key/4495/5 "2025-06-11T20:55:04Z")

</div>

hi @TimurMannapov –

Good point.

For YCQL, we have a virtual/system table `system.partitions`, which provides the location of the tablets and who the leader is etc.

```auto
ycqlsh:k> select * from system.partitions where keyspace_name='k' and table_name='t';

 keyspace_name | table_name | start_key | end_key | id | replica_addresses
---------------+------------+-----------+---------+--------------------------------------+-------------------------
             k | t | 0x | 0x8000 | 861d6bfc-ee6a-62be-1b43-83629ace5b00 | {'127.0.0.1': 'LEADER'}
             k | t | 0x8000 | 0x | 564780f6-0f89-48af-f74c-cc4515b2de4e | {'127.0.0.1': 'LEADER'}

```

We’ll look into exposing something equivalent like this, as a SQL view, for YSQL tables as well.
