Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YSQL] Support Bitmap Index Only Scans #21144

Open
1 task done
timothy-e opened this issue Feb 22, 2024 · 0 comments
Open
1 task done

[YSQL] Support Bitmap Index Only Scans #21144

timothy-e opened this issue Feb 22, 2024 · 0 comments
Assignees
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue

Comments

@timothy-e
Copy link
Contributor

timothy-e commented Feb 22, 2024

Jira Link: DB-10084

Description

CREATE TABLE test_bitmap_index_only (a INT, b INT, c INT, d INT);
CREATE INDEX ON test_bitmap_index_only (a ASC) INCLUDE (c);
CREATE INDEX ON test_bitmap_index_only (b ASC) INCLUDE (d);
INSERT INTO test_bitmap_index_only SELECT i, i * 2, i * 3, i * 4 FROM generate_series(1, 10000) i;

The following query can be answered by an index only scan:

EXPLAIN SELECT b, d FROM test_bitmap_index_only WHERE b < 100;
                                                    QUERY PLAN
-------------------------------------------------------------------------------------------------------------------
 Index Only Scan using test_bitmap_index_only_b_d_idx on test_bitmap_index_only  (cost=0.00..5.12 rows=10 width=8)
   Index Cond: (b < 100)
(2 rows)

But this query requires requests to the main table, even though all of it's fields are included in its indexes.

EXPLAIN SELECT b, d FROM test_bitmap_index_only WHERE b < 100 OR b > 19900;
                                             QUERY PLAN
----------------------------------------------------------------------------------------------------
 YB Bitmap Table Scan on test_bitmap_index_only  (cost=6.91..11.21 rows=10 width=8)
   ->  BitmapOr  (cost=6.91..6.91 rows=20 width=0)
         ->  Bitmap Index Scan on test_bitmap_index_only_b_d_idx  (cost=0.00..3.45 rows=10 width=0)
               Index Cond: (b < 100)
         ->  Bitmap Index Scan on test_bitmap_index_only_b_d_idx  (cost=0.00..3.45 rows=10 width=0)
               Index Cond: (b > 19900)
(6 rows)

Instead of storing the matching ybctids and using those to query the main table, we could detect that the fields we are requesting are covered by each of the indexes used to access them. We could then store (ybctid, <target_values>) in a hash table instead of a ybctid set and avoid a trip to the main table.

EXPLAIN (ANALYZE, DIST, COSTS OFF) SELECT b, d FROM test_bitmap_index_only WHERE b < 100 OR b > 19900;
                                        QUERY PLAN
------------------------------------------------------------------------------------------
 YB Bitmap Table Scan on test_bitmap_index_only (actual rows=99 loops=1)
   ->  BitmapOr (actual rows=99 loops=1)
         ->  Bitmap Index Scan on test_bitmap_index_only_b_d_idx (actual rows=49 loops=1)
               Index Cond: (b < 100)
               Targets: (b, d)
               Storage Index Read Requests: 1
               Storage Index Rows Scanned: 49
         ->  Bitmap Index Scan on test_bitmap_index_only_b_d_idx (actual rows=50 loops=1)
               Index Cond: (b > 19900)
               Targets: (b, d)
               Storage Index Read Requests: 1
               Storage Index Rows Scanned: 50
 Storage Read Requests: 2
 Storage Rows Scanned: 99
 Storage Write Requests: 0
 Storage Flush Requests: 0
(16 rows)

Issue Type

kind/enhancement

Warning: Please confirm that this issue does not contain any sensitive information

  • I confirm this issue does not contain any sensitive information.
@timothy-e timothy-e added area/ysql Yugabyte SQL (YSQL) status/awaiting-triage Issue awaiting triage labels Feb 22, 2024
@yugabyte-ci yugabyte-ci added kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue labels Feb 22, 2024
@timothy-e timothy-e changed the title [YSQL] Title [YSQL] Support Bitmap Index Only Scans Feb 22, 2024
@timothy-e timothy-e self-assigned this Feb 22, 2024
@sushantrmishra sushantrmishra removed the status/awaiting-triage Issue awaiting triage label Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ysql Yugabyte SQL (YSQL) kind/enhancement This is an enhancement of an existing feature priority/medium Medium priority issue
Projects
None yet
Development

No branches or pull requests

3 participants