bloom
extension already enabled, so there’s no need to run create extension
.
Creating and Populating Sample Table
Before creating the index, let’s create a sample table and populate it with data:Creating a Bloom Index
A Bloom index is most useful for queries that filter on multiple columns. You need to specify the indexed columns and configure the number of bits per column (colN
):
Note:
USING bloom
specifies that this is a Bloom filter index and col1 = 4, col2 = 4
defines the number of bits per column to be used in the index (default is 4).Querying with Bloom Index
Once the Bloom index is created, it can be used to optimize queries with equality conditions on indexed columns:Limitations
- Bloom filters are probabilistic and can produce false positives, meaning they may return more results than expected.
- They are best suited for queries filtering multiple indexed columns using equality conditions (
=
). - Unlike B-tree indexes, they do not support range queries (
<
,>
,BETWEEN
).