60 likes | 185 Vues
Query Optimization Example. Database Tables: Emp (name, age, sal , dno ) Dept ( dno , dname , floor, budget, mgr, ano ) Acnt ( ano,t ype , balance, bno ) Bank ( bno , bname,a ddress ). Query Q: select name, floor from emp , dept where emp.dno=dept.dno and sal >100K.
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