Index-based Query Algorithms - Parsing and Optimization




CS157b

Chris Pollett

Mar 8, 2023

Outline

Introduction

Index-based Join

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

In-Class Exercise

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

What to select for each plan we generate

  1. An order and grouping on the associative and commutative operations like join, unions, and intersections.
  2. An algorithm for each operator in the logical plan. For example, we need to choose between nested-loop join and hash-join.
  3. Additional operators - scanning, sorting, etc which are needed for the physical plan but are not present in the logical plan.
  4. The way in which arguments are passed from one operator to the next. (By intermediate results or by pipelining).

Estimating Sizes of Intermediate Relations

Estimating the Size of a Projection