One and Two Pass Query Algorithms




CS157b

Chris Pollett

Mar 6, 2023

Outline

Introduction

One Pass Algorithms -- Tuple at a Time Operations

One-Pass Algorithms for Unary, Full-Relation Operations

One Pass Algorithms for Binary Operations

Recall `M =` number of memory blocks; `B(T)` = number of blocks in table `T`.

More One Pass Algorithms for Binary Operations

Quiz

Which of the following statements is true?

  1. Grid files support looking up nearest neighbors better than partitioned hash files.
  2. Quad-trees out of the box support multi-dimensional indexing on three attributes.
  3. The `T(R)` cost parameter represents the number of blocks needed to store relation R.

Nested Loop Joins

More Nested Loop Join

Two Pass Algorithms Based On Sorting

Duplicate Elimination using Sorting

Given `R` we sort `R` and output distinct values.

Sort Based Duplicate Elimination

Grouping and Aggregation using Sorting

Sorting and Unions, Intersections, etc.

Sort-based Join

Partitioning Relations by Hashing

Hashed based Duplicate Elimination

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