أساسيات فهرس B-tree
استكشف نوع الفهارس الأكثر شيوعًا، وهو B-tree، وبنيته وكيف يسهّل البحث السريع عن البيانات في PostgreSQL.
أساسيات فهرس B-tree درس مجاني في Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Advanced PostgreSQL: Indexing, Partitioning, Replication، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
B-Tree Index Basics
Meet the B-tree index — PostgreSQL's default and most common type, and the workhorse behind fast, efficient data retrieval.
Speeding Up Data Access
A B-tree index acts like a book's index: instead of a full table scan, it points straight to the rows you want, saving huge amounts of time.
What the 'B' Means
The B in B-tree means Balanced: all leaf nodes sit at the same depth, so any lookup takes about the same time — consistent, predictable speed.
B-Tree Structure: Nodes
A B-tree is an upside-down tree: a root node where searches begin, internal nodes that guide the way, and leaf nodes pointing to real rows.
How a B-Tree Search Works
A B-tree search starts at the root, compares your value to keys to pick the next child, and walks down to a leaf that points at the row.
B-Tree vs. Full Scan (Concept)
A full scan reads every row top to bottom. A B-tree index scan reads a few index pages, then jumps straight to the matching rows. Far faster.
When PostgreSQL Uses B-Trees
PostgreSQL reaches for B-trees on equality checks, range scans, ORDER BY sorting, and joins — which is why they're the default index type.
Creating Your First B-Tree Index
Create one with CREATE INDEX — PostgreSQL builds a B-tree by default. The code indexes the email column of a users table.
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE
);
CREATE INDEX idx_users_email ON users (email);Confirming Index Use with EXPLAIN
Run EXPLAIN to see the query plan. Spot Index Scan in the output and you know your index is actually being used.
CREATE TABLE products (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
price DECIMAL(10, 2)
);
CREATE INDEX idx_products_price ON products (price);
EXPLAIN SELECT * FROM products WHERE price > 50;Quick Check: B-Tree Purpose
What is the primary benefit of using a B-tree index in PostgreSQL?
B-Tree Basics Recap
That's the B-tree: a balanced tree of root, internal, and leaf nodes powering equality, range, sort, and join queries. Create with CREATE INDEX, verify with EXPLAIN.
الأسئلة الشائعة
هل درس «أساسيات فهرس B-tree» مجاني؟
نعم — نص درس «أساسيات فهرس B-tree» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Advanced PostgreSQL: Indexing, Partitioning, Replication، انتقل إلى CoddyKit PRO. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.
ماذا ستتعلم في «أساسيات فهرس B-tree»؟
استكشف نوع الفهارس الأكثر شيوعًا، وهو B-tree، وبنيته وكيف يسهّل البحث السريع عن البيانات في PostgreSQL. تتمرن على Advanced PostgreSQL: Indexing, Partitioning, Replication مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Advanced PostgreSQL: Indexing, Partitioning, Replication؟
لا تُشترط خبرة سابقة. Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «أساسيات فهرس B-tree»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Advanced PostgreSQL: Indexing, Partitioning, Replication هذا؟
نعم. كل درس في Advanced PostgreSQL: Indexing, Partitioning, Replication يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- أهمية الفهارس
- أساسيات فهرس B-tree
- إنشاء الفهارس وحذفها
- فهارس المفاتيح الفريدة والمفاتيح الأساسية