Consider the relation enrolled (student, course) in which (student, course) is the primary key, and the relation paid (student, amount) where student is the primary key. Assume no null values and no foreign keys or integrity constraints. Assume that amounts and were each paid by of the students. Consider these query plans (Plan 1 on left, Plan 2 on right) to “list all courses taken by students who have paid more than x”

A disk seek takes disk data transfer bandwidth is MB/s and checking a tuple to see if amount is greater than takes Which of the following statements is correct?
View worked solution
Answer: C
The two query plans represented in the diagram are:
- Plan 1 (Selection before Join):
- Plan 2 (Join before Selection):
Let be the number of tuples in the paid relation, and be the number of tuples in the enrolled relation. Since a student can enroll in multiple courses, we have .
For , all payments () satisfy the condition , meaning of the students are selected.
- Plan 1 performs the selection on the
paidrelation first, requiring comparisons. It then joins the filtered tuples withenrolled. - Plan 2 joins the relations first, producing an intermediate relation of size , and then performs comparisons.
Since , Plan 1 requires fewer CPU comparisons ( per check) and avoids processing a larger intermediate relation. Thus, Plan 1 executes faster than Plan 2 for all databases when .
Free practice · Your answers on this page are not saved.
