Understanding bitmap indexes in postgresql

前端 未结 2 530
一整个雨季
一整个雨季 2021-01-07 22:20

PostgreSQL 9.4

I just encountered the node called Bitmap Index Scan and the concept of so-called underlying bitmap data structure mentioned in this post

2条回答
  •  礼貌的吻别
    2021-01-07 23:04

    The bitmap of pages is created dynamically for each query. It is not cached or re-used, and is discarded at the end of the bitmap index scan.

    It doesn't make sense to create the page bitmap in advance because its contents depend on the query predicates.

    Say you're searching for x=1 and y=2. You have b-tree indexes on x and y. PostgreSQL doesn't combine x and y into a bitmap then search the bitmap. It scans index x for the page address of all pages with x=1 and makes a bitmap where the pages that might contain x=1 are true. Then it scans y looking for the page addresses where y might equal 2, making a bitmap from that. Then it ANDs them to find pages where both x=1 and y=2 might be true. Finally, it scans the table its self, reading only the pages that might contain candidate values, reading each page and keeping only the rows where x=1 and y=2.

    Now, if you're looking for something like a cached, pre-built bitmap index, there is such a thing in PostgreSQL 9.5: BRIN indexes. These are intended for very large tables, and provide a way to find ranges of the table that can be skipped over because they're known not to contain a desired value.

提交回复
热议问题