大規模な連続データ向けBRINインデックス
BRIN(Block Range INdexes)を学びます。これは、時系列データや追記専用ログのようにデータが自然に並んでいる巨大なテーブルに適した、小容量のインデックスです。
「大規模な連続データ向けBRINインデックス」はCoddyKit上の無料PostgreSQL Performance & Query Optimizationレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはPostgreSQL Performance & Query Optimization学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 PostgreSQL Performance & Query Optimizationコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
What is a BRIN Index?
A BRIN (Block Range INdex) stores summary information about ranges of physical table blocks instead of pointing at individual rows. Each entry covers many pages, so the index is extremely small.
How BRIN Differs from B-tree
A B-tree has one entry per row and can be large. A BRIN keeps just the min and max value for each block range.
- B-tree: precise, big, great for random lookups
- BRIN: approximate, tiny, great for range scans on ordered data
When BRIN Shines
BRIN works best when the column's values correlate with physical storage order. Classic cases:
- Time-series tables ordered by inserted timestamp
- Append-only logs
- Large fact tables loaded in key order
Creating a BRIN Index
Use the USING brin clause. Notice how small and fast it is to build compared to a B-tree on the same column.
CREATE INDEX idx_events_ts_brin
ON events USING brin (created_at);Querying Through a BRIN
A range filter lets the planner skip block ranges whose min/max cannot match, reading only the relevant pages.
EXPLAIN ANALYZE
SELECT * FROM events
WHERE created_at >= '2026-01-01'
AND created_at < '2026-02-01';The pages_per_range Option
You can tune how many pages each summary entry covers. Smaller ranges make the index more precise but larger.
CREATE INDEX idx_events_ts_brin
ON events USING brin (created_at)
WITH (pages_per_range = 32);Why Correlation Matters
If the column is not physically ordered, almost every block range will overlap the search value and BRIN will scan the whole table. Check correlation with the stats view.
SELECT attname, correlation
FROM pg_stats
WHERE tablename = 'events';Summarizing New Data
BRIN entries for freshly inserted blocks may be unsummarized. Run this to summarize them so queries can prune those ranges.
SELECT brin_summarize_new_values('idx_events_ts_brin');Size Comparison
On a billion-row table a B-tree might be tens of gigabytes while a BRIN is a few megabytes. Compare them directly.
SELECT pg_size_pretty(pg_relation_size('idx_events_ts_brin'));Trade-offs to Remember
BRIN is not a free win:
- Useless on randomly ordered columns
- Slower for exact single-row lookups than B-tree
- Needs periodic summarization of new blocks
Pick it when the table is huge and naturally ordered.
Maintaining BRIN over Updates
If existing rows are heavily updated, a block range's min/max may widen and lose precision over time. For volatile data, periodically rebuild the index to restore tight ranges.
REINDEX INDEX idx_events_ts_brin;Quick Check
Test your BRIN knowledge.
Recap
You learned BRIN indexes:
- They store min/max summaries per block range — tiny footprint
- Ideal for large, physically ordered data like time-series
- Created with
USING brin; tunepages_per_range - Check
correlationfirst; summarize new blocks - Avoid them on randomly ordered columns
よくある質問
「大規模な連続データ向けBRINインデックス」レッスンは無料ですか?
はい。「大規模な連続データ向けBRINインデックス」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、PostgreSQL Performance & Query Optimizationコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 PostgreSQL Performance & Query Optimizationコースには全4レッスンが含まれています。
「大規模な連続データ向けBRINインデックス」で何を学びますか?
BRIN(Block Range INdexes)を学びます。これは、時系列データや追記専用ログのようにデータが自然に並んでいる巨大なテーブルに適した、小容量のインデックスです。 ブラウザで直接実行するハンズオンコードでPostgreSQL Performance & Query Optimizationを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
PostgreSQL Performance & Query Optimizationを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのPostgreSQL Performance & Query Optimizationは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「大規模な連続データ向けBRINインデックス」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このPostgreSQL Performance & Query Optimizationレッスンでコードを書いて実行できますか?
はい。すべてのPostgreSQL Performance & Query Optimizationレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Hash、GIN、GiSTインデックス
- 部分インデックスと式インデックス
- カバリングインデックスとインデックスオンリースキャン
- 大規模な連続データ向けBRINインデックス