<!-- doc/src/sgml/brin.sgml -->
<sect1 id="brin">
<title>BRIN Indexes</title>
<indexterm>
<primary>index</primary>
<secondary>BRIN</secondary>
</indexterm>
<sect2 id="brin-intro">
<title>Introduction</title>
<para>
<acronym>BRIN</acronym> stands for Block Range Index.
<acronym>BRIN</acronym> is designed for handling very large tables
in which certain columns have some natural correlation with their
physical location within the table.
</para>
<para>
<acronym>BRIN</acronym> works in terms of <firstterm>block ranges</firstterm>
(or <quote>page ranges</quote>).
A block range is a group of pages that are physically
adjacent in the table; for each block range, some summary info is stored
by the index.
For example, a table storing a store's sale orders might have
a date column on which each order was placed, and most of the time
the entries for earlier orders will appear earlier in the table as well;
a table storing a ZIP code column might have all codes for a city
grouped together naturally.
</para>
<para>
<acronym>BRIN</acronym> indexes can satisfy queries via regular bitmap
index scans, and will return all tuples in all pages within each range if
the summary info stored by the index is <firstterm>consistent</firstterm> with the
query conditions.
The query executor is in charge of rechecking these tuples and discarding
those that do not match the query conditions — in other words, these
indexes are lossy.
Because a <acronym>BRIN</acronym> index is very small, scanning the index
adds little overhead compared to a sequential scan, but may avoid scanning
large parts of the table that are known not to contain matching tuples.
</para>
<para>
The specific data that a <acronym>BRIN</acronym> index will store,
as well as the specific queries that the index will be able to satisfy,
depend on the operator class selected for each column of the index.
Data types having a linear sort order can have operator classes that
store the minimum and maximum value within each block range, for instance;
geometrical types might store the bounding box for all the objects
in the block range.
</para>
<para>
The size of the block range is determined at index creation time by
the <literal>pages_per_range</literal> storage parameter. The number of index
entries will be equal to the size of the relation in pages divided by
the selected value for <literal>pages_per_range</literal>. Therefore, the smaller
the number, the larger the index becomes (because of the need to
store more index entries), but at the same time the summary data stored can
be more precise and more data blocks can be skipped during an index scan.
</para>
<sect3 id="brin-operation">
<title>Index Maintenance</title>
<para>
At the time of creation, all existing heap pages are scanned and a
summary index tuple is created for each range, including the
possibly-incomplete range at the end.
As new pages are filled with data, page ranges that are already
summarized will cause the summary information to be updated with data
from the new tuples.
When a new page is created that does not fall within the last
summarized range, the range that the new page belongs to
does not automatically acquire a summary tuple;
those tuples remain unsummarized until a summarization run is
invoked later, creating the initial summary for that range.
</para>
<para>
There are several ways to trigger the initial summarization of a page range.
If the table is vacuumed, either manually or by
<link linkend="autovacuum">autovacuum</link>, all existing unsummarized
page ranges are summarized.
Also, if the index's
<xref linkend="index-reloption-autosummarize"/> parameter is enabled,
which it isn't by default,
whenever autovacuum runs in that database, summarization will occur for all
unsummarized page ranges that have been filled,
regardless of whether