len elements from a BITMAP value src starting from the position specified by offset. The output elements are a subset of src.
This function is mainly used for scenarios such as paginated queries. It is supported from v2.5.
This function is similar to bitmap_subset_limit. The difference is that this function intercepts elements starting from an offset whereas bitmap_subset_limit intercepts elements starting from an element value (start_range).
Syntax
Parameters
src: the BITMAP value from which you want to obtain elements.offset: the starting position. It must be a BIGINT value. Note the following points when you useoffset:- Offsets start from 0.
- Negative offsets are counted from right to left. See Examples 3 and 4.
- If the starting position specified by
offsetexceeds the actual length of the BITMAP value, NULL is returned. See Example 6.
len: the number of elements to obtain. It must be a BIGINT value greater than or equal to 1. If the number of matching elements is less than the value oflen, all the matching elements are returned. See Examples 2, 3, and 7.
Return value
Returns a value of the BITMAP type. NULL is returned if any of the input parameters is invalid.Examples
In the following examples, the input of sub_bitmap() is the output of bitmap_from_string. For example,bitmap_from_string('1,1,3,1,5,3,5,7,7,9') returns 1, 3, 5, 7, 9. sub_bitmap() takes this BITMAP value as the input.
Example 1: Obtain two elements from the BITMAP value with the offset set to 0.
-10 is an invalid input of len.
1,3,5,7,9. NULL is returned.
len is set to 5 but only two elements match the condition. All of these two elements are returned.