عرض عملي: من 4 ثوانٍ إلى 40 ms
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
fix one slow Shop endpoint query step by step with evidence.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Find the statement in
pg_stat_statements; capture itsEXPLAIN (ANALYZE, BUFFERS)(about 4 s, sequential scan with a sort). - Read the plan: the filter removes most rows, and the sort spills to disk.
- Add
(customer_id, created_at DESC); re-run and show the sort gone. - Planned mistake: wrap the date column in
date_truncin theWHERE; the index is skipped. Fix: use a half-open range. - Replace
OFFSETwith keyset pagination. - Record before/after plans and timings (about 40 ms).
Prepares MID-013-LAB1.
اختبر فهمك
Which single change removed the sort?
أظهر الإجابة
The composite index matching the ORDER BY.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.