كل المقررات

الرئيسية / مقرر قاعدة البيانات / الفصل 11 الجزء 1

الفصل 11 (الجزء 1): Query Processing and Optimization

How a query is executed

على طول: الاستعلام بيمر بمراحل لحد ما يتنفذ: parsing وبعدين خطة تنفيذ.

فيديو المحاضرة

فيديو المحاضرة

بعد الفيديو: الأمثلة والاختبار والتمارين والمشروع الصغير تحت.

رسوم متحركة

شجرة الاستعلام

أمثلة SQL

أمثلة قصيرة وبسيطة

الكود قصير والنتيجة اتجرّبت فعلاً. عدّل في المحرر واضغط شغّل.

المثال ١: خطة بدون index

Sample output (press Run to produce your own):
id | parent | notused | detail  
---+--------+---------+---------
2  | 0      | 0       | SCAN emp
(1 row)

المثال ٢: خطة join

Sample output (press Run to produce your own):
id | parent | notused | detail                                      
---+--------+---------+---------------------------------------------
3  | 0      | 0       | SCAN e                                      
7  | 0      | 0       | SEARCH d USING INTEGER PRIMARY KEY (rowid=?)
(2 rows)

المثال ٣: النتيجة نفسها

Sample output (press Run to produce your own):
label | n 
------+---
HR    | 40
IT    | 40
Sales | 40
(3 rows)

افتح الموضوع المقابل في صفحة LiU TDDD12

اختبار قصير

اختبر فهمك

1. The query optimizer's job is to:

2. Leaves of a query tree are:

3. An index search is best when the condition is:

4. Nested loop join is slow because:

5. The DBMS keeps statistics to:

تمارين برمجة

جرّب بإيدك

التمرين 1

اعرض الـ plan لـ SELECT * FROM emp WHERE id = 300 وفسّر ليه مفيش SCAN.

Show the plan for SELECT * FROM emp WHERE id = 300 and explain why there is no SCAN.

(output appears here)

التمرين 2

اعرض الـ plan لـ join بين emp وـ dept من غير شرط.

Show the plan for a join between emp and dept with no filter.

(output appears here)

مشروع صغير في آخر المحاضرة

اقرا خطط التنفيذ لتقرير

الداتا: Generated sample data: 600 employees in 3 departments. Written for this course (our own data, free to reuse).

License / source: Our own sample data; SQLite is in the public domain. Dataset page

الخطوات

  1. الجداول بتتولّد في الـ starter.
  2. اعرض الـ plan لـ: موظفين IT في Cairo.
  3. اعرض النتيجة: عدد الموظفين. المتوقع: 40.
  4. اكتب بجانب الـ plan تعليق: أنهي جدول اتعمله SCAN وأنهي اتعمله SEARCH.
Expected output (press Run to produce your own):
id | parent | notused | detail                                      
---+--------+---------+---------------------------------------------
3  | 0      | 0       | SCAN e                                      
7  | 0      | 0       | SEARCH d USING INTEGER PRIMARY KEY (rowid=?)
(2 rows)
n 
--
40
(1 row)

Credits: the topic order follows the lecture list of the course TDDD12 Database Technology at Linköping University (https://www.ida.liu.se/~TDDD12/fo/), whose reading guide is based on the textbook Fundamentals of Database Systems by Elmasri and Navathe. We found no reuse licence on that page, so we link to it and copy nothing from it: the explanations, diagrams, data and code in this lecture are our own. Reference: Elmasri and Navathe, Fundamentals of Database Systems, the chapters on query processing and optimization.