BRIN-Indizes für große partitionierte Tabellen
Lernen Sie, wann Block-Range-Indizes bei riesigen, natürlich geordneten partitionierten Tabellen B-Bäume übertreffen.
BRIN-Indizes für große partitionierte Tabellen ist eine kostenlose Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Advanced PostgreSQL: Indexing, Partitioning, Replication-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
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.
Häufig gestellte Fragen
Ist die Lektion „BRIN-Indizes für große partitionierte Tabellen“ kostenlos?
Ja — der vollständige Text von „BRIN-Indizes für große partitionierte Tabellen“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Advanced PostgreSQL: Indexing, Partitioning, Replication-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „BRIN-Indizes für große partitionierte Tabellen“?
Lernen Sie, wann Block-Range-Indizes bei riesigen, natürlich geordneten partitionierten Tabellen B-Bäume übertreffen. Du übst Advanced PostgreSQL: Indexing, Partitioning, Replication mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Advanced PostgreSQL: Indexing, Partitioning, Replication zu starten?
Keine Vorkenntnisse erforderlich. Advanced PostgreSQL: Indexing, Partitioning, Replication auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „BRIN-Indizes für große partitionierte Tabellen“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion Code schreiben und ausführen?
Ja. Jede Advanced PostgreSQL: Indexing, Partitioning, Replication-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Indizes mit Partitionierung skalieren
- Index- und Partitionierungsstrategien auswählen
- Fallstudien aus der Praxis
- BRIN-Indizes für große partitionierte Tabellen