Skip to content

pg_brin_bins

BRIN operator classes using value-bin bitmaps

pg_brin_bins · BRIN operator classes using value-bin bitmaps

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102449pg_brin_binspg_brin_bins1.0FEATPostgreSQLC

PostgreSQL · 15, 16, 17, 18, 19

Usage

Sources:

pg_brin_bins 1.0 adds BRIN operator classes that summarize each block range with a bitmap of value bins. It targets PostgreSQL 15 and later and can help when narrow value bands are interleaved across a large table. Selectivity depends on the data and chosen boundaries.

Create a Binned BRIN Index

A superuser installs this relocatable C extension. No preload or server restart is required. The example creates a table and a deliberately chosen value domain:

CREATE EXTENSION pg_brin_bins;
CREATE TABLE measurements (temperature double precision);
CREATE INDEX measurements_temperature_bins ON measurements USING brin
  (temperature float8_bins_ops (min_boundary_value = -30, max_boundary_value = 200));
SELECT * FROM measurements WHERE temperature >= 10 AND temperature < 20;

Both min_boundary_value and max_boundary_value are required, and the minimum must be smaller. The interval between them is split into 62 equal-width bins; one further bin contains underflow values and one contains overflow values. A block range may be skipped when none of its recorded bins intersects the query. This remains a lossy BRIN summary, with matching rows rechecked.

Types and Boundaries

Use int2_bins_ops, int4_bins_ops, int8_bins_ops, float4_bins_ops, float8_bins_ops, date_bins_ops, timestamp_bins_ops or timestamptz_bins_ops. They support <, <=, =, >= and >, including cross-type comparisons within the integer, float or datetime operator family.

brin_bins_datetime_value(date) returns days since 2000-01-01. Its timestamp overloads return microseconds since that epoch; timestamptz uses UTC. Use this function for datetime boundaries and explicit time zones for fixed timestamp values.

Maintenance

Choose boundaries from the actual distribution, for example reviewed percentiles; outliers share the overflow bins. The number of bins is fixed at 64 and their interior widths are equal. Validate pruning with representative queries and maintain BRIN summaries as data grows. This source revision supplies an initial 1.0 installation and no upgrade script.

The PGXN distribution is 1.0.0; its control and installation SQL retain extension version 1.0.

Table reader