keepcalculator

06 Numbers and Powers

Parallel Query Server: What It Does & How It Works

Card No. 06·6423 · Updated · Standard formula, shown below

Estimated speedup 4.44 x
Estimated parallel time
13.50 seconds
Result
Query time (single server)
60 seconds
You entered
CPU cores available
8 cores
You entered
You enter
Query time (single server), CPU cores available
You get
Estimated speedup, Estimated parallel time
Rounding
2 dp

A parallel query server splits a single database query into multiple smaller tasks, runs those tasks simultaneously across several CPU cores or machines, and then combines the partial results into one answer. You enter the query as you normally would; the server automatically distributes the work, collects the pieces, and returns the final result set, often much faster than a single-process server.

Formula

The calculator estimates the speedup and the new query time when you parallelize a query across multiple cores. The formula for the estimated parallel time is:

Estimated parallel time = (single-server time / number of cores) + (10% of single-server time)

Where:

  • Single-server time (t) – the time the same query takes on a single core, in seconds.
  • Number of cores (c) – the CPU cores available for parallel execution.
  • 10% overhead – an approximation of the cost of splitting the query, coordinating the tasks, and merging results.

The speedup is simply the original time divided by the estimated parallel time.

Worked Example

Using the defaults: a query takes 60 seconds on one core, and you have 8 cores available.

  1. Ideal parallel time = 60 / 8 = 7.5 seconds.
  2. Overhead = 10% of 60 = 6 seconds.
  3. Estimated parallel time = 7.5 + 6 = 13.5 seconds.
  4. Speedup = 60 / 13.5 ≈ 4.44x.

The calculator shows a speedup of 4.44 and a new time of 13.5 seconds. Notice that 8 cores do not give an 8x speedup because of the overhead.

Background: Why Parallel Query Servers Exist

Databases store data on disk or in memory, and queries scan, filter, join, and aggregate that data. For decades, a single CPU core executed these steps one after another. As data volumes grew, query times stretched from seconds to minutes or hours. Hardware makers responded by adding more cores to each processor, but software had to change to use them. Parallel query servers are that software: they break a query into independent chunks that can run on different cores at the same time.

The idea is not new – research prototypes existed in the 1980s – but it became mainstream when commodity servers shipped with 8, 16, or more cores. Today, every major database (PostgreSQL, MySQL, SQL Server, Oracle, and cloud data warehouses like Snowflake and BigQuery) includes some form of parallel query execution.

How It Works

When you submit a query, the server goes through several steps:

  1. Parse and optimize: The query is turned into an internal plan. The optimizer decides whether parallel execution is likely to help, based on table sizes, available memory, and the query’s complexity.
  2. Plan splitting: The plan is divided into fragments. For example, a full table scan can be split into ranges of rows, each handled by a separate worker. A join can be split by hashing the join key so each worker handles a subset of the keys.
  3. Worker assignment: The server spawns worker processes or threads – one per core (or per configured limit). Each worker runs its fragment on its own data slice.
  4. Partial results: Each worker produces a partial result (e.g., row counts, sums, or sorted runs).
  5. Merge: A coordinator collects the partial results and combines them. For aggregations, it sums the partial sums; for sorts, it merges the sorted runs; for joins, it concatenates the matched rows.
  6. Return: The final result set is sent back to the client.

The key is that each worker works on a different slice of data, so they do not interfere. The coordinator only handles the final merge, which is usually small compared to the scan.

Types of Parallelism

There are two main forms of parallelism in query servers:

  • Intra-query parallelism: One query uses multiple workers. This is what most people mean by a parallel query server. It speeds up a single slow query.
  • Inter-query parallelism: Multiple queries run at the same time, each on its own core. This improves overall throughput, not the speed of any single query. Most databases do this automatically.

Some systems also use intra-operation parallelism (splitting a single scan into ranges) and inter-operation parallelism (running different stages of a query pipeline simultaneously, like a producer-consumer pattern). Modern databases use both.

When Parallel Execution Helps (and When It Doesn’t)

Parallel execution is not a magic switch. It helps most with:

  • Large table scans – reading millions of rows.
  • Heavy aggregations – GROUP BY on big tables.
  • Large sorts – ORDER BY without a useful index.
  • Joins between big tables.

It helps least with:

  • Queries that return a few rows using an index – the index lookup is already fast.
  • Queries with a small result set that requires a lot of coordination.
  • Queries that are already I/O-bound – if the disk is the bottleneck, more CPUs won’t help.
  • Very short queries – the overhead of spawning workers can exceed the query time.

A common misconception is that parallel execution always speeds things up. In practice, the optimizer decides based on cost estimates. If the query is trivial, the server runs it on one core. You can often see the decision in the query plan.

How to Choose Parallel Settings

Database administrators can usually control parallelism with configuration parameters. The most common ones are:

  • Maximum degree of parallelism (MAXDOP): The maximum number of cores a single query can use. On a 16-core server, you might set this to 8 to leave room for other workloads.
  • Cost threshold for parallelism: The estimated cost above which the optimizer considers parallel execution. Lower values make more queries go parallel, but too low can cause overhead.
  • Number of workers: Some systems let you set the total worker pool size.

There is no universal best setting. A good starting point is to set MAXDOP to the number of physical cores (not hyperthreads) and adjust based on observed performance. For OLTP (many small transactions), keep it low (2 or 4) to avoid slowing down short queries. For data warehousing (few large queries), you can go higher.

Common Problems and Misconceptions

Parallel execution can cause issues if not configured carefully:

  • Resource contention: Too many parallel workers can saturate CPU, memory, or I/O, slowing down all queries.
  • Skew: If one worker gets a much larger data slice than others (e.g., a join key that appears frequently), that worker becomes a bottleneck. The whole query waits for it.
  • Memory pressure: Each worker needs memory for sorting and hashing. Parallel queries can exhaust memory, causing spills to disk.
  • Overhead for small queries: Spawning workers, coordinating, and merging can take longer than just running the query on one core.

A frequent misconception is that “parallel� means “instant.� It does not. The speedup is limited by the portion of the query that cannot be parallelized (Amdahl’s Law). For example, if 10% of the query is serial (like the final merge), the maximum speedup even with infinite cores is 10x.

Frequently Asked Questions

Why is my query not using parallel execution?

The optimizer may have decided the query is too small to benefit, or the cost threshold is set too high. Check the query plan to see if a parallel plan was considered. Also, some query types (like those with certain subqueries or cursors) cannot be parallelized.

Does parallel query work on a single-core machine?

No. Parallel execution requires at least two cores. On a single-core machine, the server runs queries serially.

How much faster will my query be with 8 cores?

It depends on the query and the overhead. In the best case, it could be close to 8x, but with typical overhead (10-20%) and serial portions, you might see 4-6x. Use the calculator above for a rough estimate.

Can parallel queries corrupt data?

No. The database engine ensures that parallel execution produces the same result as serial execution. The workers operate on separate data slices and the merge step is deterministic.

What is the difference between parallel query and a distributed database?

Parallel query uses multiple cores on a single server. A distributed database spreads data and queries across multiple servers. Many modern systems do both: parallel execution within each server and distribution across servers.

Should I always enable parallel execution?

No. For OLTP workloads with many small queries, parallel execution can add overhead. It is best for large analytical queries. Test with your actual workload and adjust the cost threshold and MAXDOP accordingly.

Related

Formula used
in t | Query time (single server) | seconds | 60 | 0
in c | CPU cores available | cores | 8 | 1 | 64
out speedup | Estimated speedup | x | t / (t / c + 0.1 * t) | 2
out new_time | Estimated parallel time | seconds | t / c + 0.1 * t | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →