انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-019-L03

تقسيم الجداول

  • الدرس 3 من 6
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

في هذا الدرس

split a large table by range or list and use partition pruning.

الموضوعات المخطط لها

  • Declarative partitioning: PARTITION BY RANGE (created_at) with child tables per month.
  • Partition pruning: when the query filters on the partition key, the planner reads only the matching partitions.
  • Benefits: faster maintenance (drop or detach an old partition instead of a huge DELETE), smaller indexes, easier archiving.
  • Rules: the primary key and unique constraints must include the partition key; create partitions ahead of time (or automate).
  • Do not partition small tables; the overhead is not worth it (a typical threshold is tens of millions of rows or hundreds of GB; measure).
تفاصيل المخطط المبدئي

عرض عملي

sql
CREATE TABLE orders (
  id bigint, created_at timestamptz NOT NULL, customer_id bigint, total_cents bigint,
  PRIMARY KEY (id, created_at)
) PARTITION BY RANGE (created_at);
CREATE TABLE orders_2026_01 PARTITION OF orders
  FOR VALUES FROM ('2026-01-01') TO ('2026-02-01');

اختبر فهمك

Why must the primary key include created_at?

أظهر الإجابة

Unique constraints must contain the partition key.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

المختبر والتمارين الاختبار

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

اكتب للبحث في المستويات والمراحل والوحدات والدروس.