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
CREATE TABLE T(h int, r int, v1 int, v2 int, primary key(h, r));
CREATE INDEX my_index on T(v1);
insert into T values (1, 1, 1, 1), (1,2, 1, 2), (1, 3, 1, 3), (1, 4, 1, 4);
select v2 from T where v1 = 1;
In the above example, YSQL performs 1 read rpc to query the index table and find the main table's pks that have v1=1. Then it performs separate read rpcs to the main table's tablet servers one after the other -- 1 rpc for each pk, even though all the pks belong to the same tablet.
In the general case -- even though the main table pks to be queried can belong to different tablets, there are two improvements possible -
Reads for pks that hash to the same tablet server can be batched into the same rpc call
Read rpc to different tablet servers don't have to block each other, they all can be done in parallel
Code path for the 2 steps involved with Index Scan -
YSQL issues an rpc to the index table's tablet server which hosts v1=1 and fetches the pks in the main table that have v1=1 -- this is done as part of the function ybcingettuple()
YSQL iterates through the pks one by one and fetches the value for v2 by sending an rpc to the main table's tablet server which hosts the pk -- this is done via repeated calls to index_getnext() which in turn calls index_fetch_heap()
The text was updated successfully, but these errors were encountered:
This is a non-issue, the read rpcs already fetches data from main table using the primary keys in batches. The missing piece in the issue summary is that ybc_getnext_heaptuple internally prefetches data for the pks found by the index scan.
Also both optimizations mentioned above are already a part of the database.
Thanks to @tanujnay112 for also confirming this by logging the docdb requests using set yb_debug_log_docdb_requests=true.
Jira Link: [DB-423](https://yugabyte.atlassian.net/browse/DB-423)
Description
In the above example, YSQL performs 1 read rpc to query the index table and find the main table's pks that have v1=1. Then it performs separate read rpcs to the main table's tablet servers one after the other -- 1 rpc for each pk, even though all the pks belong to the same tablet.
In the general case -- even though the main table pks to be queried can belong to different tablets, there are two improvements possible -
Code path for the 2 steps involved with Index Scan -
ybcingettuple()
index_getnext()
which in turn callsindex_fetch_heap()
The text was updated successfully, but these errors were encountered: