Skip to content
Official PYQ · 2006

GATE CS 2006 Q69 — Tuple Calculus and SQL

Explain with AI

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 6000,7000,8000,90006000, 7000, 8000, 9000 and 1000010000 were each paid by 20%20\% 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 4ms,4ms, disk data transfer bandwidth is 300300 MB/s and checking a tuple to see if amount is greater than xx takes 10µs.10µs. Which of the following statements is correct?

Choose one option
View worked solution

Answer: C

The two query plans represented in the diagram are:

  • Plan 1 (Selection before Join): πcourse(enrolled⋈σamount>x(paid))\pi_{\text{course}} \left( \text{enrolled} \bowtie \sigma_{\text{amount} > x}(\text{paid}) \right)
  • Plan 2 (Join before Selection): πcourse(σamount>x(enrolled⋈paid))\pi_{\text{course}} \left( \sigma_{\text{amount} > x}(\text{enrolled} \bowtie \text{paid}) \right)

Let NpaidN_{\text{paid}} be the number of tuples in the paid relation, and NenrolledN_{\text{enrolled}} be the number of tuples in the enrolled relation. Since a student can enroll in multiple courses, we have Nenrolled≥NpaidN_{\text{enrolled}} \ge N_{\text{paid}}.

For x=5000x = 5000, all payments (6000,7000,8000,9000,100006000, 7000, 8000, 9000, 10000) satisfy the condition amount>5000\text{amount} > 5000, meaning 100%100\% of the students are selected.

  • Plan 1 performs the selection on the paid relation first, requiring NpaidN_{\text{paid}} comparisons. It then joins the filtered tuples with enrolled.
  • Plan 2 joins the relations first, producing an intermediate relation of size NenrolledN_{\text{enrolled}}, and then performs NenrolledN_{\text{enrolled}} comparisons.

Since Nenrolled≥NpaidN_{\text{enrolled}} \ge N_{\text{paid}}, Plan 1 requires fewer CPU comparisons (10 μs10\,\mu\text{s} per check) and avoids processing a larger intermediate relation. Thus, Plan 1 executes faster than Plan 2 for all databases when x=5000x = 5000.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions