copyright © 2004 pearson education, inc.. chapter 15 algorithms for query processing and...

20
Copyright © 2004 Pearson Education, Inc.

Upload: joslyn-diffey

Post on 14-Dec-2015

216 views

Category:

Documents


1 download

TRANSCRIPT

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

Copyright © 2004 Pearson Education, Inc.

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

Copyright © 2004 Pearson Education, Inc.

Chapter 15

Algorithms for Query Processing and

Optimization

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

Slide 15-3Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.1Typical steps when processing a high-level query.

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

Slide 15-4Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.2Outline of the sort-merge algorithm for external sorting.

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

Slide 15-5Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.3Implementation 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 <project> A=BS.

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

Slide 15-6Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

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 <attribute list>(R).

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

Slide 15-7Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

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.

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

Slide 15-8Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

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.

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

Slide 15-9Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

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.

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

Slide 15-10Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.4Two query trees for the query Q2. (a) Query tree corresponding to the relational algebra expression for Q2.

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

Slide 15-11Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.4 (continued)Two query trees for the query Q2. (b) Initial (canonical) query tree for SQL query Q2.

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

Slide 15-12Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.4 (continued)Two query trees for the query Q2. (c) Query graph for Q2.

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

Slide 15-13Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.5Steps in converting a query tree during heuristic optimization. (a) Initial (canonical) query tree for SQL query Q.

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

Slide 15-14Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.5 (continued)Steps in converting a query tree during heuristic optimization. (b) Moving SELECT operations down the query tree.

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

Slide 15-15Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.5 (continued)Steps in converting a query tree during heuristic optimization. (c) Applying the more restrictive SELECT operation first.

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

Slide 15-16Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.5 (continued)Steps in converting a query tree during heuristic optimization. (d) Replacing CARTESIAN PRODUCT and SELECT with JOIN operations.

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

Slide 15-17Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.5 (continued)Steps in converting a query tree during heuristic optimization. (e) Moving PROJECT opeations down the query tree.

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

Slide 15-18Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.6A query tree for query Q1.

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

Slide 15-19Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.7Two left-deep (join) query trees.

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

Slide 15-20Elmasri and Navathe, Fundamentals of Database Systems, Fourth Edition

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.8Sample statistical information for relations in Q2. (a) Column information. (b) Table information. (c) Index information.