Bitmap decision functions
Bitmap decision functions perform some operations on the input bitmap data and return a Boolean value. The rb_is_empty() and rb_contains() functions are the bitmap decision functions supported by seekdb.
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)
If the function returns 1, the input bitmap data is empty. If the function returns 0, the 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 (0.001 sec)
SELECT rb_is_empty(rb_from_string('1,2,3'));
+--------------------------------------+
| rb_is_empty(rb_from_string('1,2,3')) |
+--------------------------------------+
| 0 |
+--------------------------------------+
1 row in set (0.001 sec)
rb_contains
The rb_contains() function has two usage scenarios:
- It determines whether the first input bitmap data (
rb1) completely contains the second input bitmap data (rb2). - It determines whether the input bitmap data contains a specific offset (
offset).
The two scenarios are implemented using different syntaxes. The following sections describe the two scenarios.
Scenario 1
The rb_contains() function can be used to determine whether the first input bitmap data (rb1) completely contains the second input bitmap data (rb2). The syntax is as follows:
rb_contains(rb1, rb2)
The following points apply to this scenario:
- The input parameter
rb1serves as the basis for the calculation, and the input parameterrb2is the bitmap data to be calculated. That is, whether each element inrb2exists inrb1. - The order of the
rb1andrb2parameters affects the result. - If the function returns
1,rb1completely containsrb2. If the function returns0,rb1does not completely containrb2.
Here are some examples:
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 (0.001 sec)
Scenario 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)
The following points apply to this scenario:
- The input parameter
rbserves as the basis for the calculation, and it is a bitmap data. offsetmust be an integer, which is used to determine whether the integer exists in the bitmap datarb.- If the function returns
1, the input bitmap data contains the offset. If the function returns0, the input bitmap data does not contain the offset.
Here are some 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 (0.001 sec)
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 (0.001 sec)