0Pricing
Advanced PostgreSQL: Indexing, Partitioning, Replication · Aula

Índices BRIN para tabelas particionadas grandes

Aprenda quando os índices de intervalo de blocos superam as árvores B em tabelas particionadas enormes e ordenadas naturalmente.

Índices BRIN para tabelas particionadas grandes é uma aula grátis de Advanced PostgreSQL: Indexing, Partitioning, Replication no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Advanced PostgreSQL: Indexing, Partitioning, Replication, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Advanced PostgreSQL: Indexing, Partitioning, Replication inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

The Scale Problem

On tables with billions of rows, a B-tree index can grow huge and consume a lot of memory. BRIN (Block Range Index) offers a tiny alternative for naturally ordered data.

How BRIN Works

BRIN stores the min and max value per block range instead of one entry per row. A query checks which ranges could contain matching rows and scans only those blocks.

Correlation Is Key

BRIN shines when the column's physical order correlates with its value order, such as an inserted_at timestamp on an append-only table. Random ordering makes BRIN nearly useless.

Creating a BRIN Index

You declare it with USING brin. It is dramatically smaller than a B-tree on the same column.

CREATE INDEX ON measurements USING brin (recorded_at);

pages_per_range

The pages_per_range storage parameter controls granularity. Smaller values give more precise (but larger) indexes.

CREATE INDEX ON measurements USING brin (recorded_at)
  WITH (pages_per_range = 32);

Size Comparison

A B-tree might be many gigabytes on a billion-row table; the equivalent BRIN can be just a few megabytes. The trade-off is BRIN does coarser filtering.

BRIN on Partitions

On a range-partitioned table, create the BRIN on the parent; it propagates to each partition. Within a partition the data is usually well-correlated, so BRIN works great.

CREATE INDEX ON events USING brin (created_at);

Keeping BRIN Fresh

New blocks must be summarized for BRIN to cover them. Autovacuum does this, or you can force it.

SELECT brin_summarize_new_values('measurements_recorded_at_idx');

Verifying with EXPLAIN

Look for a Bitmap Index Scan on the BRIN index followed by a recheck. The recheck confirms candidate blocks really contain matches.

EXPLAIN SELECT * FROM measurements
WHERE recorded_at > now() - interval '1 day';

When Not to Use BRIN

Avoid BRIN for:

  • Columns with random physical order
  • Point lookups needing exact, fast access (use B-tree)
  • Uniqueness enforcement (BRIN cannot)

Combining Strategies

At scale, a common pattern is: range-partition by time, BRIN on the time column for cheap range scans, and a small B-tree on a frequently filtered foreign key.

Quick Check

When is BRIN a strong choice?

Recap

You learned BRIN indexes: tiny block-range summaries ideal for huge, well-correlated partitioned tables. Tune pages_per_range, keep summaries fresh, verify with EXPLAIN, and combine BRIN with selective B-trees.

Perguntas Frequentes

A aula “Índices BRIN para tabelas particionadas grandes” é grátis?

Sim — o texto completo de “Índices BRIN para tabelas particionadas grandes” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Advanced PostgreSQL: Indexing, Partitioning, Replication, atualize para CoddyKit PRO. O curso de Advanced PostgreSQL: Indexing, Partitioning, Replication inclui 4 aulas no total.

O que vou aprender em “Índices BRIN para tabelas particionadas grandes”?

Aprenda quando os índices de intervalo de blocos superam as árvores B em tabelas particionadas enormes e ordenadas naturalmente. Você pratica Advanced PostgreSQL: Indexing, Partitioning, Replication com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Advanced PostgreSQL: Indexing, Partitioning, Replication?

Nenhuma experiência prévia é necessária. Advanced PostgreSQL: Indexing, Partitioning, Replication no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “Índices BRIN para tabelas particionadas grandes”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Advanced PostgreSQL: Indexing, Partitioning, Replication?

Sim. Cada aula de Advanced PostgreSQL: Indexing, Partitioning, Replication inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Aumentando a escala de índices com particionamento
  2. Escolhendo estratégias de índices e partições
  3. Estudos de caso do mundo real
  4. Índices BRIN para tabelas particionadas grandes
← Voltar para Advanced PostgreSQL: Indexing, Partitioning, Replication