D K
02/27/2026, 8:29 AMSrihith Garlapati
03/02/2026, 9:45 PMCOUNT(DISTINCT bitmap_col), the optimizer rewrites it to BITMAP_UNION_COUNT(bitmap_col), which merges bitmaps via bitwise OR and returns the count of set bits. This then replaces the expensive hash-based dedup + multi-node shuffles with cheap bitwise operations on compressed data.
• Distributed Execution:
◦ each BE node runs BITMAP_UNION locally, then only the compressed bitmap results get shuffled across the network
◦ the final node runs BITMAP_UNION_COUNT to return the cardinality.
▪︎ This avoids the multiple data shuffles that traditional COUNT DISTINCT requires
• With MV acceleration - you can pre-compute bitmap aggregations:
CREATE MATERIALIZED VIEW mv_uv AS
SELECT date, page, BITMAP_UNION(TO_BITMAP(user_id))
FROM visit_log GROUP BY date, page;
Then running SELECT date, COUNT(DISTINCT user_id) FROM visit_log GROUP BY date automatically reads from the MV instead of scanning the base table
Docs: https://docs.starrocks.io/docs/using_starrocks/distinct_values/Using_bitmap/D K
03/03/2026, 10:17 AM