Database Chapter 9 Homework - Relational Query Processing and Query Optimization

The title of this chapter, I want to use one word to describe - "absolutely". . .
First review the heuristic optimization rules for query trees

(1) The selection operation should be done first as much as possible
(2) The projection operation and the selection operation should be performed at the same time
(3) The projection is combined with the binocular operation before or after it, and there is no need to scan the relationship once to remove some fields
( 4) Combining some selection with the Cartesian product to be performed before it becomes a join operation.
(5) Find common subexpressions.

The homework for this chapter is questions 2, 3, 4, and 5.
2 questions

Suppose the relationship R (A, B) and S (B, C, D) is as follows: R has 20,000 tuples, S has 1,200 tuples, and a block can hold 40 R tuples and 30 S A tuple of , estimate how many disk block reads and writes are required for the following operations.
(1) There is no index on R, select * from R;
(2) A in R is the main key, and A has a 3-layer B+ tree index, select * from R where A = 10;
(3) Nested loop connection R⋈S;
(4) Sorting and merging connection R⋈S, distinguishing between R and S has two cases of order and disorder on the B attribute.

3 questions

For the student-course database, query the names of all the courses that the information department students have taken

select Cname
from Student,Course,SC
where Student.Sno=SC.Sno and SC.Cno=Course.Cno and Student.Sdept='IS';

Try to draw a syntax tree represented by relational algebra, optimize the original syntax tree with relational algebra expression optimization algorithm, and draw the optimized standard syntax tree.

4 questions

For the following database schema
Teacher(Tno, Tname, Tage,Tsex); Department(Dno, Dname, Tno); Work(Tno, Dno, Year, Salary), assuming that there are B+ tree indexes on the Tno attribute of Teacher, the Dno attribute of Department and the Year attribute of Work, it illustrates a better processing method for the following query statement.
(1) select * from teacher where Tsex = '女'
(2) select * from department where Dno < 301
(3) select * from work where Year <> 2000
(4) select * from work where year > 2000 and salary < 5000
(5)select * from work where year < 2000 and salary < 5000

5 questions

For the database schema in question 4, there are the following queries

select Tname
from teacher,department,work
where teacher.tno = work.tno and department.dno = work.dno
and department.dname = '计算机系' and salary > 5000

Draw the syntax tree and the syntax tree represented by relational algebra, optimize the relational algebra syntax tree, and draw the optimized syntax tree.

Answer

insert image description here

insert image description here

insert image description here

Guess you like

Origin blog.csdn.net/weixin_45845039/article/details/116673051