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

Post on 14-Dec-2015

216 views 1 download

Tags:

Transcript of Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and...

Copyright © 2004 Pearson Education, Inc.

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.

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.

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.

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).

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

Copyright © 2004 Pearson Education, Inc.

FIGURE 15.6A query tree for query Q1.

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

Copyright © 2004 Pearson Education, Inc.

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

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.