Interquery Parallelism
In interquery parallelism different queries or transactions run at the same time on different processors. It increases the throughput (transactions per second) of a transaction processing system and is the easiest form to support, especially on shared-memory systems. It does not make a single query faster. On shared-disk and shared-nothing systems, concurrent transactions need cache coherency protocols, so that each processor sees the latest page contents.
Intraquery Parallelism
Intraquery parallelism executes one query using several processors, which reduces its response time. It has two forms:
- Intra-operation parallelism: one operation (sort, join, scan, aggregate) is split among processors, because relations are large and operations work on many tuples.
- Inter-operation parallelism: different operations of the same query tree run at the same time. In pipelined parallelism an operation passes its output tuples to the next one as soon as they are produced; in independent parallelism operations that do not depend on each other run on separate processors.
Parallel Sort and Join
- Range-partitioning sort: the relation is range-partitioned on the sort key, each node sorts its partition locally and the sorted partitions are concatenated.
- Parallel external merge sort: each node sorts its own data and the sorted runs are merged.
- Partitioned parallel join: both relations are partitioned with the same hash function on the join attribute, so that matching tuples land on the same node, and each node joins its partition locally (partitioned hash join). A small relation can instead be replicated to every node (fragment-and-replicate).
- Parallel aggregation: each node computes partial results, which are combined.
Limits (Amdahl's Law)
If a fraction s of a job is serial and cannot be parallelised, the speedup on n processors is 1 / (s + (1 - s) / n), and can never exceed 1 / s.
Definition: Intraquery parallelism. Executing a single query in parallel on several processors, either by splitting one operation or by running different operations together, to reduce the response time of that query.
Table 3.2: Forms of parallelism
| Form | What runs in parallel | Goal |
|---|---|---|
| Interquery | Different queries | Higher throughput |
| Intra-operation | Parts of one operation | Lower response time |
| Inter-operation | Different operations of a query | Lower response time |
Example 3.2: Amdahl's law
Problem: A query has 10 percent serial work. What speedup is obtained on 2, 4, 8 and 16 processors, and what is the upper limit?
Solution:
- Speedup = 1 / (s + (1 - s) / n) with s = 0.1.
- n = 2: 1 / (0.1 + 0.45) = 1.82. n = 4: 1 / (0.1 + 0.225) = 3.08.
- n = 8: 1 / (0.1 + 0.1125) = 4.71. n = 16: 1 / (0.1 + 0.05625) = 6.40.
- The limit as n grows is 1 / 0.1 = 10.
Result: The speedups are 1.82, 3.08, 4.71 and 6.40, and can never exceed 10.
s = 0.1
for n in (2, 4, 8, 16):
print(n, "processors: speedup", round(1 / (s + (1 - s) / n), 2))
print("Upper limit:", 1 / s)
data = [42, 7, 19, 3, 88, 25, 61, 14, 50, 9, 73, 31]
parts = [[x for x in data if x < 30],
[x for x in data if 30 <= x < 60],
[x for x in data if x >= 60]]
local = [sorted(p) for p in parts]
print("Sorted partitions:", local)
print("Concatenated :", sum(local, []))
Output
2 processors: speedup 1.82
4 processors: speedup 3.08
8 processors: speedup 4.71
16 processors: speedup 6.4
Upper limit: 10.0
Sorted partitions: [[3, 7, 9, 14, 19, 25], [31, 42, 50], [61, 73, 88]]
Concatenated : [3, 7, 9, 14, 19, 25, 31, 42, 50, 61, 73, 88]
Common mistakes
- Believing that interquery parallelism makes one query faster.
- Partitioning the two relations of a join with different hash functions.
- Ignoring the serial part of a query when estimating speedup.
- Using range-partitioning sort with a skewed partition vector.
Key takeaways
- Interquery gives throughput; intraquery gives response time.
- Intraquery is intra-operation or inter-operation (pipelined or independent).
- Partitioned hash join sends matching tuples to the same node.
- Amdahl: speedup = 1 / (s + (1 - s) / n).
Practice questions
- What is interquery parallelism?
- What is pipelined parallelism?
- What limits speedup according to Amdahl's law?
Answers to the practice questions
- Running different queries or transactions at the same time on different processors.
- Passing output tuples of one operation straight to the next while it is still running.
- The serial fraction of the work.
Sources
- Official BCA syllabus Advanced Database Systems, course code 25BCA406DS04, Unit III
