# Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.

## Presentation on theme: "Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization."— Presentation transcript:

Chapter 15 Algorithms for Query Processing and Optimization

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-3 FIGURE 15.1 Typical steps when processing a high- level query.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-4 FIGURE 15.2 Outline of the sort-merge algorithm for external sorting.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-5 FIGURE 15.3 Implementation JOIN, PROJECT, UNION, INTERSECTION, and SET DIFFERENCE by using sort- merge, where R has n tuples and S has m tuples. (a) Implementing the operation T  R A=B S.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-6 FIGURE 15.3 (continued) Implementation JOIN, PROJECT, UNION, INTERSECTION, and SET DIFFERENCE by using sort- merge, where R has n tuples and S has m tuples. (b) Implementing the operation T   (R).

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-7 FIGURE 15.3 (continued) Implementation JOIN, PROJECT, UNION, INTERSECTION, and SET DIFFERENCE by using sort- merge, where R has n tuples and S has m tuples. (c) Implementing the operation T  R  S.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-8 FIGURE 15.3 (continued) Implementation JOIN, PROJECT, UNION, INTERSECTION, and SET DIFFERENCE by using sort- merge, where R has n tuples and S has m tuples. (d) Implementing the operation T  R  S.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-9 FIGURE 15.3 (continued) Implementation JOIN, PROJECT, UNION, INTERSECTION, and SET DIFFERENCE by using sort- merge, where R has n tuples and S has m tuples. (e) Implementing the operation T  R – S.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-10 FIGURE 15.4 Two query trees for the query Q2. (a) Query tree corresponding to the relational algebra expression for Q2.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-11 FIGURE 15.4 (continued) Two query trees for the query Q2. (b) Initial (canonical) query tree for SQL query Q2.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-12 FIGURE 15.4 (continued) Two query trees for the query Q2. (c) Query graph for Q2.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-13 FIGURE 15.5 Steps in converting a query tree during heuristic optimization. (a) Initial (canonical) query tree for SQL query Q.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-14 FIGURE 15.5 (continued) Steps in converting a query tree during heuristic optimization. (b) Moving SELECT operations down the query tree.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-15 FIGURE 15.5 (continued) Steps in converting a query tree during heuristic optimization. (c) Applying the more restrictive SELECT operation first.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-16 FIGURE 15.5 (continued) Steps in converting a query tree during heuristic optimization. (d) Replacing CARTESIAN PRODUCT and SELECT with JOIN operations.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-17 FIGURE 15.5 (continued) Steps in converting a query tree during heuristic optimization. (e) Moving PROJECT opeations down the query tree.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-18 FIGURE 15.6 A query tree for query Q1.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-19 FIGURE 15.7 Two left-deep (join) query trees.

Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition Copyright © 2004 Pearson Education, Inc. Slide 15-20 FIGURE 15.8 Sample statistical information for relations in Q2. (a) Column information. (b) Table information. (c) Index information.

Similar presentations