Roaring bitmap operation functions perform basic operations between Roaring bitmap data. OceanBase Database supports the following Roaring bitmap operation functions: rb_and(), rb_or(), rb_xor(), rb_andnot(), rb_and_null2empty(), rb_or_null2empty(), and rb_andnot_null2empty().
rb_and and rb_and_null2empty
rb_and() calculates the intersection between two Roaring bitmaps. The syntax is as follows:
rb_and(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here are some examples:
SELECT rb_to_string(rb_and(rb_from_string('1,2,3'), rb_from_string('2,3,4')));
+------------------------------------------------------------------------+
| rb_to_string(rb_and(rb_from_string('1,2,3'), rb_from_string('2,3,4'))) |
+------------------------------------------------------------------------+
| 2,3 |
+------------------------------------------------------------------------+
1 row in set
SELECT rb_to_string(rb_and(rb_from_string('1,2,3'), NULL));
+-----------------------------------------------------+
| rb_to_string(rb_and(rb_from_string('1,2,3'), NULL)) |
+-----------------------------------------------------+
| NULL |
+-----------------------------------------------------+
1 row in set
The calculation logic of the rb_and_null2empty() function is consistent with that of the rb_and() function. The difference is that the rb_and_null2empty() function considers a null input as an empty bitmap.
SELECT rb_to_string(rb_and_null2empty(rb_from_string('1,2,3'), NULL));
+----------------------------------------------------------------+
| rb_to_string(rb_and_null2empty(rb_from_string('1,2,3'), NULL)) |
+----------------------------------------------------------------+
| |
+----------------------------------------------------------------+
1 row in set
rb_or and rb_or_null2empty
rb_or() calculates the union of two Roaring bitmaps. The syntax is as follows:
rb_or(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here is an example:
SELECT rb_to_string(rb_or(rb_from_string('1,2,3'), rb_from_string('2,3,4')));
+-----------------------------------------------------------------------+
| rb_to_string(rb_or(rb_from_string('1,2,3'), rb_from_string('2,3,4'))) |
+-----------------------------------------------------------------------+
| 1,2,3,4 |
+-----------------------------------------------------------------------+
1 row in set
The calculation logic of the rb_or_null2empty() function is consistent with that of the rb_or() function. The difference is that the rb_or_null2empty() function considers a null input as an empty bitmap.
rb_xor
rb_xor() performs an XOR operation on two Roaring bitmaps. The syntax is as follows:
rb_xor(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here is an example:
SELECT rb_to_string(rb_xor(rb_from_string('1,2,3'), rb_from_string('2,3,4')));
+------------------------------------------------------------------------+
| rb_to_string(rb_xor(rb_from_string('1,2,3'), rb_from_string('2,3,4'))) |
+------------------------------------------------------------------------+
| 1,4 |
+------------------------------------------------------------------------+
1 row in set
rb_andnot and rb_andnot_null2empty
rb_andnot() performs a NAND operation on two Roaring bitmaps. The syntax is as follows:
rb_andnot(rb1, rb2)
rb_andnot() subtracts rb2 from rb1 and returns the resulting Roaring bitmap.
Here is an example:
SELECT rb_to_string(rb_andnot(rb_from_string('1,2,3'), rb_from_string('2,3,4')));
+---------------------------------------------------------------------------+
| rb_to_string(rb_andnot(rb_from_string('1,2,3'), rb_from_string('2,3,4'))) |
+---------------------------------------------------------------------------+
| 1 |
+---------------------------------------------------------------------------+
1 row in set
The calculation logic of the rb_andnot_null2empty() function is consistent with that of the rb_andnot() function. The difference is that the rb_andnot_null2empty() function considers a null input as an empty bitmap.