csep 544: lecture 09 - courses.cs.washington.edu · csep 544: lecture 09 advanced query processing...

58
CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation 1 CSEP544 - Fall 2015

Upload: others

Post on 31-May-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

CSEP 544: Lecture 09

Advanced Query Processing Parallel Query Evaluation

1 CSEP544 - Fall 2015

Page 2: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Outline

•  Optimal Sequential Algorithms

•  Semijoin Reduction

•  Optimal Parallel Algorithms

2

Page 3: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Semijoin: Review of Basics

R ⋉C S = Π A1,…,An (R ⨝C S)

Formally, R ⋉C S means this: retain from R only those tuples that have some matching tuple in S Duplicates in R are preserved Duplicates in S don’t matter

Where A1, …, An are the attributes in R

Page 4: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Application

Q(x,y,z,u,v,w) = R(x,y),S(y,z),T(z,u),K(u,v),L(v,w)

Intermediate relations of size up to m5… ... But final answer can be as small as 0 (or 1...)

Page 5: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Application

Q(x,y,z,u,v,w) = R(x,y),S(y,z),T(z,u),K(u,v),L(v,w)

Intermediate relations of size up to m5… ... But final answer can be as small as 0 (or 1...)

Solution: semi-join reduction

/* Forwards: */ S := S ⋉ R T := T ⋉ S K := K ⋉ T L := L ⋉ K /* then backwards: */ K := K ⋉ L T := T ⋉ K S := S ⋉ T R := R ⋉ S

Page 6: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Application

Q(x,y,z,u,v,w) = R(x,y),S(y,z),T(z,u),K(u,v),L(v,w)

Intermediate relations of size up to m5… ... But final answer can be as small as 0 (or 1...)

Solution: semi-join reduction

/* Forwards: */ S := S ⋉ R T := T ⋉ S K := K ⋉ T L := L ⋉ K /* then backwards: */ K := K ⋉ L T := T ⋉ K S := S ⋉ T R := R ⋉ S

Next, compute the query in time O(|Input| + |Output|)

Page 7: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Acyclic Queries

•  A query is acyclic if its relations can be placed in a tree such that the set of nodes that contain any variable form a connected set

•  Yannakakis’ algorithm (from the 80’s): any acyclic query can be computed in time: O(|Input| + |Output|)

7

Page 8: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

O(n + |Output|)

8

Acyclic query: Q(x,y,z,u,v,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Cyclic query: Q(x,y,z) = R(x,y),S(y,z),T(z,x)

R(x,y)

S(y,z)

T(z,x)

Incorrect for x

Page 9: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Yannakakis’ Algorithm

•  Step 1: semi-join reduction – Two sweeps: up and down

•  Step 2: use the tree as query query plan, compute bottom up

•  Note: this works also for queries with projections and/or aggregates (in class…)

9

Page 10: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

Acyclic query: Q(x,y,z,u,v,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Semi- join down…

Page 11: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

Acyclic query: Q(x,y,z,u,v,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Semi- join down…

…semi- join up

Page 12: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

O(n + |Output|)

Acyclic query: Q(x,y,z,u,v,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Semi- join down…

…semi- join up

Query plan

⋈ R(x,y) ⋈

S(y,z,u)

T(y,z,w) ⋈

K(z,v) L(v,m)

Page 13: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

O(n + |Output|)

Acyclic query: Q(x,y,z,u,v,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Semi- join down…

…semi- join up

Query plan

⋈ R(x,y) ⋈

S(y,z,u)

T(y,z,w) ⋈

K(z,v) L(v,m)

Question: change the query plan to return only variables x,w,m Q(x,w,m) = R(x,y),S(y,z,u),T(y,zw),K(z,v),L(v,m)

Page 14: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Cyclic Queries: 1.  Acyclic queries: computable in time

O( |input| + |output| ) [Yannakakis’81]

2.  Arbitrary queries: computable in time O( |input|fractional-tree-width + |output| )

The fractional tree-width: •  Tree nodes may contain multiple relations •  FTW is the largest AGM bound of any node

14

Page 15: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

R(x,y)

S(y,z,u)

T(y,z,w)

K(z,v)

L(v,m)

O(n + |Output|)

R(x,y), A(y,s),B(x,s)

S(y,z,u)

T(y,z,w), C(z,t),D(t,p),E(p,y)

K(z,v),F(v,q)

L(v,m)

ρ*=3/2

ρ*=2

ρ*=1

ρ*=2

ρ*=1

O(|Input|2 + |Output|)

ftw = max(ρ*) = 2

In class: how do we compute this query

Optimal edge cover = ρ* AGM bound = mρ* Generic-join algorithm, time = O(mρ*)

Acyclic query Cyclic query

Page 16: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Outline

•  Optimal Sequential Algorithms

•  Semijoin Reduction

•  Optimal Parallel Algorithms

16

Page 17: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Parallel Models

•  Shared-Nothing: p servers •  MapReduce: p reducers

•  Notice: in MR we can choose p, but, as we shall see, it’s better if p is the number of physical servers

17

Page 18: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Overview Computes a full conjunctive query in one round, by partial replication. •  Replication appears in [Ganguli’92] •  Shares Algorithm: [Afrati&Ullman’10]

– For MapReduce •  HyperCube Algorithm [Beame’13,’14]

– Same as in Shares – But different optimization/analysis

18

Page 19: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

The Triangle Query •  Input: three tables

R(X, Y), S(Y, Z), T(Z, X) |R| = |S| = |T| = m tuples

•  Output: compute all triangles Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

Z X

Fred Alice

Jack Jim

Fred Jim

Carol Alice

Y Z

Fred Alice

Jack Jim

Fred Jim

Carol Alice

X Y

Fred Alice

Jack Jim

Fred Jim

Carol Alice

R

S

T

19

Page 20: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Triangles in One Round

•  Place servers in a cube p = p1/3 × p1/3 × p1/3

•  Each server identified by (i,j,k)

i

j k

(i,j,k)

p1/3

Server (i,j,k)

20

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x) |R| = |S| = |T| = m tuples

Page 21: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Triangles in One Round

k

(i,j,k)

Z X

Fred Alice

Jack Jim

Fred Jim

Carol Alice

Jack Jim Y Z

Fred Alice

Jack Jim

Fred Jim

Carol Alice

Jim Jack Jim Jack

X Y

Fred Alice

Jack Jim

Fred Jim

Carol Alice

R

S

T

i = h2(Fred)

j = h1(Jim)

Fred Jim Fred Jim

Fred Jim Fred Jim

Jim Jack

Jim Jack

Fred Jim Jim Jack

Jim Jack Fred Jim

Fred Jim

Jack Jim Jack Jim

Round 1: Send R(x,y) to all servers (h1(x),h2(y),*) Send S(y,z) to all servers (*, h2(y), h3(z)) Send T(z,x) to all servers (h1(x), *, h3(z))

Output: compute locally R(x,y) ⋈ S(y,z) ⋈ T(z,x)

21 p1/3

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x) |R| = |S| = |T| = m tuples

Page 22: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Input (size=m)

Input data = size m

Number of servers = p

O(m/p) O(m/p)

Extends BSP [Valiant]

Page 23: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

Round 1

Input data = size m

One round = Compute & communicate

Number of servers = p

O(m/p) O(m/p)

Extends BSP [Valiant]

≤L ≤L

Page 24: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p

O(m/p) O(m/p)

Extends BSP [Valiant]

≤L

≤L

≤L

≤L

≤L

≤L

Page 25: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Page 26: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Cost: Ideal Practical ε∈(0,1) Naïve 1 Naïve 2 Load L L = m/p L = m/p1-ε L = m L = m/p Rounds r 1 O(1) 1 p

Page 27: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Cost: Ideal Practical ε∈(0,1) Naïve 1 Naïve 2 Load L L = m/p L = m/p1-ε L = m L = m/p Rounds r 1 O(1) 1 p

Page 28: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Cost: Ideal Practical ε∈(0,1) Naïve 1 Naïve 2 Load L L = m/p L = m/p1-ε L = m L = m/p Rounds r 1 O(1) 1 p

Page 29: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Cost: Ideal Practical ε∈(0,1) Naïve 1 Naïve 2 Load L L = m/p L = m/p1-ε L = m L = m/p Rounds r 1 O(1) 1 p

Page 30: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Massively Parallel Communication Model (MPC)

Server 1 Server p . . . .

Server 1 Server p . . . .

Server 1 Server p . . . .

Input (size=m)

. . . .

Round 1

Round 2

Round 3 . . . .

Input data = size m

Max communication load / round / server = L

Algorithm = Several rounds

One round = Compute & communicate

Number of servers = p ≤L

≤L

≤L

≤L

≤L

≤L

O(m/p) O(m/p)

Extends BSP [Valiant]

Cost: Ideal Practical ε∈(0,1) Naïve 1 Naïve 2 Load L L = m/p L = m/p1-ε L = m L = m/p Rounds r 1 O(1) 1 p

Page 31: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Data Complexity of the Load

•  Query Q is fixed blue

•  Input: data m, servers p red

•  Load: L = f(m, p)

•  We discuss one round only

31

Page 32: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Speedup

32

# processors (=p)

Speed A load of L = m/p corresponds to linear speedup

A load of L = m/p1-ε corresponds to sub-linear speedup

Page 33: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example: Join(x,y,z) = R(x,y), S(y,z)

Server 1 Server p . . . .

R(x,y) ⋈ S(y,z) R(x,y) ⋈ S(y,z)

Output: each server •  local join R(x,y) ⋈ S(y,z)

Server 1 Server p . . . .

Round 1: each server •  Sends record R(x,y) to server h(y) mod p •  Sends record S(y,z) to server h(y) mod p

Input: R, S •  Uniformly partitioned

|R|=|S|=m

L = O(m/p) w.h.p.

Assuming no skew

33

x y a b

a c

b c

y z b d

b e

c e ⋈

R S

O(m/p) O(m/p)

Page 34: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example: Triangles

34

Theorem If data has “no skew”, then HyperCube computes Triangles with load/server L = O(m/p2/3) w.h.p.

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x) |R| = |S| = |T| = m tuples

Round 1: Send R(x,y) to all servers (h1(x),h2(y),*) Send S(y,z) to all servers (*, h2(y), h3(z)) Send T(z,x) to all servers (h1(x), *, h3(z))

Output: compute locally R(x,y) ⋈ S(y,z) ⋈ T(z,x)

Server 1 Server p . . . .

R(x,y)⋈S(y,z)⋈T(z,x) R(x,y)⋈S(y,z)⋈T(z,x)

Server 1 Server p . . . .

|R|=|S|=m

O(m/p) O(m/p)

O(m/p2/3) O(m/p2/3)

Page 35: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

56BHJ 56BTJ B5BHJ B5BTJ HCBHJ HCBTJ0

2

4

6

8

10

12

14

16

Tim

H (

sHc)

10.9

12.8

4.55.4

2.4

0.9

56BHJ 56B7J B5BHJ B5B7J HCBHJ HCB7J0

50

100

150

200

250

7im

H (

sHc)

75

98116

229

3718

56BHJ 56BTJ B5BHJ B5BTJ HCBHJ HCBTJ0

20

40

60

80

100

120

140

160

Tu

SlH

s sh

uff

lHd

(m

illi

Rn

)

54 54

142 142

13 13

1.1M triples of Twitter data à 220k triangles; p=64

35

2 rounds hash-join

1 round broadcast 1 round

hypercube

local 1 or 2-step hash-join; local 1-step Leapfrog Trie-join (a.k.a. Generic-Join)

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x) |R| = |S| = |T| = 1.1M

Wall clock time Total CPU time Number of tuples shuffled

Page 36: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

1.1M triples of Twitter data à 220k triangles; p=64 Trianges(x,y,z) = R(x,y), S(y,z), T(z,x) |R| = |S| = |T| = 1.1M

Page 37: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

HperCube Algorithm for Full CQ

•  Write: p = p1 * p2 * … * pk

•  Round 1: send Sj(xj1, xj2, …) to all servers whose coordinates agree with hj1(xj1), hj2(xj2), …

•  Output: compute Q locally

Q(x1, . . . ,xk) = S1(x̄1),S2(x̄2), . . . ,S`(x̄`)

pi = a “share”

independent hash functions

Page 38: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Computing Shares p1, p2, …, pk

Q(x1, . . . ,xk) = S1(x̄1),S2(x̄2), . . . ,S`(x̄`)

Minimize maxj Lj

[Beame’13] linear opt:

Load/server from Sj : Lj = mj / (pj1 * pj2 * … )

Optimization problem: find p1 * p2 * … * pk = p

38

Page 39: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Vertex Cover / Edge Packing

Hyper-graph: nodes x1, …, xk, edges S1, …, Sl

Def. A fractional vertex cover: k numbers v1, v2, … vk ≥ 0 such that for every hyperedge Sj: Σi vi ≥ 1

Σi vi ≥ Σj uj minv1,… vk Σi vi = maxu1,… ul Σj uj = τ*

Def. A fractional edge packing: l numbers u1, u2, … ul ≥ 0 such that for every node xi: Σj uj ≤ 1

Page 40: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Optimal L

Q(x1, . . . ,xk) = S1(x̄1),S2(x̄2), . . . ,S`(x̄`)Suppose m1 = … = ml = m

Optimal load: L = m / p1/τ* Optimal speedup: 1/p1/τ*

Thm. For every v1, … vk, there exists an algorithm for Q with L ≤ m / p1/τ w.h.p. on skew-fee instances, where τ = Σi vi

Proof: use shares pi = p vi / τ

Fractional vertex packing:

Thm. For every u1, … ul, any algorithm for Q has L ≥ m / p1/τ even on skew-fee instances, where τ = Σj uj

Proof: uses Friedgut’s inequality

Fractional edge cover:

Page 41: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

max(wR + wS + wT) x: wR + wT ≤ 1 y: wR + wS ≤ 1 z: wS + wT ≤ 1

min(vR + vS + vT) R: vx + vy ≥ 1 S: vy + vS ≥ 1 T: vx + vz ≥ 1 ≥

Q(x,y,z) = R(x,y), S(y,z), T(z,x)

Suppose mR = mS = mT = m

Fractional vertex packing: Fractional edge cover:

Optimal load: L = m / p2/3 Optimal speedup: 1/p2/3

Page 42: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Lessons So Far •  MPC model: cost = communication load + rounds

•  HyperCube: rounds=1, L = m/p1/τ* Sub-linear speedup Note: it only shuffles data! Still need to compute Q locally.

•  Strong optimality guarantee: any algorithm with better load m/ps reports only 1/ps×τ*-1 fraction of answers. Parallelism gets harder as p increases!

•  Total communication = p×L = m × p1-1/τ* MapReduce model is wrong! It encourages many reducers p

42

Page 43: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Skew Matters

•  If the database is skewed, the query becomes provably harder. We want to optimize for the common case (skew-free) and treat skew separately

•  Parallel processing different from sequential processing, were worst-case optimal algorithms (LFTJ, generic-join) are for arbitrary instances, skewed or not.

43

Page 44: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Skew Matters •  Join(x,y,z) = R(x,y),S(y,z)

L = m/p

•  Suppose R, S are skewed, e.g. single value y

•  The query becomes a cartesian product! Product(x,z) = R(x),S(z) L = m/p1/2

44

τ* = 1 0 0 1

τ* = 2 1 1

Lets examine skew…

Page 45: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

All You Need to Know About Skew Hash-partition a bag of m data values to p bins Fact 1 Expected size of any one fixed bin is m/p Fact 2 Say that database is skewed if some value has degree > m/p. Then some bin has load > m/p Fact 3 Conversely, if the database is skew-free then max size of all bins = O(m/p) w.h.p. Join: if ∀degree < m/p then L = O(m/p) w.h.p Triangles: if ∀degree < m/p1/3 then L = O(m/p2/3 ) w.h.p In general: if ∀degree < m/pvi/τ* then L = O(m/p1/τ*) w.h.p

Hiding log p factors

Page 46: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

AGM Bound + Optimal Alg.

(Generalized) fractional edge cover:

min(wR log|R| + wS log|S| + wT log|T|) x: wR + wT ≥ 1 y: wR + wS ≥ 1 z: wS + wT ≥ 1

Hypergraph = variables + relations

Thm. For any feasible wR, wS, wT: log|Q| ≤ objective |Q| ≤ |R|wR × |S|wS × |T|wT

(Generalized) fractional vertex packing:

max(vR + vS + vT) R: vx + vy ≤ log|R| S: vy + vS ≤ log|S| T: vx + vz ≤ log|T|

Thm. For any feasible vR,vS,vT log|Q| ≥ objective |Q| ≥ mvx × mvy × mvz

Proof “Free” instance R(x,y) = [mvx] × [mvy] S(y,z) = [mvy] × [mvz] T(z,x) = [mvx] × [mvz]

Proof. (use Friedgut’s inequality) Optimal edge cover = ρ* AGM bound = mρ* Generic-join algorithm, time = O(mρ*)

Q(x,y,z) = R(x,y), S(y,z), T(z,x)

Log base m

Page 47: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

The AGM Inequality

47

Q(x1, . . . ,xk) = S1(x̄1),S2(x̄2), . . . ,S`(x̄`)

m1 = … = ml = m

Fact. Any MPC algorithm satisfies r×L ≥ m / p1/ρ* where r = # rounds, L = load/server

Informal proof: •  AGM lower bound: there exists db s.t. |Q| = mρ*

•  Each server receives subset |Si| ≤ r×L •  AGM upper bound: server reports ≤ (r×L)ρ* answers •  All p servers report ≤ p×(r×L)ρ* answers, = mρ*

Page 48: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Lessons so Far •  Skew affects communication dramatically

– E.g. Join from linear m/p to m/p1/2

•  Analysis differs: – w/o skew: L = m / p1/τ* fractional vertex cover – w/ skew: L ≥ m / p1/ρ* fractional edge cover

•  Focus on skew-free databases.

Handle skewed values as a residual query.

48

Tight

Not tight

Page 49: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Statistics •  So far: all relations have same size m •  In reality, we know their sizes = m1, m2, …

Q1: What is the optimal choice of shares? Q2: What is the optimal load L?

Will answer Q2, giving closed formula for L. Will answer Q1 indirectly, by showing that HyperCube takes advantage of statistics.

49

Page 50: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

L for Cross Product

S1(x) à

S2(

y) à

2-way product Q(x,y) = S1(x) × S2(y) |S1|=m1, |S2| = m2

Shares p = p1 × p2 L = max(m1 / p1 , m2 / p2) Minimal L:

L =

✓m1 ·m2

p

◆ 12

t-way product: Q(x1,…,xu) = S1(x1)× …×St(xt):

L =

✓m1 ·m2 · · ·mt

p

◆ 1t

Page 51: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

L for arbitrary Query Q Q(x1, . . . ,xk) = S1(x̄1),S2(x̄2), . . . ,S`(x̄`)

Relations sizes= m1, m2, … Then, for any 1-round algorithm

Fact For any integral edge packing Sj1, Sj2, …, Sjt:

L ≥

✓mj1 ·mj2 · · ·mjt

p

◆ 1t

Theorem: [Beame’14] (1) For any fractional edge packing u1, …, ul

L ≥ (2) The optimal load of the HyperCube algorithm is maxu L(u)

L(u) =

✓m1

u1 ·m2u2 · · ·m`

u`

p

◆ 1u1+u2+···+u`

51

t = size of packing

Page 52: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

Edge packing u1, u2, u3

1/2, 1/2, 1/2 (m1 m2 m3)1/3 / p2/3

1, 0, 0 m1 / p 0, 1, 0 m2 / p 0, 0, 1 m3 / p

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

✓m1

u1 ·m2u2 ·m3

u3

p

◆ 1u1+u2+u3

0 0

1 ½ ½

½

Page 53: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

Edge packing u1, u2, u3

1/2, 1/2, 1/2 (m1 m2 m3)1/3 / p2/3

1, 0, 0 m1 / p 0, 1, 0 m2 / p 0, 0, 1 m3 / p

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

✓m1

u1 ·m2u2 ·m3

u3

p

◆ 1u1+u2+u3

0 0

1 ½ ½

½

Page 54: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

Edge packing u1, u2, u3

1/2, 1/2, 1/2 (m1 m2 m3)1/3 / p2/3

1, 0, 0 m1 / p 0, 1, 0 m2 / p 0, 0, 1 m3 / p

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

✓m1

u1 ·m2u2 ·m3

u3

p

◆ 1u1+u2+u3

0 0

1 ½ ½

½

Page 55: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

Edge packing u1, u2, u3

1/2, 1/2, 1/2 (m1 m2 m3)1/3 / p2/3

1, 0, 0 m1 / p 0, 1, 0 m2 / p 0, 0, 1 m3 / p

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

L = the largest of these four values.

✓m1

u1 ·m2u2 ·m3

u3

p

◆ 1u1+u2+u3

0 0

1 ½ ½

½

Page 56: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Example

Edge packing u1, u2, u3

1/2, 1/2, 1/2 (m1 m2 m3)1/3 / p2/3

1, 0, 0 m1 / p 0, 1, 0 m2 / p 0, 0, 1 m3 / p

Trianges(x,y,z) = R(x,y), S(y,z), T(z,x)

L = the largest of these four values.

✓m1

u1 ·m2u2 ·m3

u3

p

◆ 1u1+u2+u3

0 0

1 ½ ½

½

Assuming m1 > m2 , m3 •  When p is small, then L = m1 / p. •  When p is large, then L = (m1 m2 m3)1/3 / p2/3

Page 57: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Discussion

Fact 3 . If mj < mk/p , then uj = 0. Intuitively: broadcast the small relations Sj

Fact 1 L = [geometric-mean of m1,m2,..] / p1/Σuj

Speedup

Fact 2 As p increases, speedup degrades. 1/p1/Σuj à 1/p1/τ*

L =max

u

✓m1

u1 ·m2u2 · · ·m`

u`

p

◆ 1u1+u2+···+u`

57

Page 58: CSEP 544: Lecture 09 - courses.cs.washington.edu · CSEP 544: Lecture 09 Advanced Query Processing Parallel Query Evaluation CSEP544 - Fall 2015 1 . Outline • Optimal Sequential

Summary

•  Traditional query plans are sub-optimal for complex, cyclic queries

•  Real data/applications: keys or UDF’s make traditional plans suboptimal even for acyclic queries

•  Novel algorithm are now emerging, especially for large-scale data analytics

58