64.1. Introduction
BRIN stands for Block Range Index.BRIN is designed for handling very large tables in which certain columns have some natural correlation with their physical location within the table.
BRIN 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 isconsistent 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 aBRIN 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.
The specific data that aBRIN 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.
There are several ways to trigger the initial summarization of a page range. If the table is vacuumed, either manually or byautovacuum, all existing unsummarized page ranges are summarized. Also, if the index'sautosummarize 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 the table itself is processed by autovacuum; see below.
Lastly, the following functions can be used:
brin_summarize_new_values(regclass) which summarizes all unsummarized ranges; |
brin_summarize_range(regclass, bigint) which summarizes only the range containing the given page, if it is unsummarized. |
When autosummarization is enabled, a request is sent toautovacuum
to execute a targeted summarization for a block range when an insertion is detected for the first item of the first page of the next block range, to be fulfilled the next time an autovacuum worker finishes running in the same database. If the request queue is full, the request is not recorded and a message is sent to the server log:
LOG: request for BRIN range summarization for index "brin_wi_idx" page 128 was not recorded
When this happens, the range will remain unsummarized until the next regular vacuum run on the table, or one of the functions mentioned above are invoked.
Conversely, a range can be de-summarized using thebrin_desummarize_range(regclass, bigint)
function, which is useful when the index tuple is no longer a very good representation because the existing values have changed. SeeSection 9.26.8 for details.