46
Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution Query Optimization (3 lectures) CSE 414 - Autumn 2018 1

Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Introduction to Data Management

CSE 414

Unit 4: RDBMS Internals

Logical and Physical Plans

Query Execution

Query Optimization

(3 lectures)

CSE 414 - Autumn 2018 1

Page 2: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Introduction to Data ManagementCSE 414

Lecture 15: Introduction to Query Evaluation

CSE 414 - Autumn 2018 2

Page 3: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Announcements

• WQ5 (datalog) due tomorrow

• HW4 (datalog) due tomorrow

• Midterm review session this evening– 5:30pm, CSE 2nd Floor Breakout

CSE 414 - Autumn 2018 3

Page 4: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Class Overview

• Unit 1: Intro• Unit 2: Relational Data Models and Query Languages• Unit 3: Non-relational data• Unit 4: RDMBS internals and query optimization• Unit 5: Parallel query processing• Unit 6: DBMS usability, conceptual design• Unit 7: Transactions• Unit 8: Advanced topics (time permitting)

4CSE 414 - Autumn 2018

Page 5: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

From Logical RA Plans to Physical Plans

CSE 414 - Autumn 2018 5

Page 6: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Query Evaluation Steps Review

6

Parse & Rewrite Query

Select Logical Plan

Select Physical Plan

Query Execution

Disk

SQL query

Queryoptimization

Logicalplan (RA)

Physicalplan

Page 7: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Logical vs Physical Plans• Logical plans:

– Created by the parser from the input SQL text– Expressed as a relational algebra tree– Each SQL query has many possible logical plans

• Physical plans:– Goal is to choose an efficient implementation for

each operator in the RA tree– Each logical plan has many possible physical plans

CSE 414 - Autumn 2018 7

Page 8: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Review: Relational Algebra

CSE 414 - Autumn 2018 8

Supplier Supply

sid = sid

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

Relational algebra expression is also called the “logical query plan”

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

SELECT snameFROM Supplier x, Supply yWHERE x.sid = y.sid

and y.pno = 2and x.scity = ‘Seattle’and x.sstate = ‘WA’

Page 9: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Logical Plan v.s. Physical Plan

• Logical Plan = a Relational Algebra tree

• Physical Plan = a Logical Plan plus annotation of each operator with an algorithm

CSE 414 - Autumn 2018 9

Page 10: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Query Optimization and Execution

• Query optimizer:– Choose a good logical plan– Refine it to a good physical plan– Sometimes these steps are intertwined

• Query execution– Execute the physical plan

CSE 414 - Autumn 2018 10

Page 11: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Query Execution

CSE 414 - Autumn 2018 11

Page 12: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Physical Operators

Relational algebra operators:• Selection, projection, join, union, difference• Group-by, distinct, sort

Physical operators:• For each operators above, several possible

algorithms• Main memory algorithms, or disk-based

algorithmsCSE 414 - Autumn 2018 12

Page 13: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Main Memory Algorithms

Logical operator:Supplier ⨝sid=sid SupplyPropose three physical operators for the join, assuming the tables are in main memory:1.2.3.

CSE 414 - Autumn 2018 13

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Page 14: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Main Memory Algorithms

Logical operator:Supplier ⨝sid=sid SupplyPropose three physical operators for the join, assuming the tables are in main memory:1. Nested Loop Join O(??)2. Merge join O(??)3. Hash join O(??)

CSE 414 - Autumn 2018 14

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Page 15: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Main Memory Algorithms

Logical operator:

Supplier ⨝sid=sid Supply

Propose three physical operators for the join, assuming the

tables are in main memory:

1. Nested Loop Join O(n2)

2. Merge join O(n log n)

3. Hash join O(n) … O(n2)

CSE 414 - Autumn 2018 15

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Page 16: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

BRIEF Review of Hash Tables

0123456789

Separate chaining:

h(x) = x mod 10

A (naïve) hash function:

503 103

76 666

48

503

Duplicates OKWHY ??

Operations:

find(103) = ??insert(488) = ??

CSE 414 - Autumn 2018 16

Page 17: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

BRIEF Review of Hash Tables

• insert(k, v) = inserts a key k with value v

• Many values for one key– Hence, duplicate k’s are OK

• find(k) = returns the list of all values vassociated to the key k

CSE 414 - Autumn 2018 17

Page 18: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Query Execution

• Join R ⨝ S: e.g. using hash-join:

– Nested-loop: forall x in R forall y in S do …

– Hash–join: build a hash table on S, probe R

• Selection: σ(R): e.g. “on-the-fly”

• But what about a larger plan?

– Each operator implements

the Iterator Interface

CSE 414 - Autumn 2018 18

⨝ ⨝

R

S T K

W

σ

σ

Page 19: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Implementing Query Operators with the Iterator Interface

Each operator implements three methods:

• open()

• next()

• close()

CSE 414 - Autumn 2018 19

⨝ ⨝

R

S T K

W

σ

σ

Page 20: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)Tuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Iterator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;while (!found) {

Tuple in = child.next();if (in == EOF) return EOF;found = p(in);

}return in;

} void close () { child.close(); }

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 20

Page 21: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)Tuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Iterator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;while (!found) {

Tuple in = child.next();if (in == EOF) return EOF;found = p(in);

}return in;

} void close () { child.close(); }

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 21

Page 22: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

}

class Select implements Operator {...void open (Predicate p,

Iterator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;while (!found) {

Tuple in = child.next();if (in == EOF) return EOF;found = p(in);

}return in;

} void close () { child.close(); }

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 22

Page 23: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Iterator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;while (!found) {

Tuple in = child.next();if (in == EOF) return EOF;found = p(in);

}return in;

} void close () { child.close(); }

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 23

Page 24: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Operator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;while (!found) {

Tuple in = child.next();if (in == EOF) return EOF;found = p(in);

}

return in;} void close () { child.close(); }

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 24

Page 25: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Operator child) {this.p = p; this.child = child;

} Tuple next () {

}

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 25

Page 26: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Operator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;Tuple r = null;while (!found) {

r = child.next();if (r == null) break;found = p(in);

}

}

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 26

Page 27: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Operator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;Tuple r = null;while (!found) {

r = child.next();if (r == null) break;found = p(in);

}return r;

}

}

Example “on the fly” selection operator

Implementing Query Operators with the Iterator Interface

CSE 414 - Autumn 2018 27

Page 28: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Implementing Query Operators with the Iterator Interface

interface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

class Select implements Operator {...void open (Predicate p,

Operator child) {this.p = p; this.child = child;

} Tuple next () {boolean found = false;Tuple r = null;while (!found) {

r = child.next();if (r == null) break;found = p(in);

}return r;

} void close () { child.close(); }

}

Example “on the fly” selection operator

28

Page 29: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Implementing Query Operators with the Iterator Interface

29

Operator q = parse(“SELECT ...”);q = optimize(q);

q.open();while (true) { Tuple t = q.next();if (t == null) break;else printOnScreen(t);

}q.close();

Query plan executioninterface Operator {

// initializes operator state // and sets parametersvoid open (...);

// calls next() on its inputs// processes an input tuple // produces output tuple(s)// returns null when doneTuple next ();

// cleans up (if any)void close ();

}

CSE 414 - Autumn 2018

Page 30: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 30

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 31: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 31

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)open()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 32: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 32

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)open()

open()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 33: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 33

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)open()

open()

open()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 34: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 34

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)open()

open()

open()

open()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 35: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 35

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)open()

open()

open()

open() open()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 36: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 36

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 37: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 37

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 38: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 38

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

next()

next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 39: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 39

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

next()

next()

next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 40: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 40

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

next()

next()

next() next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 41: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 41

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Nested loop)

(On the fly)

(On the fly)next()

next()

next()

next()next()

next()

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss: open/next/closefor nested loop join

Page 42: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 42

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Hash Join)

(On the fly)

(On the fly)

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss hash-joinin class

Page 43: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 43

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Hash Join)

(On the fly)

(On the fly)

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss hash-joinin class

Tuples fromhere arepipelined

Page 44: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipelining

CSE 414 - Autumn 2018 44

Suppliers Supplies

sno = sno

σscity=�Seattle� and sstate=�WA’ and pno=2

πsname

(File scan) (File scan)

(Hash Join)

(On the fly)

(On the fly)

Supplier(sid, sname, scity, sstate)Supply(sid, pno, quantity)

Discuss hash-join

in class

Tuples fromhere are

pipelined

Tuples fromhere are

“blocked”

Page 45: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Pipeline v.s. Blocking

• Pipeline– A tuple moves all the way through up the query plan– Advantages: speed– Disadvantage: need all hash at the same time in

memory• Blocking

– The entire result of the subplan is computed (and stored to disk) before the first tuple is sent up the plan

– Advantage: saves memory– Disadvantage: slower

47CSE 414 - Autumn 2018

Page 46: Introduction to Data Management CSE 414 · 2018-10-29 · Introduction to Data Management CSE 414 Unit 4: RDBMS Internals Logical and Physical Plans Query Execution ... Intro •Unit

Discussion on Physical Plan

More components of a physical plan:• Access path selection for each relation

– Scan the relation or use an index (next lecture)• Implementation choice for each operator

– Nested loop join, hash join, etc.• Scheduling decisions for operators

– Pipelined execution or intermediate materialization

CSE 414 - Autumn 2018 48