cse 444: database internals - … › courses › cse444 › 19sp › ...cse 444: database internals...
TRANSCRIPT
![Page 1: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/1.jpg)
CSE 444: Database Internals
Lectures 20-21Parallel DBMSs
1CSE 444 - Spring 2019
![Page 2: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/2.jpg)
What We Have Already Learned
• Overall architecture of a DBMS• Internals of query execution:
– Data storage and indexing– Buffer management– Query evaluation including operator algorithms– Query optimization
• Internals of transaction processing:– Concurrency control: pessimistic and optimistic– Transaction recovery: undo, redo, and undo/redo
CSE 444 - Spring 2019 2
![Page 3: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/3.jpg)
Where We Are Headed Next
• Scaling the execution of a query– Parallel DBMS– MapReduce– Spark and Myria
• Scaling transactions– Distributed transactions– Replication
• Scaling with NoSQL and NewSQLCSE 444 - Spring 2019 3
![Page 4: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/4.jpg)
Reading Assignments
• Main textbook Chapter 20.1
• Database management systems. Ramakrishnan&Gehrke.Third Ed. Chapter 22.11
CSE 444 - Spring 2019 4
![Page 5: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/5.jpg)
DBMS Deployment: Local
CSE 444 - Spring 2019 5
Data files on disk
DBMS
Application
Desktop
Great for one application (could be more) and one user.
![Page 6: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/6.jpg)
CSE 444 - Spring 2019
DBMS Deployment: Client/Server
Data files
connection(ODBC, JDBC)
6Applications
DB Server
Great for many apps and many users
![Page 7: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/7.jpg)
CSE 444 - Spring 2019
DBMS Deployment: 3 Tiers
Data files7Browser
DB Server
Great for web-based applications
Web Server & App Server
Connection(e.g., JDBC)
HTTP/SSL
![Page 8: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/8.jpg)
CSE 444 - Spring 2019
DBMS Deployment: Cloud
8Browser
Great for web-based applications
Data files DB Server Web Server & App Server
Connection(e.g., JDBC)
HTTP/SSL
![Page 9: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/9.jpg)
How to Scale?
9Browser
DB Server
Connection(e.g., JDBC)
HTTP/SSL…
httpmultiplex
CSE 444 - Spring 2019Use many Web servers: Easy!
![Page 10: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/10.jpg)
How to Scale?
10Browser
Many DBMS instances: HARD
Connection(e.g., JDBC)
HTTP/SSL…
httpmultiplex
…
CSE 444 - Spring 2019Web Server Farm
![Page 11: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/11.jpg)
How to Scale?
• We can easily replicate the web servers and the application servers
• We cannot so easily replicate the database servers, because the database is unique
• We need to design ways to scale up the DBMS
CSE 444 - Spring 2019 11
![Page 12: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/12.jpg)
CSE 444 - Spring 2019
How to Scale a DBMS?
12
Scale up
Scale outA more
powerful server
More servers,one database
![Page 13: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/13.jpg)
What to scale?
• OLTP: Transactions per second– OLTP = Online Transaction Processing
• OLAP: Query response time– OLAP = Online Analytical Processing
CSE 444 - Spring 2019 13
![Page 14: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/14.jpg)
Scaling Transactions Per Second
• Amazon• Facebook• Twitter• … your favorite Internet application…
• Goal is to scale OLTP workloads
• We will get back to this next week
CSE 444 - Spring 2019 14
![Page 15: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/15.jpg)
Scaling Single QueryResponse Time
• Goal is to scale OLAP workloads
• That means the analysis of massive datasets
CSE 444 - Spring 2019 15
![Page 16: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/16.jpg)
This Week: Focus on Scaling a Single Query
CSE 444 - Spring 2019 16
![Page 17: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/17.jpg)
Big Data
• Buzzword?
• Definition from industry:– High Volume– High Variety– High Velocity
CSE 444 - Spring 2019 17
http://www.gartner.com/newsroom/id/1731916
![Page 18: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/18.jpg)
Big DataVolume is not an issue• Databases do parallelize easily; techniques available
from the 80’s– Data partitioning– Parallel query processing
• SQL is embarrassingly parallel
• We will learn how to do this
CSE 444 - Spring 2019 18
![Page 19: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/19.jpg)
Big Data
New workloads are an issue
• Big volumes, small analytics– OLAP queries: join + group-by + aggregate– Can be handled by today’s RDBMSs (e.g., Teradata)
• Big volumes, big analytics– More complex Machine Learning, e.g. click
prediction, topic modeling, SVM, k-means– Requires innovation – Active research area
CSE 444 - Spring 2019 19
![Page 20: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/20.jpg)
Data Analytics CompaniesFifteen years ago, explosion of db analytics companies
• Greenplum founded in 2003 acquired by EMC in 2010; A parallel shared-nothing DBMS (this lecture)
• Vertica founded in 2005 and acquired by HP in 2011; A parallel, column-store shared-nothing DBMS
• DATAllegro founded in 2003 acquired by Microsoft in 2008; A parallel, shared-nothing DBMS
• Aster Data Systems founded in 2005 acquired by Teradata in 2011; A parallel, shared-nothing, MapReduce-based data processing system (in two lectures). SQL on top of MapReduce
• Netezza founded in 2000 and acquired by IBM in 2010. A parallel, shared-nothing DBMS.
CSE 444 - Spring 2019 20
![Page 21: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/21.jpg)
CSE 444 - Spring 2019 21
![Page 22: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/22.jpg)
Two Fundamental Approaches to Parallel Data Processing
• Parallel databases, developed starting with the 80s (this lecture)– For both OLTP (transaction processing) – And for OLAP (decision support queries)
• MapReduce, first developed by Google, published in 2004 (in two lectures)– Only for decision support queries
CSE 444 - Spring 2019 22Today we see convergence of the two approaches
![Page 23: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/23.jpg)
Architectures for Parallel DMBSs
24
From: Greenplum Database Whitepaper
SAN = “Storage Area Network”CSE 444 - Spring 2019
![Page 24: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/24.jpg)
Our Focus: Shared-Nothing DBMS
CSE 444 - Spring 2019 25
![Page 25: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/25.jpg)
Parallel Query Evaluation
• Multiple DBMS instances (= processes) also called “nodes” execute on machines in a cluster– One instance plays role of the coordinator– Other instances play role of workers
• Applications interact with coordinator• Workers execute queries
– Typically all workers execute the same plan• Intra-operator parallelism & intra-query parallelism
– Some operations may execute at subsets of workers– Workers can execute multiple queries at the same time
• Inter-query parallelismCSE 444 - Spring 2019 26
![Page 26: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/26.jpg)
Parallel Query Execution
CSE 444 - Spring 2019 27
SCAN
SCAN
SHUFFLE ProducerDISK
DISK
SELECT
S
h
u
f
f
l
e
AGG
SHUFFLE Producer
SHUFFLE Consumer
SELECT
Worker 1
Worker 2
SHUFFLE Consumer AGG
![Page 27: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/27.jpg)
Parallel Query EvaluationNew operator: Shuffle • Origin: Exchange operator from Volcano system• Serves to re-shuffle data between processes
– Handles data routing, buffering, and flow control• Two parts: ShuffleProducer and ShuffleConsumer• Producer:
– Pulls data from child operator and sends to n consumers– Producer acts as driver for operators below it in query plan
• Consumer:– Buffers input data from n producers and makes it available
to operator through getNext() interface
28CSE 444 - Spring 2019
![Page 28: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/28.jpg)
Parallel DBMSs
• Performance metrics– Speedup: More nodes, same data -> higher speed– Scaleup: More nodes, more data -> same speed– Speed = query execution time
• Key challenges– Start-up costs– Interference– Skew
29CSE 444 - Spring 2019
![Page 29: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/29.jpg)
Parallel Query ProcessingHow do we compute these operations on a shared-nothing parallel db?
• Selection: σA=123(R)
• Group-by: γA,sum(B)(R)
• Join: R ⋈ S
Before we answer that: how do we store R (and S) on a shared-nothing parallel db?
30CSE 444 - Spring 2019
![Page 30: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/30.jpg)
Horizontal Data Partitioning
CSE 444 - Spring 2019 31
1 2 P . . .
Data: Servers:
K A B… …
![Page 31: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/31.jpg)
Horizontal Data Partitioning
CSE 444 - Spring 2019 32
K A B… …
1 2 P . . .
Data: Servers:
K A B
… …
K A B
… …
K A B
… …
![Page 32: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/32.jpg)
Horizontal Data Partitioning
CSE 444 - Spring 2019 33
K A B… …
1 2 P . . .
Data: Servers:
K A B
… …
K A B
… …
K A B
… …
Which tuplesgo to what server?
![Page 33: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/33.jpg)
Horizontal Data Partitioning
• Relation R split into P chunks R0, …, RP-1, stored at the P nodes
• Block partitioned– Each group of k tuples goes to a different node
• Hash based partitioning on attribute A:– Tuple t to chunk h(t.A) mod P
• Range based partitioning on attribute A:– Tuple t to chunk i if vi-1 < t.A < vi
• For hash and range partitioning: Beware of skew
34CSE 444 - Spring 2019
![Page 34: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/34.jpg)
Horizontal Data Partitioning
All three choices are just special cases:
• For each tuple, compute bin = f(t)
• Different properties of the function f determine hash vs. range vs. round robin vs. anything
35CSE 444 - Spring 2019
![Page 35: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/35.jpg)
36
Example: Teradata – Loading
AMP = “Access Module Processor” = unit of parallelismCSE 444 - Spring 2019
![Page 36: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/36.jpg)
Parallel Selection
Compute σA=v(R), or σv1<A<v2(R)
• On a conventional database: cost = B(R)
• Q: What is the cost on a parallel database with P processors ?– Block partitioned– Hash partitioned– Range partitioned
37CSE 444 - Spring 2019
![Page 37: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/37.jpg)
Parallel Selection
Compute σA=v(R), or σv1<A<v2(R)
• On a conventional database: cost = B(R)
• Q: What is the cost on a parallel database with P processors ? A: B(R) / P, but– Block partitioned -- all servers do the work– Hash partitioned -- some servers do the work– Range partitioned -- some servers do the work
38CSE 444 - Spring 2019
![Page 38: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/38.jpg)
Basic Parallel GroupBy
Data: R(K,A,B,C) -- hash-partitioned on KQuery: γA,sum(B)(R)
39
R1’ R2’ RP’. . .
R1 R2 RP
. . .
Reshuffle Ron attribute A
CSE 444 - Spring 2019
![Page 39: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/39.jpg)
Basic Parallel GroupBy
• Step 1: each server i partitions its chunk Ri using a hash function h(t.A) mod P: Ri,0, Ri,1, …, Ri,P-1
• Step 2: server j computes γA, sum(B) on R0,j, R1,j, …, RP-1,j
40CSE 444 - Spring 2019
![Page 40: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/40.jpg)
Speedup and Scaleup
• Consider:– Query: γA,sum(C)(R)– Runtime: dominated by reading chunks from disk
• If we double the number of nodes P, what is the new running time?
• If we double both P and the size of R, what is the new running time?
CSE 444 - Spring 2019 41
![Page 41: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/41.jpg)
Speedup and Scaleup
• Consider:– Query: γA,sum(C)(R)– Runtime: dominated by reading chunks from disk
• If we double the number of nodes P, what is the new running time?– Half (each server holds ½ as many chunks)
• If we double both P and the size of R, what is the new running time?– Same (each server holds the same # of chunks)
CSE 444 - Spring 2019 42
![Page 42: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/42.jpg)
Announcements
• Lab 4 due Friday
• Quiz 3+4 Monday 3/11
• HW 6 released – due 3/18
CSE 444 - Spring 2019 43
![Page 43: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/43.jpg)
Basic Parallel GroupBy
Can we do better?• Sum?• Count?• Avg?• Max?• Median?
44CSE 444 - Spring 2019
![Page 44: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/44.jpg)
Basic Parallel GroupBy
Can we do better?• Sum?• Count?• Avg?• Max?• Median?YES• Compute partial aggregates before shuffling
45CSE 444 - Spring 2019
Distributive Algebraic Holistic
sum(a1+a2+…+a9)=sum(sum(a1+a2+a3)+
sum(a4+a5+a6)+sum(a7+a8+a9))
avg(B) = sum(B)/count(B)
median(B)
![Page 45: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/45.jpg)
Basic Parallel GroupBy
Can we do better?• Sum?• Count?• Avg?• Max?• Median?YES• Compute partial aggregates before shuffling
46CSE 444 - Spring 2019
Distributive Algebraic Holistic
sum(a1+a2+…+a9)=sum(sum(a1+a2+a3)+
sum(a4+a5+a6)+sum(a7+a8+a9))
avg(B) = sum(B)/count(B)
median(B)
MapReduce implements this as “Combiners”
![Page 46: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/46.jpg)
Machine 1
1/3 of R
Machine 2
1/3 of R
Machine 3
1/3 of R
SELECT a, max(b) as topbFROM R WHERE a > 0GROUP BY a
Example Query with Group By
47CSE 444 - Spring 2019
![Page 47: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/47.jpg)
Machine 1
1/3 of R
Machine 2
1/3 of R
Machine 3
1/3 of R
σa>0
scan
g a, max(b)→b
hash on a
g a, max(b)→topb
σa>0
scan
g a, max(b)→b
hash on a
g a, max(b)→topb
σa>0
scan
g a, max(b)→b
hash on a
g a, max(b)→topb
48CSE 444 - Spring 2019
![Page 48: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/48.jpg)
Parallel Join: R ⋈A=B S
• Data: R(K1,A, C), S(K2, B, D)• Query: R(K1,A,C) ⋈ S(K2,B,D)
49CSE 444 - Spring 2019
![Page 49: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/49.jpg)
Parallel Join: R ⋈A=B S
• Data: R(K1,A, C), S(K2, B, D)• Query: R(K1,A,C) ⋈ S(K2,B,D)
50
R’1, S’1 R’2, S’2 R’P, S’P . . .
R1, S1 R2, S2 RP, SP . . .
Reshuffle R on R.Aand S on S.B
Each server computesthe join locally
CSE 444 - Spring 2019
Initially, both R and S are horizontally partitioned on K1 and K2
![Page 50: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/50.jpg)
Parallel Join: R ⋈A=B S
• Step 1– Every server holding any chunk of R partitions its
chunk using a hash function h(t.A) mod P– Every server holding any chunk of S partitions its
chunk using a hash function h(t.B) mod P
• Step 2: – Each server computes the join of its local fragment
of R with its local fragment of S
51CSE 444 - Spring 2019
![Page 51: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/51.jpg)
Data: R(K1,A, B), S(K2, B, C)Query: R(K1,A,B) ⋈ S(K2,B,C)
52
K1 B1 202 50
K2 B101 50102 50
K1 B3 204 20
K2 B201 20202 50
R1 S1 R2 S2
K1 B1 203 204 20
K2 B201 20
K1 B2 50
K2 B101 50102 50202 50
R1’ S1’ R2’ S2’
M1 M2
M1 M2Shuffle
⋈ ⋈
Partition
Local Join
Join on R.B = S.B
CSE 444 - Spring 2019
![Page 52: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/52.jpg)
Optimization for Small Relations
When joining R and S• If |R| >> |S|
– Leave R where it is– Replicate entire S relation across nodes
• Also called a small join or a broadcast join
CSE 444 - Spring 2019 53
![Page 53: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/53.jpg)
Other Interesting ParallelJoin Implementation
Skew:• Some partitions get more input tuples than others
Reasons:– Range-partition instead of hash– Some values are very popular:
• Heavy hitters values; e.g. ‘Justin Bieber’
– Selection before join with different selectivities
• Some partitions generate more output tuples than others
CSE 444 - Spring 2019 54
![Page 54: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/54.jpg)
Some Skew Handling TechniquesIf using range partition:
• Ensure each range gets same number of tuples
• E.g.: {1, 1, 1, 2, 3, 4, 5, 6 } à [1,2] and [3,6]
• Eq-depth v.s. eq-width histograms
CSE 444 - Spring 2019 55
![Page 55: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/55.jpg)
Some Skew Handling TechniquesCreate more partitions than nodes
• And be smart about scheduling the partitions
• Note: MapReduce uses this technique
CSE 444 - Spring 2019 56
![Page 56: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/56.jpg)
Some Skew Handling TechniquesUse subset-replicate (a.k.a. “skewedJoin”)• Given R ⋈A=B S• Given a heavy hitter value R.A = ‘v’
(i.e. ‘v’ occurs very many times in R)• Partition R tuples with value ‘v’ across all nodes
e.g. block-partition, or hash on other attributes• Replicate S tuples with value ‘v’ to all nodes• R = the build relation• S = the probe relation
CSE 444 - Spring 2019 57
![Page 57: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/57.jpg)
58
Example: Teradata – Query Execution
SELECT *
FROM Order o, Line iWHERE o.item = i.item
AND o.date = today()
join
select
scan scan
date = today()
o.item = i.item
Order oItem i
Find all orders from today, along with the items ordered
CSE 444 - Spring 2019
Order(oid, item, date), Line(item, …)
![Page 58: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/58.jpg)
Query Execution
CSE 444 - Spring 2019 59
AMP 1 AMP 2 AMP 3
selectdate=today()
selectdate=today()
selectdate=today()
scanOrder o
scanOrder o
scanOrder o
hashh(o.item)
hashh(o.item)
hashh(o.item)
AMP 1 AMP 2 AMP 3
join
select
scan
date = today()
o.item = i.item
Order o
Order(oid, item, date), Line(item, …)
![Page 59: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/59.jpg)
Query Execution
CSE 444 - Spring 2019 60
AMP 1 AMP 2 AMP 3
scanItem i
AMP 1 AMP 2 AMP 3
hashh(i.item)
scanItem i
hashh(i.item)
scanItem i
hashh(i.item)
join
scandate = today()
o.item = i.item
Order oItem i
Order(oid, item, date), Line(item, …)
![Page 60: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/60.jpg)
Query Execution
CSE 444 - Spring 2019 61
AMP 1 AMP 2 AMP 3
join join joino.item = i.item o.item = i.item o.item = i.item
contains all orders and all lines where hash(item) = 1
contains all orders and all lines where hash(item) = 2
contains all orders and all lines where hash(item) = 3
Order(oid, item, date), Line(item, …)
![Page 61: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/61.jpg)
Machine 1
1/3 of R, S, T
Machine 2
1/3 of R, S, T
Machine 3
1/3 of R, S, T
SELECT * FROM R, S, T WHERE R.b = S.c AND S.d = T.e AND (R.a - T.f) > 100
Example 2
CSE 444 - Spring 2019 62
![Page 62: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/62.jpg)
σR.a – T.f >100
scan R
Machine 1
1/3 of R, S, T
Machine 2
1/3 of R, S, T
Machine 3
1/3 of R, S, T
scan S scan T
h(R.b) h(S.c) h(T.e)
R ⨝ S
h(S.d)
RS ⨝ T
σR.a – T.f >100
scan R scan S scan T
h(R.b) h(S.c) h(T.e)
R ⨝ S
h(S.d)
RS ⨝ T
σR.a – T.f >100
scan R scan S scan T
h(R.b) h(S.c) h(T.e)
R ⨝ S
h(S.d)
RS ⨝ T
Shuffling intermediate result from R ⨝ S
Shuffling R, S, and T
63CSE 444 - Spring 2019
![Page 63: CSE 444: Database Internals - … › courses › cse444 › 19sp › ...CSE 444: Database Internals Lectures 20-21 Parallel DBMSs CSE 444 -Spring 2019 1 What We Have Already Learned](https://reader033.vdocuments.net/reader033/viewer/2022053013/5f1037e57e708231d4480681/html5/thumbnails/63.jpg)
Machine 1
1/3 of R, S, T
Machine 2
1/3 of R, S, T
Machine 3
1/3 of R, S, T
Broadcasting S and T
σR.a – T.f >100
scan R
scan S scan T
broadcast broadcast
R ⨝ S
RS ⨝ T
σR.a – T.f >100
scan R
scan S scan T
broadcast broadcast
R ⨝ S
RS ⨝ T
σR.a – T.f >100
scan R
scan S scan T
broadcast broadcast
R ⨝ S
RS ⨝ T
64CSE 444 - Spring 2019