One and Two Pass Query Algorithms




CS157b

Chris Pollett

Mar 4, 2024

Outline

Introduction

Two Phase Multiway Merge-Sort (TPMMS)

N-Way Merge sort

Phase I Example

Phase II

Phase II -cont'd (finish sorting in secondary storage aside)

How much more efficient is this last idea than just merging two sorted lists at time?

Iterators for Implementing Physical Operators

One Pass Algorithms -- Tuple at a Time Operations

One-Pass Algorithms for Unary, Full-Relation Operations

Quiz

Which of the following is true?

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

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

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.