60 likes | 194 Vues
This document presents an optimization strategy for SQL queries involving employee and department tables. We analyze two queries targeting employee names and department floors, specifying conditions on salary and job title. The first query selects employees with a salary greater than 100K, while the second query narrows down results to "Sr. Programmers" with the same salary constraint. System catalog information highlights data distribution and indexing, facilitating an understanding of disk I/O costs and optimal query plans through algebraic tree transformations and dynamic programming methods.
E N D
Query Optimization Example Database Tables: Emp (name, age, sal, dno) Dept (dno, dname, floor, budget, mgr, ano) Acnt (ano,type, balance, bno) Bank (bno, bname,address) Query Q: select name, floor from emp, dept where emp.dno=dept.dno and sal>100K. Source: Query Optimization, Y. E. Ioannidis, ACM Computing Surveys, 28(1), March 1996. System Catalog Information: Table Emp: 20,000 pages, 100,000 tuples, clustering B+tree index on emp.sal (3-levels) selectivity( salary > 100K) = 10 percent Table Dept: 10 pages, 100 tuples, clustering Hash-file on dept.dno (1.2 pages/bucket) Memory Buffer: 3 pages Disk I/O cost: 20 ms/page
Q? Compare queries Q and Q’ on • Query Result • Efficiency of query plans Query Q: select name, floor from emp, dept where emp.dno=dept.dno And job = “Sr. Programmer” Semantic Query Optimization Integrity Constraint: assert sal-constraint on emp: sal>100K where job = “Sr. Programmer” Query Q’: select name, floor from emp, dept where emp.dno=dept.dno and job = “Sr. Programmer” and sal>100K. System Catalog Information: Table Emp: 20,000 pages, 100,000 tuples, clustering B+tree index on emp.sal (3-levels) selectivity( salary > 100K) = 10 percent Table Dept: 10 pages, 100 tuples, clustering Hash-file on dept.dno (1.2 pages/bucket) Memory Buffer: 3 pages Disk I/O cost: 20 ms/page