Skip to main content

Bitmap Functions

This page provides a comprehensive overview of Bitmap functions in Databend, organized by functionality for easy reference.

Bitmap Operations​

FunctionDescriptionExample
BITMAP_ANDPerforms a bitwise AND operation on two bitmapsBITMAP_AND(BUILD_BITMAP([1,4,5]), BUILD_BITMAP([4,5])) → {4,5}
BITMAP_ORPerforms a bitwise OR operation on two bitmapsBITMAP_OR(BUILD_BITMAP([1,2]), BUILD_BITMAP([2,3])) → {1,2,3}
BITMAP_XORPerforms a bitwise XOR operation on two bitmapsBITMAP_XOR(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3,4])) → {1,4}
BITMAP_NOTPerforms a bitwise NOT operation on a bitmapBITMAP_NOT(BUILD_BITMAP([1,2,3]), 5) → {0,4}
BITMAP_AND_NOTReturns elements in the first bitmap but not in the secondBITMAP_AND_NOT(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3])) → {1}
BITMAP_UNIONCombines multiple bitmaps into oneBITMAP_UNION([BUILD_BITMAP([1,2]), BUILD_BITMAP([2,3])]) → {1,2,3}
BITMAP_INTERSECTReturns the intersection of multiple bitmapsBITMAP_INTERSECT([BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3,4])]) → {2,3}

Bitmap Information​

FunctionDescriptionExample
BITMAP_COUNTReturns the number of elements in a bitmapBITMAP_COUNT(BUILD_BITMAP([1,2,3])) → 3
BITMAP_CONTAINSChecks if a bitmap contains a specific elementBITMAP_CONTAINS(BUILD_BITMAP([1,2,3]), 2) → true
BITMAP_HAS_ANYChecks if a bitmap contains any element from another bitmapBITMAP_HAS_ANY(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([3,4])) → true
BITMAP_HAS_ALLChecks if a bitmap contains all elements from another bitmapBITMAP_HAS_ALL(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3])) → true
BITMAP_MINReturns the minimum element in a bitmapBITMAP_MIN(BUILD_BITMAP([1,2,3])) → 1
BITMAP_MAXReturns the maximum element in a bitmapBITMAP_MAX(BUILD_BITMAP([1,2,3])) → 3
BITMAP_CARDINALITYReturns the number of elements in a bitmapBITMAP_CARDINALITY(BUILD_BITMAP([1,2,3])) → 3

Bitmap Count Operations​

FunctionDescriptionExample
BITMAP_AND_COUNTReturns the count of elements in the bitwise AND of two bitmapsBITMAP_AND_COUNT(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3,4])) → 2
BITMAP_OR_COUNTReturns the count of elements in the bitwise OR of two bitmapsBITMAP_OR_COUNT(BUILD_BITMAP([1,2]), BUILD_BITMAP([2,3])) → 3
BITMAP_XOR_COUNTReturns the count of elements in the bitwise XOR of two bitmapsBITMAP_XOR_COUNT(BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3,4])) → 2
BITMAP_NOT_COUNTReturns the count of elements in the bitwise NOT of a bitmapBITMAP_NOT_COUNT(BUILD_BITMAP([1,2,3]), 5) → 2
INTERSECT_COUNTReturns the count of elements in the intersection of multiple bitmapsINTERSECT_COUNT([BUILD_BITMAP([1,2,3]), BUILD_BITMAP([2,3,4])]) → 2

Bitmap Subset Operations​

FunctionDescriptionExample
SUB_BITMAPExtracts a subset of a bitmapSUB_BITMAP(BUILD_BITMAP([1,2,3,4,5]), 1, 3) → {2,3,4}
BITMAP_SUBSET_IN_RANGEReturns a subset of a bitmap within a rangeBITMAP_SUBSET_IN_RANGE(BUILD_BITMAP([1,2,3,4,5]), 2, 4) → {2,3}
BITMAP_SUBSET_LIMITReturns a subset of a bitmap with a limitBITMAP_SUBSET_LIMIT(BUILD_BITMAP([1,2,3,4,5]), 2, 2) → {3,4}
Try Databend Cloud for FREE

Multimodal, object-storage-native warehouse for BI, vectors, search, and geo.

Snowflake-compatible SQL with automatic scaling.

Sign up and get $200 in credits.

Try it today