Bitmap predicate functions perform certain checks on the input bitmap data and return a boolean value. OceanBase AI Database currently supports the following bitmap predicate functions: rb_is_empty() and rb_contains().
rb_is_empty
The rb_is_empty() function determines whether the input bitmap data is empty. The syntax is as follows:
rb_is_empty(rb)
A return value of 1 indicates the field is empty, and 0 indicates the field is not empty.
An example is as follows:
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 usages:
- Checks whether the first bitmap data (
rb1) completely contains the second bitmap data (rb2). - Checks whether the input bitmap data contains a specific offset (
offset).
The two usages are implemented through different syntaxes. The details are as follows.
Usage 1
The rb_contains() function determines whether the first bitmap data input (rb1) completely contains the second bitmap data input (rb2). The syntax is as follows:
rb_contains(rb1, rb2)
The details are as follows:
- The input parameter
rb1serves as the base for computation, while the input parameterrb2contains the bitmap data to be calculated. Specifically,rb2indicates whether each element is present inrb1. - The order of the parameters
rb1andrb2affects the result. - The return value
1indicates a complete subset, and0indicates a partial subset.
For 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
Usage 2
The rb_contains() function determines whether the input bitmap data contains a specific offset (offset). The syntax is as follows:
rb_contains(rb, offset)
The details are as follows:
- The input parameter
rbis the calculation basis, which is a bitmap data. offsetmust be an integer, used to determine whether this integer exists in the bitmap datarb.- The return value
1indicates inclusion, and0indicates exclusion.
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