Roaring bitmap judgment functions perform judgment on the input Roaring bitmap data and return a Boolean value. OceanBase Database supports the rb_is_empty() and rb_contains() Roaring bitmap judgment functions.
rb_is_empty
rb_is_empty() judges whether the input Roaring bitmap data is empty. The syntax is as follows:
rb_is_empty(rb)
The returned value 1 indicates that the input bitmap data is empty, and 0 indicates that input bitmap data is not empty.
Here are some examples:
SELECT rb_is_empty(rb_from_string(''));
+---------------------------------+
| rb_is_empty(rb_from_string('')) |
+---------------------------------+
| 1 |
+---------------------------------+
1 row in set
SELECT rb_is_empty(rb_from_string('1,2,3'));
+--------------------------------------+
| rb_is_empty(rb_from_string('1,2,3')) |
+--------------------------------------+
| 0 |
+--------------------------------------+
1 row in set
rb_contains
The rb_contains() function has two use cases:
- To check if the first input bitmap (
rb1) fully contains the second input bitmap (rb2). - To check if the input bitmap contains a specific offset (
offset).
These two use cases are implemented using different syntax. Details are as follows:
Use case 1
The rb_contains() function can be used to determine whether the first input bitmap (rb1) fully contains the second input bitmap (rb2). The syntax is as follows:
rb_contains(rb1, rb2)
Specifically:
- The parameter
rb1serves as the base for the calculation, whilerb2is the bitmap being checked. The function determines whether every element inrb2is also present inrb1. - The order of the parameters
rb1andrb2affects the result. - The function returns
1if rb1 fully containsrb2, and0if it does not.
Here is an example:
SELECT rb_contains(rb_from_string('1,2,3,4,5'), rb_from_string('1,2,3,4'));
+---------------------------------------------------------------------+
| rb_contains(rb_from_string('1,2,3,4,5'), rb_from_string('1,2,3,4')) |
+---------------------------------------------------------------------+
| 1 |
+---------------------------------------------------------------------+
1 row in set
Use case 2
The rb_contains() function can be used to determine whether the input bitmap data contains a specific offset (offset). The syntax is as follows:
rb_contains(rb, offset)
Specifically:
- The parameter
rbserves as the basis for the calculation and is a bitmap dataset. offsetmust be an integer, used to check whether this integer exists in the bitmap datarb.- The function returns
1if the offset is contained withinrb, and0if it is not.
Here is an example:
SELECT rb_contains(rb_from_string('1,2,3,4,5'), 1);
+---------------------------------------------+
| rb_contains(rb_from_string('1,2,3,4,5'), 1) |
+---------------------------------------------+
| 1 |
+---------------------------------------------+
1 row in set
SELECT rb_contains(rb_from_string('1,2,3,4,6'), 5);
+---------------------------------------------+
| rb_contains(rb_from_string('1,2,3,4,6'), 5) |
+---------------------------------------------+
| 0 |
+---------------------------------------------+
1 row in set