40 likes | 185 Views
Query Optimization Highlights. Chapter 16 (intro), 16.1 (skim), 16.2 (skim). Naïve Query Processing. SELECT LNAME FROM EMPLOYEE, DEPARTMENT WHERE DNO=DNUMBER AND SALARY>45000 AND DNAME="Software Support"; Naively, this is 1 Cartesian product, followed by 3 selects, followed by one project.
E N D
Query Optimization Highlights Chapter 16 (intro), 16.1 (skim), 16.2 (skim)
Naïve Query Processing SELECT LNAME FROM EMPLOYEE, DEPARTMENT WHERE DNO=DNUMBER AND SALARY>45000 AND DNAME="Software Support"; Naively, this is 1 Cartesian product, followed by 3 selects, followed by one project. Query tree is drawn from bottom up.
Optimization • The Query Processor might actually execute this as 2 selects, a join, a select and a project. • A smarter optimizer might do additional projects. • Seem intuitive? It's really intuitive only for the smallest queries. • Execution strategy is a plan for getting the result of a query. • Query optimization means finding the best execution strategy.
Helpful Ideas • Reduce table size before joins: • Push selects and projects as far down the tree as possible • Do joins and C.P.s as late as possible • Do operations in decreasing order of selectivity (if known) • DBMS might keep profile information • Combine single-table operations when possible • Use secondary indexes to advantage