Roaring bitmaps as MySQL/MariaDB User Defined Functions

This development is completed, but only partially tested. Please use it at your own risk.

Storage

UDF functions

prefixes

functions

full list of functions

libmysql_roaring.md

SQL queries for all functions loading

libmysql_roaring.sql

Build and installation

Standalone MySQL/MariaDB

Docker

You will need to add build stage to your Dockerfile. And copy .so and .sql files from it to your MySQL/MariaDB image.

```Dockerfile FROM rust:latest AS build

ENV CARGOREGISTRIESCRATESIOPROTOCOL=sparse

WORKDIR /build

COPY ./mysql_roaring /build

RUN --mount=type=cache,target=/usr/local/cargo/registry \ --mount=type=cache,target=/build/target \ cargo build --release \ && mkdir /output \ && cp target/release/libmysqlroaring.so /output \ && cp libmysqlroaring.sql /output

FROM mariadb

COPY --from=build /output/libmysqlroaring.so /usr/lib/mysql/plugin/ COPY --from=build /output/libmysqlroaring.sql /docker-entrypoint-initdb.d/ ```

Examples

32bit integer

```sql CREATE DATABASE IF NOT EXISTS example;

CREATE TABLE IF NOT EXISTS example.bitmaps (id INT8 UNSIGNED PRIMARY KEY, map LONGBLOB);

TRUNCATE TABLE example.bitmaps;

INSERT INTO example.bitmaps SELECT seq % 10 as id, roaring32groupcreate(CAST(RAND() * POW(2, 31) AS INTEGER)) as map FROM mysql.seq1to_1000000 GROUP BY seq % 10;

SELECT roaring32_count(map) FROM example.bitmaps;

SELECT roaring32groupor_count(map) FROM example.bitmaps; ```

64bit integer

Please note that the 64-bit version may be significantly (6.5x in some my cases) slower than the 32-bit version.

```sql CREATE DATABASE IF NOT EXISTS example;

CREATE TABLE IF NOT EXISTS example.bitmaps (id INT8 UNSIGNED PRIMARY KEY, map LONGBLOB);

TRUNCATE TABLE example.bitmaps;

INSERT INTO example.bitmaps SELECT seq % 10 as id, roaring64groupcreate(CAST(RAND() * POW(2, 63) AS INTEGER)) as map FROM mysql.seq1to_1000000 GROUP BY seq % 10;

SELECT roaring64_count(map) FROM example.bitmaps;

SELECT roaring64groupor_count(map) FROM example.bitmaps; ```