[YSQL] Pushdown Limit for Bitmap Scans without ORDER BY clause #21155
Labels
area/ysql
Yugabyte SQL (YSQL)
kind/enhancement
This is an enhancement of an existing feature
priority/medium
Medium priority issue
Jira Link: DB-10089
Description
Generally, a scan with a LIMIT should also have an ORDER BY clause. Bitmap scans return unordered results, so an ORDER BY clause requires all the rows to be fetched, sorted, and then the limit can be applied. So the optimization outlined here is not very applicable to the general case.
If a bitmap scan is used in a subquery used for a
WHERE EXISTS
orWHERE NOT EXISTS
clause, then we are only interested in collecting one row, with no order information. This is a case where a LIMIT is present without an ORDER BY, so it allows for the following optimization to be applied:If the top level node in a Bitmap Scan is a
Bitmap Or
or aBitmap Index Scan
, we know that any ybctid collected by it (or its immediate children) will be returned to the client.If a request is sent with a
LIMIT 10
, then we know that the first 10 ybctids that we collect are all that we need.Consider the query:
Here, we collected 199 ybctids from the index even though we only needed to get 10. Then we requested 100 rows from the main table, even though we also only needed 10.
Using the limit for the
YB Bitmap Table Scan
node should be easy.For the
Bitmap Index Scans
, if the only nodes between them and theYB Bitmap Table Scan
node areBitmap Or
nodes, then they can also have a limit of 10.For example:
Issue Type
kind/enhancement
Warning: Please confirm that this issue does not contain any sensitive information
The text was updated successfully, but these errors were encountered: