Advanced PostgreSQL: Indexing, Partitioning, Replication · درس

الربط والتجميع حسب الأقسام

اكتشف كيف يستطيع PostgreSQL ربط الجداول المقسّمة وتجميعها قسمًا تلو الآخر لتحقيق مكاسب كبيرة في الأداء.

الدرس 4 من 413 خطوة

الربط والتجميع حسب الأقسام درس مجاني في Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Advanced PostgreSQL: Indexing, Partitioning, Replication، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

What Are Partition-wise Operations

When two tables are partitioned the same way, PostgreSQL can join matching partitions to each other instead of joining the whole tables. This is a partition-wise join.

The same idea applies to grouping: a partition-wise aggregate.

Enabling the Feature

These optimizations are off by default because they increase planning cost. Turn them on per session or in postgresql.conf.

SET enable_partitionwise_join = on;
SET enable_partitionwise_aggregate = on;

Matching Partition Boundaries

For a partition-wise join the tables must share the same partition key type and identical bounds. Otherwise the planner cannot pair partitions.

Example Setup

Two tables partitioned by the same range on customer_id.

CREATE TABLE orders (customer_id int, total numeric)
    PARTITION BY RANGE (customer_id);
CREATE TABLE refunds (customer_id int, amount numeric)
    PARTITION BY RANGE (customer_id);

The Join

With matching partitions, this join runs as several small joins, each fitting in memory more easily.

SELECT o.customer_id, sum(o.total), sum(r.amount)
FROM orders o
JOIN refunds r USING (customer_id)
GROUP BY o.customer_id;

Why It Is Faster

Smaller per-partition joins mean:

  • Smaller hash tables that fit in work_mem
  • Better cache locality
  • Opportunities for parallel workers per partition

Reading the Plan

Use EXPLAIN to confirm. You will see an Append node over several join nodes rather than one giant join.

EXPLAIN
SELECT * FROM orders o JOIN refunds r USING (customer_id);

Partition-wise Aggregate

If you group by the partition key, each partition is aggregated independently and the results are concatenated. No global sort or hash across the whole table is needed.

SELECT customer_id, sum(total)
FROM orders
GROUP BY customer_id;

Planning Cost Trade-off

With many partitions, considering each one increases planning time. Enable these settings only when partition counts are moderate and the query benefits clearly.

Combining with Pruning

Partition-wise joins combine well with partition pruning: pruning removes irrelevant partitions first, then the remaining ones are joined pair-by-pair.

When It Does Not Apply

If only one table is partitioned, or the bounds differ, PostgreSQL falls back to a normal join over the appended partitions.

Quick Check

What is required for a partition-wise join?

Recap

You learned to speed up queries on partitioned tables with partition-wise joins and aggregates. Enable the settings, ensure matching bounds, verify with EXPLAIN, and combine with pruning for the best results.

البدء مجانًا

تعلم Advanced PostgreSQL: Indexing, Partitioning, Replication مع معلم ذكاء اصطناعي — مجانًا

اكتب وقم بتشغيل أكوادك الفعلية في المتصفح، واحصل على مساعدة فورية من معلم ذكاء اصطناعي متاح 24/7، واستمر من حيث توقفت على الويب أو في التطبيق.

الدورات
11
الدروس
44

الأسئلة الشائعة

هل درس «الربط والتجميع حسب الأقسام» مجاني؟

نعم — نص درس «الربط والتجميع حسب الأقسام» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Advanced PostgreSQL: Indexing, Partitioning, Replication، انتقل إلى CoddyKit PRO. تتضمن دورة Advanced PostgreSQL: Indexing, Partitioning, Replication 4 دروس في المجموع.

ماذا ستتعلم في «الربط والتجميع حسب الأقسام»؟

اكتشف كيف يستطيع PostgreSQL ربط الجداول المقسّمة وتجميعها قسمًا تلو الآخر لتحقيق مكاسب كبيرة في الأداء. تتمرن على Advanced PostgreSQL: Indexing, Partitioning, Replication مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Advanced PostgreSQL: Indexing, Partitioning, Replication؟

لا تُشترط خبرة سابقة. Advanced PostgreSQL: Indexing, Partitioning, Replication على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «الربط والتجميع حسب الأقسام»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Advanced PostgreSQL: Indexing, Partitioning, Replication هذا؟

نعم. كل درس في Advanced PostgreSQL: Indexing, Partitioning, Replication يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تحسين الاستعلامات باستخدام التقسيم
  2. إرفاق الأقسام وفصلها
  3. تشذيب الأقسام واستبعادها
  4. الربط والتجميع حسب الأقسام
← العودة إلى Advanced PostgreSQL: Indexing, Partitioning, Replication