Student: - 100K tuples - 10K leaves in a B+(RegNo) tree with 3 levels Exam: - 1M tuples - 10K leaves in a B+(ERegNo,ECCode) tree with 3 levels Course: - 1K tuples - 100 leaves in a B+(CCode) tree with 2 levels The query is: SELECT * FROM Student JOIN Exam ON RegNo = ERegNo JOIN Course on ECCode = CCode ==== Scenario A: Nested loop on Student × Exam, Student external The nested loop on Result × Course, Result external Read all student, for each student get the corresponding exams. The tree is on (ERegNo, ECCode), and we have only the RegNo so we can't use it. We have to read the entire table. We will have 1M tuples at the end (each student has about 10 exams), for each of this tuples get the course through the tree. (10K + 100K * 10K) + (1M * 2) ≈ 1G If we want the worst case, exams will be in two consecutive leaves so we pay 4 instead of 3 to access the exams, getting 2.41M in the end. The reasoning is the same in all the next exercises. ==== Scenario B: Nested loop on Student × Exam, Exam external The nested loop on Result × Course, Result external Here we can use the tree on Student. Note that reading all the leaves is feasible, but worse in terms of cost. (10K + 1M * 3) + (1M * 2) = 3.01M + 2M = 5.01M ==== Scenario C: Nested loop on Course × Exam, Course external The nested loop on Result × Student, Result external We cannot use the tree on Exam here. We will have 1M tuples after the first join and we can use the tree on Student. (100 + 1K * 10K) + (1M * 3) ≈ 13M ==== Scenario C: Nested loop on Course × Exam, Exam external The nested loop on Result × Student, Result external We can use the tree on Course. (10K + 1M * 2) + (1M * 3) = 5.01M