Finish Two Pass Query Algorithms - Query Parsing and Optimization




CS157b

Chris Pollett

Mar 5, 2018

Outline

Introduction

Hash-Based Algorithm for Grouping and Aggregation

Two Pass Group By Hash Example

Two Pass Group By Hash Example

Hash based and Unions, Intersections, etc

Hash-Join

Index-based Selection

Index-based Join

Quiz

Which of the following statements is true?

  1. The I/O model cost for a table scan was Cost(Table-Scan(R)) = T(R)
  2. Duplicate elimination can always be done in one pass.
  3. One reason what the time for sort-based duplicate elimination was `3 \cdot B(R)` was we assumed we didn't need to write the results back to disk.

Parsing Queries

Syntax Analysis and Parse Trees

A Grammar for a Simple Subset of SQL

Example

SELECT name
FROM MovieStar
WHERE birthdate LIKE '%1960'

Might yield parse tree:

Example Parse Tree

The Preprocessor

Algebraic Laws For Improving Query Plans

Commutative and Associative Laws

Laws Involving Selection

Pushing Selections

Laws Involving Projection

Laws for Joins and Products

From Parse Trees to Logical Query Plans