A Roaring bitmap cardinality calculation function calculates the cardinality of Roaring bitmap data. OceanBase Database supports the following Roaring bitmap cardinality calculation functions: rb_cardinality(), rb_and_cardinality(), rb_or_cardinality(), rb_xor_cardinality(), rb_andnot_cardinality(), rb_and_null2empty_cardinality(), rb_or_null2empty_cardinality(), and rb_andnot_null2empty_cardinality().
rb_cardinality
rb_cardinality() returns the cardinality of the input Roaring bitmap data. The syntax is as follows:
rb_cardinality(rb)
Here is an example:
SELECT rb_cardinality(rb_from_string('1,2,3'));
+-----------------------------------------+
| rb_cardinality(rb_from_string('1,2,3')) |
+-----------------------------------------+
| 3 |
+-----------------------------------------+
1 row in set
rb_and_cardinality and rb_and_null2empty_cardinality
rb_and_cardinality() performs an AND operation on the two input Roaring bitmaps and returns the cardinality of the resulting Roaring bitmap. The syntax is as follows:
rb_and_cardinality(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here are several examples:
SELECT rb_and_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4'));
+----------------------------------------------------------------------+
| rb_and_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4')) |
+----------------------------------------------------------------------+
| 2 |
+----------------------------------------------------------------------+
1 row in set
SELECT rb_and_cardinality(rb_from_string('1,2,3'), NULL);
+---------------------------------------------------+
| rb_and_cardinality(rb_from_string('1,2,3'), NULL) |
+---------------------------------------------------+
| NULL |
+---------------------------------------------------+
1 row in set
The calculation logic of the rb_and_null2empty_cardinality() function is consistent with that of the rb_and_cardinality() function. The difference is that the rb_and_null2empty_cardinality() function considers a null input as an empty bitmap.
SELECT rb_and_null2empty_cardinality(rb_from_string('1,2,3'), NULL);
+--------------------------------------------------------------+
| rb_and_null2empty_cardinality(rb_from_string('1,2,3'), NULL) |
+--------------------------------------------------------------+
| 0 |
+--------------------------------------------------------------+
1 row in set
rb_or_cardinality and rb_or_null2empty_cardinality
rb_or_cardinality() performs an OR operation on the two input Roaring bitmaps and returns the cardinality of the resulting Roaring bitmap. The syntax is as follows:
rb_or_cardinality(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here are several examples:
SELECT rb_or_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4'));
+---------------------------------------------------------------------+
| rb_or_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4')) |
+---------------------------------------------------------------------+
| 4 |
+---------------------------------------------------------------------+
1 row in set
SELECT rb_or_null2empty_cardinality(rb_from_string('1,2,3'), NULL);
+-------------------------------------------------------------+
| rb_or_null2empty_cardinality(rb_from_string('1,2,3'), NULL) |
+-------------------------------------------------------------+
| 3 |
+-------------------------------------------------------------+
1 row in set
The calculation logic of the rb_or_null2empty_cardinality() function is consistent with that of the rb_or_cardinality() function. The difference is that the rb_or_null2empty_cardinality() function considers a null input as an empty bitmap.
rb_xor_cardinality
rb_xor_cardinality() performs an XOR operation on the two input Roaring bitmaps and returns the cardinality of the resulting Roaring bitmap. The syntax is as follows:
rb_xor_cardinality(rb1, rb2)
The order of the rb1 and rb2 arguments does not affect the result.
Here is an example:
SELECT rb_xor_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4'));
+----------------------------------------------------------------------+
| rb_xor_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4')) |
+----------------------------------------------------------------------+
| 2 |
+----------------------------------------------------------------------+
1 row in set
rb_andnot_cardinality and rb_andnot_null2empty_cardinality
rb_andnot_cardinality() performs a NAND operation on the two input Roaring bitmaps and returns the cardinality of the resulting Roaring bitmap. The syntax is as follows:
rb_andnot_cardinality(rb1, rb2)
rb_andnot_cardinality() subtracts rb2 from rb1 and returns the cardinality of the resulting value.
Here are several examples:
SELECT rb_andnot_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4'));
+-------------------------------------------------------------------------+
| rb_andnot_cardinality(rb_from_string('1,2,3'), rb_from_string('2,3,4')) |
+-------------------------------------------------------------------------+
| 1 |
+-------------------------------------------------------------------------+
1 row in set
SELECT rb_andnot_null2empty_cardinality(rb_from_string('1,2,3'), NULL);
+-----------------------------------------------------------------+
| rb_andnot_null2empty_cardinality(rb_from_string('1,2,3'), NULL) |
+-----------------------------------------------------------------+
| 3 |
+-----------------------------------------------------------------+
1 row in set
The calculation logic of the rb_andnot_null2empty_cardinality() function is consistent with that of the rb_andnot_cardinality() function. The difference is that the rb_andnot_null2empty_cardinality() function considers a null input as an empty bitmap.