فهارس BRIN للبيانات التسلسلية الكبيرة
اكتشف BRIN (Block Range INdexes)، وهو نوع فهرس صغير مثالي للجداول الضخمة ذات البيانات المرتبة طبيعيًا، مثل السلاسل الزمنية والسجلات التي تُضاف فقط
فهارس BRIN للبيانات التسلسلية الكبيرة درس مجاني في PostgreSQL Performance & Query Optimization على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في 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/7) وفتح باقي دورة PostgreSQL Performance & Query Optimization، انتقل إلى CoddyKit PRO. تتضمن دورة PostgreSQL Performance & Query Optimization 4 دروس في المجموع.
ماذا ستتعلم في «فهارس BRIN للبيانات التسلسلية الكبيرة»؟
اكتشف BRIN (Block Range INdexes)، وهو نوع فهرس صغير مثالي للجداول الضخمة ذات البيانات المرتبة طبيعيًا، مثل السلاسل الزمنية والسجلات التي تُضاف فقط تتمرن على PostgreSQL Performance & Query Optimization مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ PostgreSQL Performance & Query Optimization؟
لا تُشترط خبرة سابقة. PostgreSQL Performance & Query Optimization على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.
كم من الوقت يستغرق درس «فهارس BRIN للبيانات التسلسلية الكبيرة»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس PostgreSQL Performance & Query Optimization هذا؟
نعم. كل درس في PostgreSQL Performance & Query Optimization يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- فهارس Hash وGIN وGiST
- الفهارس الجزئية وفهارس التعبيرات
- الفهارس المغطية وعمليات المسح بالفهرس فقط
- فهارس BRIN للبيانات التسلسلية الكبيرة