CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721...
Transcript of CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721...
![Page 1: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/1.jpg)
Andy Pavlo // Carnegie Mellon University // Spring 2016
Lecture #10 – Query Execution & Scheduling
DATABASE SYSTEMS
15-721
![Page 2: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/2.jpg)
CMU 15-721 (Spring 2016)
TODAY ’S AGENDA
Process Models Query Parallelization Data Placement Scheduling 10 Crack Commandments
2
![Page 3: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/3.jpg)
CMU 15-721 (Spring 2016)
MULTI -USER DATABASE APP STACK
3
Server Client End Users
![Page 4: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/4.jpg)
CMU 15-721 (Spring 2016)
MULTI -USER DATABASE APP STACK
3
Server Client End Users
SQL PL/SQL
![Page 5: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/5.jpg)
CMU 15-721 (Spring 2016)
MULTI -USER DATABASE APP STACK
3
Server Client End Users
REST SOAP
SQL PL/SQL
![Page 6: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/6.jpg)
CMU 15-721 (Spring 2016)
MULTI -USER DATABASE APP STACK
3
Server Client End Users
REST SOAP
SQL PL/SQL
BACK-END APPLICATION
FRONT-END APPLICATION DBMS
![Page 7: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/7.jpg)
CMU 15-721 (Spring 2016)
QUERY EXECUTION
A query plan is comprised of operators.
An operator instance is an invocation of an operator on some segment of data.
A task is the execution of a sequence of one or more operator instances.
4
![Page 8: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/8.jpg)
CMU 15-721 (Spring 2016)
PROCESS MODEL
A DBMS’s process model defines how the system is architected to support concurrent requests from a multi-user application.
A worker is the DBMS component that is responsible for executing tasks on behalf of the client and returning the results.
5
ARCHITECTURE OF A DATABASE SYSTEM Foundations and Trends in Databases 2007
![Page 9: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/9.jpg)
CMU 15-721 (Spring 2016)
PROCESS MODELS
Approach #1: Process per DBMS Worker
Approach #2: Process Pool
Approach #3: Thread per DBMS Worker
6
![Page 10: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/10.jpg)
CMU 15-721 (Spring 2016)
PROCESS PER WORKER
Each worker is a separate OS process. → Relies on OS scheduler. → Use shared-memory for global data structures. → Examples: IBM DB2, Postgres, Oracle
7
Dispatcher Worker
![Page 11: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/11.jpg)
CMU 15-721 (Spring 2016)
PROCESS PER WORKER
Each worker is a separate OS process. → Relies on OS scheduler. → Use shared-memory for global data structures. → Examples: IBM DB2, Postgres, Oracle
7
Dispatcher Worker
![Page 12: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/12.jpg)
CMU 15-721 (Spring 2016)
PROCESS PER WORKER
Each worker is a separate OS process. → Relies on OS scheduler. → Use shared-memory for global data structures. → Examples: IBM DB2, Postgres, Oracle
7
Dispatcher Worker
![Page 13: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/13.jpg)
CMU 15-721 (Spring 2016)
PROCESS PER WORKER
Each worker is a separate OS process. → Relies on OS scheduler. → Use shared-memory for global data structures. → Examples: IBM DB2, Postgres, Oracle
7
Dispatcher Worker
![Page 14: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/14.jpg)
CMU 15-721 (Spring 2016)
PROCESS PER WORKER
Each worker is a separate OS process. → Relies on OS scheduler. → Use shared-memory for global data structures. → Examples: IBM DB2, Postgres, Oracle
7
Dispatcher Worker
![Page 15: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/15.jpg)
CMU 15-721 (Spring 2016)
PROCESS POOL
A worker uses any process that is free in a pool → Still relies on OS scheduler and shared memory. → Bad for CPU cache locality. → Examples: IBM DB2
8
Worker Pool Dispatcher
![Page 16: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/16.jpg)
CMU 15-721 (Spring 2016)
PROCESS POOL
A worker uses any process that is free in a pool → Still relies on OS scheduler and shared memory. → Bad for CPU cache locality. → Examples: IBM DB2
8
Worker Pool Dispatcher
![Page 17: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/17.jpg)
CMU 15-721 (Spring 2016)
THREAD PER WORKER
Single process with multiple worker threads. → DBMS has to manage its own scheduling. → May or may not use a dispatcher thread. → Examples: IBM DB2, MSSQL, MySQL, Oracle (Newer)
9
Worker Threads
![Page 18: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/18.jpg)
CMU 15-721 (Spring 2016)
PROCESS MODELS
Using a multi-threaded architecture has several advantages: → Less overhead per context switch. → Don’t have to manage shared memory.
The thread per worker model does not mean that you have intra-query parallelism.
I am not aware of any new DBMS built in the last 7-8 years that doesn’t use threads.
10
![Page 19: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/19.jpg)
CMU 15-721 (Spring 2016)
SCHEDULING
For each query plan, the DBMS has to decide where, when, and how to execute it. → How many tasks should it use? → How many CPU cores should it use? → What CPU core should the tasks execute on? → Where should a task store its output?
The DBMS always knows more than the OS.
11
![Page 20: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/20.jpg)
CMU 15-721 (Spring 2016)
INTER-QUERY PARALLELISM
Improve overall performance by allowing multiple queries to execute simultaneously. → Provide the illusion of isolation through concurrency
control scheme.
The difficulty of implementing a concurrency control scheme is not significantly affected by the DBMS’s process model.
12
![Page 21: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/21.jpg)
CMU 15-721 (Spring 2016)
INTRA-QUERY PARALLELISM
Improve the performance of a single query by executing its operators in parallel.
Approach #1: Intra-Operator (Horizontal) → Operators are decomposed into independent
instances that perform the same function on different subsets of data.
Approach #2: Inter-Operator (Vertical) → Operations are overlapped in order to pipeline data
from one stage to the next without materialization.
13
![Page 22: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/22.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ
![Page 23: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/23.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ
![Page 24: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/24.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3 A B
⨝ σ
π
σ
![Page 25: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/25.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3 1 2 3 A B
⨝ σ
π
σ
![Page 26: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/26.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3 1 2 3 A B
⨝ σ
π
σ
![Page 27: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/27.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3 1 2 3 A B
⨝ σ
π
σ σ σ σ
![Page 28: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/28.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
1 2 3 A B
⨝ σ
π
σ σ σ σ
![Page 29: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/29.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
1 2 3
Exchange
A B
⨝ σ
π
σ σ σ σ
![Page 30: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/30.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
1 2 3
Exchange
A B
⨝ σ
π
σ σ σ σ
![Page 31: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/31.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
B1 B2 1 2 3 4 5
Exchange
A B
⨝ σ
π
σ σ σ σ
![Page 32: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/32.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
B1 B2
Build HT Build HT
1 2 3 4 5
Exchange Exchange
σ σ
A B
⨝ σ
π
σ σ σ σ
![Page 33: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/33.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
B1 B2
Build HT Build HT
1 2 3 4 5
Exchange Exchange
σ σ
A B
⨝ σ
π
σ σ σ σ
![Page 34: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/34.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
B1 B2
Build HT Build HT
1 2 3 4 5
⨝ Exchange Exchange
σ σ
A B
⨝ σ
π
σ σ σ σ
![Page 35: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/35.jpg)
CMU 15-721 (Spring 2016)
INTRA-OPERATOR PARALLELISM
14
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A2 A1 A3
Build HT Build HT Build HT
B1 B2
Build HT Build HT
1 2 3 4 5
1 2 3 4
Probe HT Probe HT Probe HT Probe HT
⨝ Exchange Exchange
Exchange
σ σ
A B
⨝ σ
π
σ σ σ σ
![Page 36: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/36.jpg)
CMU 15-721 (Spring 2016)
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
INTER-OPERATOR PARALLELISM
15
A B
⨝ σ
π
σ
![Page 37: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/37.jpg)
CMU 15-721 (Spring 2016)
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
INTER-OPERATOR PARALLELISM
15
A B
⨝ σ
π
σ
![Page 38: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/38.jpg)
CMU 15-721 (Spring 2016)
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
INTER-OPERATOR PARALLELISM
15
1 ⨝ for r1 ∊ outer: for r2 ∊ inner: emit(r1⨝r2) A B
⨝ σ
π
σ
![Page 39: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/39.jpg)
CMU 15-721 (Spring 2016)
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
INTER-OPERATOR PARALLELISM
15
1 ⨝ for r1 ∊ outer: for r2 ∊ inner: emit(r1⨝r2)
2 π for r ∊ incoming: emit(πr)
A B
⨝ σ
π
σ
![Page 40: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/40.jpg)
CMU 15-721 (Spring 2016)
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
INTER-OPERATOR PARALLELISM
15
1 ⨝ for r1 ∊ outer: for r2 ∊ inner: emit(r1⨝r2)
2 π for r ∊ incoming: emit(πr)
A B
⨝ σ
π
σ
![Page 41: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/41.jpg)
CMU 15-721 (Spring 2016)
OBSERVATION
Coming up with the right number of workers to use for a query plan depends on the number of CPU cores, the size of the data, and functionality of the operators.
16
![Page 42: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/42.jpg)
CMU 15-721 (Spring 2016)
WORKER ALLOCATION
Approach #1: One Worker per Core → Each core is assigned one thread that is pinned to
that core in the OS. → See sched_setaffinity
Approach #2: Multiple Workers per Core → Use a pool of workers per core (or per socket). → Allows CPU cores to be fully utilized in case one
worker at a core blocks.
17
![Page 43: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/43.jpg)
CMU 15-721 (Spring 2016)
TASK ASSIGNMENT
Approach #1: Push → A centralized dispatcher assigns tasks to workers and
monitors their progress. → When the worker notifies the dispatcher that it is
finished, it is given a new task.
Approach #1: Pull → Workers pull the next task from a queue, process it,
and then return to get the next task.
18
![Page 44: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/44.jpg)
CMU 15-721 (Spring 2016)
OBSERVATION
Regardless of what worker allocation or task assignment policy the DBMS uses, it’s important that workers operate on local data.
The DBMS’s scheduler has to be aware of it’s underlying hardware’s memory layout. → Uniform vs. Non-Uniform Memory Access
19
![Page 45: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/45.jpg)
CMU 15-721 (Spring 2016)
UNIFORM MEMORY ACCESS
20
Bus
Cache Cache Cache Cache
![Page 46: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/46.jpg)
CMU 15-721 (Spring 2016)
NON-UNIFORM MEMORY ACCESS
21
Cach
e Ca
che Cache
Cache
![Page 47: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/47.jpg)
CMU 15-721 (Spring 2016)
DATA PLACEMENT
The DBMS can partition memory for a database and assign each partition to a CPU. By controlling and tracking the location of partitions, it can schedule operators to execute on workers at the closest CPU core.
See Linux’s move_pages
22
![Page 48: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/48.jpg)
CMU 15-721 (Spring 2016)
MEMORY ALLOCATION
What happens when the DBMS calls malloc? → Assume that the allocator doesn’t already have an
chunk of memory that it can give out.
23
![Page 49: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/49.jpg)
CMU 15-721 (Spring 2016)
MEMORY ALLOCATION
What happens when the DBMS calls malloc? → Assume that the allocator doesn’t already have an
chunk of memory that it can give out.
Actually, almost nothing:
23
![Page 50: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/50.jpg)
CMU 15-721 (Spring 2016)
MEMORY ALLOCATION
What happens when the DBMS calls malloc? → Assume that the allocator doesn’t already have an
chunk of memory that it can give out.
Actually, almost nothing: → The allocator will extend the process’ data segment. → But this new virtual memory is not immediately
backed by physical memory. → The OS only allocates physical memory when there is
a page fault.
23
![Page 51: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/51.jpg)
CMU 15-721 (Spring 2016)
MEMORY ALLOCATION LOCATION
Now after a page fault, where does the OS allocate physical memory in a NUMA system?
Approach #1: Interleaving → Distribute allocated memory uniformly across CPUs.
Approach #2: First-Touch → At the CPU of the thread that accessed the memory
location that caused the page fault.
24
![Page 52: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/52.jpg)
CMU 15-721 (Spring 2016)
DATA PLACEMENT
25
Source: Danica Porobic
0
4000
8000
12000
Spread Group Mix OS
Thro
ughp
ut (t
xn/s
ec)
Workload: TPC-C Payment using 4 Workers Processor: NUMA with 4 sockets (6 cores each)
? ? ? ?
![Page 53: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/53.jpg)
CMU 15-721 (Spring 2016)
DATA PLACEMENT
25
Source: Danica Porobic
0
4000
8000
12000
Spread Group Mix OS
Thro
ughp
ut (t
xn/s
ec)
Workload: TPC-C Payment using 4 Workers Processor: NUMA with 4 sockets (6 cores each)
? ? ? ?
![Page 54: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/54.jpg)
CMU 15-721 (Spring 2016)
PARTITIONING VS. PLACEMENT
A partitioning scheme is used to split the database based on some policy. → Round-robin → Attribute Ranges → Hashing → Partial/Full Replication
A placement scheme then tells the DBMS where to put those partitions. → Round-robin → Interleave across cores
26
![Page 55: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/55.jpg)
CMU 15-721 (Spring 2016)
OBSERVATION
We have the following so far: → Process Model → Worker Allocation Model → Task Assignment Model → Data Placement Policy → Solid appreciation for the CMU-DB fam.
But how do we decide how to create a set of tasks from a logical query plan? → This is relatively easy for OLTP queries. → Much harder for OLAP queries…
27
![Page 56: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/56.jpg)
CMU 15-721 (Spring 2016)
STATIC SCHEDULING
The DBMS decides how many threads to use to execute the query when it generates the plan.
It does not change while the query executes. → The easiest approach is to just use the same # of tasks
as the # of cores.
28
![Page 57: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/57.jpg)
CMU 15-721 (Spring 2016)
MORSEL-DRIVEN SCHEDULING
Dynamic scheduling of tasks that operate over horizontal partitions called “morsels” that are distributed across cores. → One worker per core → Pull-based task assignment → Round-robin data placement
Supports parallel, NUMA-aware operator implementations.
29
MORSEL-DRIVEN PARALLELISM: A NUMA-AWARE QUERY EVALUATION FRAMEWORK FOR THE MANY-CORE AGE SIGMOD 2014
![Page 58: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/58.jpg)
CMU 15-721 (Spring 2016)
HYPER: ARCHITECTURE
No separate dispatcher thread. The threads perform cooperative scheduling for each query plan. → Each worker has a queue of tasks that will execute on
morsels that are local to it. → It pulls the next task from a global work queue.
30
![Page 59: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/59.jpg)
CMU 15-721 (Spring 2016)
Data Table
HYPER: DATA PARTITIONING
31
id a1 a2 a3
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ
![Page 60: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/60.jpg)
CMU 15-721 (Spring 2016)
Data Table
HYPER: DATA PARTITIONING
31
id a1 a2 a3
A2
A1
A3
Morsels
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ
![Page 61: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/61.jpg)
CMU 15-721 (Spring 2016)
Data Table
HYPER: DATA PARTITIONING
31
1
2
3
id a1 a2 a3
A2
A1
A3
Morsels
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ
![Page 62: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/62.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 63: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/63.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 64: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/64.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 65: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/65.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 66: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/66.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 67: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/67.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 68: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/68.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 69: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/69.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 70: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/70.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 71: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/71.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 72: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/72.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 73: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/73.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 74: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/74.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 75: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/75.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 76: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/76.jpg)
CMU 15-721 (Spring 2016)
Task Queues
HYPER: EXECUTION EXAMPLE
32
SELECT A.id, B.value FROM A, B WHERE A.id = B.id AND A.value < 99 AND B.value > 100
A B
⨝ σ
π
σ 1
Morsels
Local Data
2
Morsels
Local Data
3
Morsels
Local Data
![Page 77: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/77.jpg)
CMU 15-721 (Spring 2016)
MORSEL-DRIVEN SCHEDULING
Because there is only one worker per core, they have to use work stealing because otherwise threads could sit idle waiting for stragglers.
Uses a lock-free hash table to maintain the global work queues. → We will discuss hash tables next class…
33
![Page 78: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/78.jpg)
CMU 15-721 (Spring 2016)
HANA NUMA-AWARE SCHEDULER
Pull-based scheduling with multiple worker threads that are organized into groups (pools). → Each CPU can have multiple groups. → Each group has a soft and hard priority queue.
Uses a separate “watchdog” thread to check whether groups are saturated and can reassign tasks dynamically.
34
SCALING UP CONCURRENT MAIN-MEMORY COLUMN-STORE SCANS: TOWARDS ADAPTIVE NUMA-AWARE DATA AND TASK PLACEMENT VLDB 2015
![Page 79: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/79.jpg)
CMU 15-721 (Spring 2016)
HANA THREAD GROUPS
Each thread group has a soft and hard priority task queues. → Threads are allowed to steal tasks from other groups’
soft queues.
Four different pools of thread per group: → Working: Actively executing a task. → Inactive: Blocked inside of the kernel due to a latch. → Free: Sleeps for a little, wake up to see whether there
is a new task to execute. → Parked: Like free but doesn’t wake up on its own.
35
![Page 80: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/80.jpg)
CMU 15-721 (Spring 2016)
HANA NUMA-AWARE SCHEDULER
Can dynamically adjust thread pinning based on whether a task is CPU or memory bound.
Found that work stealing was not as beneficial for systems with a larger number of sockets.
Using thread groups allows cores to execute other tasks instead of just only queries.
36
![Page 81: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/81.jpg)
CMU 15-721 (Spring 2016)
PARTING THOUGHTS
A DBMS is a beautiful, strong-willed independent piece of software. But it has to make sure that it uses its underlying hardware correctly. → Data location is an important aspect of this. → Tracking memory location in a single-node DBMS is
the same as tracking shards in a distributed DBMS
Don’t let the OS ruin your life.
37
![Page 82: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/82.jpg)
CMU 15-721 (Spring 2016)
10 CRACK COMMANDMENTS
In 1997, Christopher Wallace wrote a prophetic list of rules to follow if you are hustling product out on the streets. Almost 20 years later, these rules are still apt for both trapping and databases.
38
Wallace
10 CRACK COMMANDMENTS BAD BOY RECORDS 1997
![Page 83: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/83.jpg)
CMU 15-721 (Spring 2016)
10 CRACK COMMANDMENTS
39
6. Never lend anybody credit.
7. Never mix your family with your business affairs.
8. Never keep a large amount of product on yourself.
9. Never talk to the police.
10. Never take a consignment if you do not have the clientele.
1. Never let people know how much money you have.
2. Never let people know your next move.
3. Never trust anybody.
4. Never sample your own supply.
5. Never sling where you live.
![Page 84: CMU SCS 15-721 :: Query Execution & SchedulingFoundations and Trends in Databases 2007 CMU 15-721 (Spring 2016) PROCESS MODELS Approach #1: Process per DBMS Worker Approach #2: Process](https://reader033.fdocuments.net/reader033/viewer/2022050105/5f436856dc65995cb40a8f69/html5/thumbnails/84.jpg)
CMU 15-721 (Spring 2016)
NEXT CLASS
Parallel Hash Joins! Project #2 Checkpoint: Monday Feb 22
40