題意:oop
查詢處理和優化優化
解析:code
第一題: 考慮兩張關係表Parts和Supply,分別有60000和150000條記錄,每頁存儲50條記錄,兩者均沒有索引。對於下列查詢語句,以磁盤I/O次數(頁面數量)做爲成本計算的方法,計算下列4種鏈接方式的成本,分別爲Page-oriented Nested Loops Join、Block-oriented Nested Loops Join、Sort-Merge Join、Hash Join,寫出成本計算公式: SELECT FROM Parts INNER JOIN Supply ON Parts.PartID = Supply.PID; 第二題: 考慮下面的關係模式: Employee (EmpID, firstname, lastname, department, salary) 員工信息表包含1200個頁面,每頁存儲120條記錄。對於下列查詢語句,分析和估計不一樣索引方式下查詢的成本,clustered B+ tree index on (department, salary)、unclustered B+ tree index on (salary)、 unclustered Hash index on (department)、unclustered Hash index on (salary) SELECT FROM Employee WHERE salary > 300,000 AND department = ‘Marketing’; 第三題: 考慮下面三種關係模式: Employee (eid: integer, salary: integer, name: char(30)) Project (projid: integer, code: char(20), start: date, end: date, eid: integer) Department (did: integer, projid: integer, budget: real, floor: integer) 對於下列查詢語句,分別計算下列4種查詢方案的成本,假設Project.projid和employee.salary都有B+樹索引。 SELECT e.name, d.projid FROM Employee e, Project p, Department d WHERE e.eid = p.eid AND p.projid = d.projid AND e.salary < 300,000 AND p.code = ‘alpha 340’;排序
涉及知識點:索引
嵌套循環鏈接、哈希鏈接、排序合併鏈接get