ArticleslgStudy

science

Block Range Index

Block Range Index is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Block Range Index rather than just read about it. In short: A Block Range Index or BRIN is a database indexing technique. They are intended to improve performance with extremely large tables.

Block Range Index — main illustration
Block Range Index — illustration

Key takeaways

  • Block Range Index belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Block Range Index to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Block Range Index from memory before moving on to harder problems.

Reference excerpt

A Block Range Index or BRIN is a database indexing technique. They are intended to improve performance with extremely large tables. BRIN indexes provide similar benefits to horizontal partitioning or sharding but without needing to explicitly declare partitions. A BRIN is applicable to an index on a table that is large and where the index key value is easily sorted and evaluated with a MinMax function. BRIN were originally proposed by Alvaro Herrera of 2ndQuadrant in 2013 as 'Minmax indexes'. Implementations thus far are tightly coupled to internal implementation and storage techniques for the database tables. This makes them efficient, but limits them to particular vendors. So far PostgreSQL is the only vendor to have announced a live product with this specific feature, in PostgreSQL 9.5. Other vendors have described some similar features, including Oracle, Netezza 'zone maps', Infobright 'data packs', MonetDB and Apache Hive with ORC/Parquet.

Design

BRIN operate by "summarising" large blocks of data into a compact form, which can be efficiently tested to exclude many of them from a database query, early on. These tests exclude a large block of data for each comparison. By reducing the data volume so early on, both by representing large blocks as small tuples, and by eliminating many blocks, BRIN substantially reduce the amount of detailed data that must be examined by the database node on a row-by-row basis. Data storage in large databases is layered and chunked, with the table storage arranged into 'blocks'. Each block contains perhaps 1MB in each chunk and they are retrieved by requesting specific blocks from a disk-based storage layer. BRIN are a lightweight in-memory summary layer above this: each tuple in the index summarises one block as to the range of the data contained therein: its minimum and maximum values, and if the block contains any non-null data for the column(s) of interest. Unlike a traditional index which locates the regions of the table containing values of interest, BRIN act as "negative indexes", showing the blocks that are definitely not of interest and thus do not need to be processed further. Some simple benchmarks suggest a five-fold improvement in search performance with an index scan, compared to the unindexed table. Compared to B-trees, they avoid their maintenance overhead. As BRIN are so lightweight, they may be held entirely in memory, thus avoiding disk overhead during the scan. The same may not be true of B-tree: B-tree requires a tree node for every approximately N rows in the table, where N is the capacity of a single node, thus the index size is large. As BRIN only requires a tuple for each block (of many rows), the index becomes sufficiently small to make the difference between disk and memory. For a 'narrow' table the B-tree index volume approaches that of the table itself; the BRIN may be only 5–15% of it.

Advantages

Search and index scan A large database index would typically use B-tree algorithms. BRIN is not always a substitute for B-tree, it is an improvement on sequential scanning of an index, with particular (and potentially large) advantages when the index meets particular conditions for being ordered and for the search target to be a narrow set of these values. In the general case, with random data, B-tree may still be superior. A particular advantage of the BRIN technique, shared with Oracle Exadata's Smart Scanning, is in the use of this type of index with Big Data or data warehousing applications, where it is known that almost all of the table is irrelevant to the range of interest. BRIN allows the table to be queried in such cases by only retrieving blocks that may contain data of interest and excluding those which are clearly outside the range, or contain no data for this column.

Insert A regular problem with the processing of large tables is that retrieval requires the use of an index, but maintaining this index slows down the addition of new records. Typical practices have been to group additions together and add them as a single bulk transaction, or to drop the index, add the batch of new records and then recreate the index. Both of these are disruptive to simultaneous read / write operations and may not be possible in some continuously operating businesses. With BRIN, the slowdown from maintaining the index is much reduced compared to B-tree. Wong reports that B-tree slowed down additions to an unindexed 10GB table by 85%, but a comparable BRIN only had an overhead of 11%.

Index creation BRIN may be created for extremely large data where B-tree would require horizontal partitioning. Creating the BRIN is also much faster than for a B-tree, by 80%. This would be a useful improvement to refactoring existing database applications that use the drop-add-reindex approach, without requiring code changes.

Implementation

Dependence on table ordering Multiple BRIN may be defined for different columns on a single table. However, there are restrictions. BRIN are only efficient if the ordering of the key values follows the organisation of blocks in the storage layer. In the simplest case, this could require the physical ordering of the table, which is often the creation order of the rows within it, to match the key's order. Where this key is a creation date, that may be a trivial requirement. If the data is truly random, or if there is much churn of the key values in a 'hot' database, the assumptions underlying BRIN may break down. All blocks contain entries "of interest" and so few may be excluded early on by the BRIN range filter. In most cases, BRIN is restricted to a single index per table. Multiple BRIN may be defined, but only one is likely to have suitable ordering. If two (or more) indexes have similar ordering behaviour, it may be possible and useful to define multiple BRIN on the same table. An obvious example is where both a creation date and a record_id column both increase monotonically with the record creation sequence. In other cases, the key value may not be monotonic, but provided that there is still a strong grouping within the record's physical order, BRIN is effective.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Block Range Index

Start with the simplest possible case. Write down what Block Range Index claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Block Range Index before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Block Range Index ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Block Range Index

In research
Block Range Index appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Block Range Index in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Block Range Index is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database index techniques, PostgreSQL, so understanding it makes those chapters shorter.
In everyday life
Look for Block Range Index outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Block Range Index in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Block Range Index means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Block Range Index out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Block Range Index in simple terms?

A Block Range Index or BRIN is a database indexing technique. They are intended to improve performance with extremely large tables.

Why does Block Range Index matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Block Range Index?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Block Range Index.

Tags

  • Database index techniques
  • PostgreSQL

Keep exploring