BRIN Index (Block-Range Summaries for Huge Datasets)

Last updated: 2026-11-04

BRIN Index (Block-Range Summaries for Huge Datasets)

BRIN (Block Range INdex) stores no per-row keys. It groups the table into ranges of pages (pages_per_range, 128 by default) and keeps one summary per group, so the index stays tiny and suits billion-row tables. The price is that BRIN is lossy: matching rows must be rechecked one by one in the heap, which shows up as Rows Removed by Index Recheck. It only prunes effectively when the physical row order correlates with the indexed column — the classic case is an append-only time-series or log table.

Kindindex
Example LanguageSQL

📝 Syntax

CREATE INDEX <index_name> ON <table_name> USING brin ( <column> ) WITH ( pages_per_range = <pages> )

⚙️ Parameters

index_nameName of the new index.
table_nameThe table to index.
column_nameThe indexed column. Built-in support covers range types (range_inclusion_ops), minmax summaries for integer and timestamp columns, and inet inclusion summaries.
pages_per_rangeNumber of pages covered by each summary, 128 by default. Smaller values prune more precisely but grow the index; larger values shrink the index but may fail to exclude irrelevant pages.

Returns:No return value. On success the command tag is CREATE INDEX.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

CREATE TABLE
INSERT 0 20000
CREATE INDEX
ANALYZE
SET
RESET

-- EXPLAIN: Bitmap Index Scan on idx_brin_span confirms the BRIN index is used
Aggregate  (cost=390.05..390.06 rows=1 width=8)
  ->  Bitmap Heap Scan on idx_demo_brin  (cost=12.03..390.03 rows=5 width=0)
        Recheck Cond: (span @> 199995)
        Rows Removed by Index Recheck: 4923
        Heap Blocks: lossy=32
        Buffers: shared hit=36 read=1
        ->  Bitmap Index Scan on idx_brin_span  (cost=0.00..12.03 rows=20000 width=0)
  Index Cond: (span @> 199995)
  Index Searches: 1
  Buffers: shared hit=4 read=1
Planning Time: 0.215 ms
Execution Time: 0.692 ms

-- Query result
 count 
-------
     5
(1 row)

(The EXPLAIN plans above come from a real PostgreSQL 18.6 run; actual time / Planning Time / Execution Time are indicative values and vary with machine load.
 Note: at only twenty thousand rows this table is far below the size where BRIN pays off, so the planner would normally choose a sequential scan. The example therefore uses SET enable_seqscan = off to force the index path and expose the BRIN plan. In production, with tens of millions of rows and an insertion order correlated with the indexed column, the planner picks BRIN on its own.)

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QBRIN or B-tree — which should I pick?
AFor tens of millions of rows with write-heavy workloads and only a few indexed columns, BRIN's size and write costs win. For smaller tables, or when you need range lookups or a unique constraint, B-tree is the better choice. BRIN cannot back a unique constraint and supports far fewer operators.
QWhat does Rows Removed by Index Recheck mean?
AThe BRIN summary marks a whole page range as "might match", so the index scan returns more candidates than necessary; the heap recheck then discards most of them, and the plan reports how many were dropped. A large number means the summary is coarse — try a smaller pages_per_range.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏