14-queryexecution2 (1)
14-queryexecution2 (1)
1 Background
Previous discussions of query executions assumed that the queries executed with a single worker (i.e
thread). However, in practice, queries are often executed in parallel with multiple workers.
Parallel execution provides a number of key benefits for DBMSs:
• Increased performance in throughput (more queries per second) and latency (less time per query).
• Increased responsiveness and availability from the perspective of external clients of the DBMS.
• Potentially lower total cost of ownership (TCO). This cost includes both the hardware procurement
and software license, as well as the labor overhead of deploying the DBMS and the energy needed
to run the machines. This has become of particular relevance in increasingly cloud-centric systems.
There are two types of parallelism that DBMSs support: inter-query parallelism and intra-query paral-
lelism.
3 Process Models
A DBMS process model defines how the system supports concurrent requests from a multi-user applica-
tion/environment. The DBMS is comprised of one or more workers that are responsible for executing tasks
on behalf of the client and returning the results. An application may send a large request or multiple
requests at the same time that must be divided across different workers.
Fall 2024 – Lecture #14 Query Execution II
There are two major process models that a DBMS may adopt: process per worker and thread per worker.
A third common database usage pattern takes an embedded approach.
Embedded DBMS
A very different usage pattern for databases involves running the system in the same address space of the
application, as opposed to a client-server model where the database stands independent of the application.
In this scenario, the application will set up the threads and tasks to run on the database system. The
application itself will largely be responsible for scheduling. A diagram of an embedded DBMS’s scheduling
behaviors is shown in Figure 3.
DuckDB, SQLite, and RocksDB are the most famous embedded DBMSs.
Scheduling
In conclusion, for each query plan, the DBMS has to decide where, when, and how to execute. Relevant
questions include:
• How many tasks should it use?
• How many CPU cores should it use?
• What CPU cores should the tasks execute on?
• Where should a task store its output?
When making decisions regarding query plans, the DBMS always knows more than the OS and should be
prioritized as such.
4 Inter-Query Parallelism
In inter-query parallelism, the DBMS executes different queries concurrently. Since multiple workers are
running requests simultaneously, overall performance is improved. This increases throughput and reduces
latency.
If the queries are read-only, then little coordination is required between queries. However, if multiple
queries are updating the database concurrently, more complicated conflicts arise. These issues are discussed
further in lecture 16.
Figure 4: Intra-Operator Parallelism – The query plan for this SELECT is a se-
quential scan on A that is fed into a filter operator. To run this in parallel, the query
plan is partitioned into disjoint fragments. A given plan fragment is operated on a
by a distinct worker. The exchange operator calls Next concurrently on all fragments
which then retrieve data from their respective pages.
5 Intra-Query parallelism
In intra-query parallelism, the DBMS executes the operations of a single query in parallel. This decreases
latency for long-running queries.
The organization of intra-query parallelism can be thought of in terms of a producer/consumer paradigm.
Each operator is a producer of data as well as a consumer of data from some operator running below it.
Parallel algorithms exist for every relational operator. The DBMS can either have multiple threads access
centralized data structures or use partitioning to divide work up.
Within intra-query parallelism, there are three types of parallelism: intra-operator, inter-operator, and
bushy. These approaches are not mutually exclusive. It is the DBMS’ responsibility to combine these
techniques in a way that optimizes performance on a given workload.
Figure 6: Bushy Parallelism – To perform a 4-way JOIN on three tables, the query
plan is divided into four fragments as shown. Different portions of the query plan
run at the same time, in a manner similar to inter-operator parallelism.
This approach is widely used in stream processing systems, which are systems that continually execute a
query over a stream of input tuples.
Bushy Parallelism
Bushy parallelism is a hybrid of intra-operator and inter-operator parallelism where workers execute mul-
tiple operators from different segments of the query plan at the same time.
The DBMS still uses exchange operators to combine intermediate results from these segments. An example
is shown in Figure 6.
6 I/O Parallelism
Using additional processes/threads to execute queries in parallel will not improve performance if the disk
is always the main bottleneck. Therefore, it is important to be able to split a database across multiple
storage devices.
To get around this, DBMSs use I/O parallelism to split installation across multiple devices. Two approaches
to I/O parallelism are multi-disk parallelism and database partitioning.
Multi-Disk Parallelism
In multi-disk parallelism, the OS/hardware is configured to store the DBMS’s files across multiple storage
devices. This can be done through storage appliances or RAID configuration based on performance, dura-
bility, and capacity constraints. All of the storage setup is transparent to the DBMS so workers cannot
operate on different devices because the DBMS is unaware of the underlying parallelism.
Database Partitioning
In database partitioning, the database is split up into disjoint subsets that can be assigned to discrete disks.
Some DBMSs allow for specification of the disk location of each individual database. This is easy to do at
the file-system level if the DBMS stores each database in a separate directory. The log file of changes made
is usually shared.
The idea of logical partitioning is to split single logical table into disjoint physical segments that are stored/-
managed separately. Such partitioning is ideally transparent to the application. That is, the application
should be able to access logical tables without caring how things are stored.
We will cover these approaches later in the semester when discussing distributed databases.