Skip to content

pgfaceting

fast faceting queries using an inverted index

Overview

PackageVersionCategoryLicenseLanguage
pgfaceting0.2.0TYPEBSD-3-ClauseSQL
IDExtensionBinLibLoadCreateTrustRelocSchema
3640pgfacetingNoNoNoYesNoNofaceting

Version

TypeRepoVersionPG VerPackageDeps
EXTPGDG0.2.01817161514pgfacetingroaringbitmap
RPMPGDG0.2.01817161514pgfaceting_$v-
DEBPGDG0.2.01817161514postgresql-$v-pgfaceting-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
u22.x86_64
u22.aarch64
u24.x86_64
u24.aarch64
u26.x86_64
u26.aarch64

Build

You can build the RPM packages for pgfaceting using pig build:

pig build pkg pgfaceting         # build RPM packages

Install

You can install pgfaceting directly. First, make sure the PGDG repository is added and enabled:

pig repo add pgdg -u          # Add PGDG repo and update cache

Install the extension using pig or apt/yum/dnf:

Install
pig install pgfaceting;          # Install for current active PG version
pig
pig ext install -y pgfaceting -v 18  # PG 18
pig ext install -y pgfaceting -v 17  # PG 17
pig ext install -y pgfaceting -v 16  # PG 16
pig ext install -y pgfaceting -v 15  # PG 15
pig ext install -y pgfaceting -v 14  # PG 14
dnf
dnf install -y pgfaceting_18       # PG 18
dnf install -y pgfaceting_17       # PG 17
dnf install -y pgfaceting_16       # PG 16
dnf install -y pgfaceting_15       # PG 15
dnf install -y pgfaceting_14       # PG 14
apt
apt install -y postgresql-18-pgfaceting   # PG 18
apt install -y postgresql-17-pgfaceting   # PG 17
apt install -y postgresql-16-pgfaceting   # PG 16
apt install -y postgresql-15-pgfaceting   # PG 15
apt install -y postgresql-14-pgfaceting   # PG 14

Create Extension:

CREATE EXTENSION pgfaceting CASCADE;  -- requires: roaringbitmap

Usage

pgfaceting: fast faceted search using inverted indexes with roaring bitmaps

The pgfaceting extension enables rapid facet counting via inverted indexes built with roaring bitmaps. Requires the pg_roaringbitmap extension.

CREATE EXTENSION pgfaceting;

Facet Types

  • plain_facet(column): Use column values directly as facets
  • datetrunc_facet(column, precision): Apply date truncation (e.g., monthly/yearly buckets)
  • bucket_facet(column, buckets): Assign continuous variables to predefined ranges

Key Functions

-- Create facet infrastructure for a table
SELECT pgfaceting.add_faceting_to_table(
    'products',
    'id',
    ARRAY[
        plain_facet('color'),
        plain_facet('size'),
        bucket_facet('price', ARRAY[0, 10, 50, 100, 500])
    ]
);

-- Run maintenance to merge incremental changes
SELECT pgfaceting.run_maintenance();

-- Merge deltas for a specific table
SELECT pgfaceting.merge_deltas('products');

-- Get top N facet values
SELECT pgfaceting.top_values('products', 10);

-- Count results with facet filters
SELECT pgfaceting.count_results('products', filters);

Architecture

The extension maintains two auxiliary tables per indexed table: a main facets table with roaring bitmaps mapping facet values to row IDs, and a delta table for incremental changes between maintenance runs.

Currently supports only 32-bit integer ID columns.

Was this page helpful?