Bitmap decision functions judge the input bitmap data and return Boolean values. OceanBase Database supports the rb_is_empty() and rb_contains() functions.
rb_is_empty
The rb_is_empty() function judges whether the input bitmap data is empty. Syntax:
rb_is_empty(rb)
When the result is 1, it indicates that the bitmap data is empty. When it is 0, it indicates that the bitmap data is not empty.
Example:
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 is used in the following two ways:
- To judge whether the input first bitmap data (
rb1) contains the input second bitmap data (rb2) completely. - To judge whether the input bitmap data contains a specified offset (
offset).
The two usages are implemented through different syntaxes. Details are as follows.
Usage 1
The rb_contains() function can be used to judge whether the input first bitmap data (rb1) contains the input second bitmap data (rb2) completely. Syntax:
rb_contains(rb1, rb2)
Details:
- The input parameter
rb1serves as the basis for calculation, and the input parameterrb2serves as the bitmap data to be calculated. It checks whether each element inrb2is present inrb1. - The order of parameters
rb1andrb2affects the result. - When the result is
1, it indicates that the first bitmap data is completely contained in the second. When it is0, it indicates that the first is not completely contained in the second.
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 can be used to judge whether the input bitmap data contains a specified offset (offset). Syntax:
rb_contains(rb, offset)
Details:
- The input parameter
rbserves as the basis for calculation, representing a bitmap data. - The offset must be an integer, which is to be checked for existence within the bitmap data
rb. - When the result is
1, it indicates that the offset exists in the bitmap data. When it is0, it indicates the opposite.
Examples:
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
