This topic describes how to use the roaringbitmap plug-in provided by ApsaraDB RDS for PostgreSQL to improve query performance.
Prerequisites
Background information
The Roaring bitmap algorithm divides 32-bit integers into 216 chunks. Each chunk stores the 16 most significant digits and uses a container to store the 16 least significant digits. A Roaring bitmap stores containers in a dynamic array as primary indexes. Two types of containers are available: array containers for sparse chunks and bitmap containers for dense chunks. An array container can store up to 4,096 integers. A bitmap container can store more than 4,096 integers.
Roaring bitmaps can use this storage structure to rapidly retrieve specific values. Additionally, Roaring bitmaps provide bitwise operations such as AND, OR, and XOR between the two types of containers. Therefore, Roaring bitmaps can deliver excellent storage and computing performance.
Procedure
Bitmap calculation functions
Function | Input | Output | Description | Example |
---|---|---|---|---|
rb_build | integer[] | roaringbitmap | Creates a Roaring bitmap from an integer array. |
|
rb_and | roaringbitmap,roaringbitmap | roaringbitmap | Performs an AND operation. |
|
rb_or | roaringbitmap,roaringbitmap | roaringbitmap | Performs an OR operation. |
|
rb_xor | roaringbitmap,roaringbitmap | roaringbitmap | Performs an XOR operation. |
|
rb_andnot | roaringbitmap,roaringbitmap | roaringbitmap | Performs an ANDNOT operation. |
|
rb_cardinality | roaringbitmap | integer | Calculates the cardinality. |
|
rb_and_cardinality | roaringbitmap,roaringbitmap | integer | Calculates the cardinality from an AND operation on two Roaring bitmaps. |
|
rb_or_cardinality | roaringbitmap,roaringbitmap | integer | Calculates the cardinality from an OR operation on two Roaring bitmaps. |
|
rb_xor_cardinality | roaringbitmap,roaringbitmap | integer | Calculates the cardinality from an XOR operation on two Roaring bitmaps. |
|
rb_andnot_cardinality | roaringbitmap,roaringbitmap | integer | Calculates the cardinality from an ANDNOT operation on two Roaring bitmaps. |
|
rb_is_empty | roaringbitmap | boolean | Checks whether a Roaring bitmap is empty. |
|
rb_equals | roaringbitmap,roaringbitmap | boolean | Checks whether two Roaring bitmaps are the same. |
|
rb_intersect | roaringbitmap,roaringbitmap | boolean | Checks whether two Roaring bitmaps intersect. |
|
rb_remove | roaringbitmap,integer | roaringbitmap | Removes an offset from a Roaring bitmap. |
|
rb_flip | roaringbitmap,integer,integer | roaringbitmap | Flips specific offsets in a Roaring bitmap. |
|
rb_minimum | roaringbitmap | integer | Returns the smallest offset in a Roaring bitmap. If the Roaring bitmap is empty, the value -1 is returned. |
|
rb_maximum | roaringbitmap | integer | Returns the largest offset in a Roaring bitmap. If the Roaring bitmap is empty, the value 0 is returned. |
|
rb_rank | roaringbitmap,integer | integer | Returns the number of elements that are smaller than or equal to a specified offset in a Roaring bitmap. |
|
rb_iterate | roaringbitmap | setof integer | Returns a list of offsets from a Roaring bitmap. |
|
Bitmap aggregate functions
Function | Input | Output | Description | Example |
---|---|---|---|---|
rb_build_agg | integer | roaringbitmap | Creates a Roaring bitmap from a group of offsets. |
|
rb_or_agg | roaringbitmap | roaringbitmap | Performs an OR aggregate operation. |
|
rb_and_agg | roaringbitmap | roaringbitmap | Performs an AND aggregate operation. |
|
rb_xor_agg | roaringbitmap | roaringbitmap | Performs an XOR aggregate operation. |
|
rb_or_cardinality_agg | roaringbitmap | integer | Calculates the cardinality from an OR aggregate operation on two Roaring bitmaps. |
|
rb_and_cardinality_agg | roaringbitmap | integer | Calculates the cardinality from an AND aggregate operation on two Roaring bitmaps. |
|
rb_xor_cardinality_agg | roaringbitmap | integer | Calculates the cardinality from an XOR aggregate operation on two Roaring bitmaps. |
|