عرض عملي: تقدير خاطئ وكيف تصلحه الإحصائيات
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
diagnose a bad plan caused by a wrong row estimate.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Create correlated columns (
country,currency) and a query filtering on both; the planner estimates 5 rows, actual is 300 000. - Show the nested loop chosen because of the underestimate and its runtime.
- Run
CREATE STATISTICS s (dependencies) ON country, currency FROM orders; ANALYZE orders;. - Planned mistake: forget to run
ANALYZEafter creating the statistics; the estimate does not change. Fix: analyze. - Re-run: estimate close to actual, plan switches to a hash join, time drops.
اختبر فهمك
Why was the estimate wrong?
أظهر الإجابة
The planner assumed the two columns were independent.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.