Comment on page
Multi-stage query engine (v2)
An overview of the multi-stage query engine.
This document is an overview of the new multi-stage query engine.
The multi-stage engine is the new query execution engine released in Pinot 1.0.0. Here are some useful links:
Apache Pinot 1.0 Multi-Stage Query Engine overview
You must use the multi-stage query engine (v2) to query distributed joins, window functions, and other multi-stage operators in real-time.
The multi-stage query engine is built to run real-time, complex ANSI SQL (ISO/IEC 9075). Highlights include joins and data correlations, particularly optimized for dynamic broadcast fact-dim joins, and partitioned-based or colocated table joins.
Although the multi-stage query engine can generally execute any complex ANSI SQL, it's not designed to run generic ANSI SQL in the most efficient way.
Some use cases to avoid:
- Large-scale, long-running queries designed to access and transform entire datasets are not recommended, as the multistage engine is a pure in-memory system.
- Complex correlation, join algorithms that touch many tables or have many non-trivial join conditions are not recommended.
- Long-running, complex queries such as ETL-type (extract, transform, and load) use cases are not recommended.
Figure 1: Multi-stage query execution model
The intermediate compute stage includes a set of processing servers and a data exchange mechanism.
Processing servers in the intermediate compute stage can be assigned to any Pinot component. Multiple servers can process data in the intermediate stage; the goal being to offload the computation from the brokers. Each server in the intermediate stage executes the same processing logic, but against different sets of data.
The data exchange service coordinates the transfer of the different sets of data to and from the processing servers.
The multi-stage query engine also includes a new query plan optimizer to produce optimal process logic in each stage and minimize data shuffling overhead.
With a multi-stage query engine, Pinot first breaks down the single scatter-gather query plan used in v1 into multiple query sub-plans that run across different sets of servers. We call these sub-plans “stage plans,” and refer to each execution as a “stage.”
Consider the following JOIN query example, which illustrates the breakdown of a query into stages. This query joins a real-time
orderStatustable with an offline
os.uid, -- user ID
os.rName, -- restaurant Name
c.ltv -- life-time value
orderStatus AS os
INNER JOIN customer AS c
ON os.uid = c.uid
os.ic < 10 -- item count
AND c.lto > 5 –- life-time order count
In the first stage, the query is processed as follows:
- 1.Real-time servers execute the filter query on the
SELECT os.uid, os.rName FROM orderStatus AS os WHERE os.ic < 10
- 2.Offline servers execute the filter query offline
SELECT c.uid c.ltv FROM customer AS c WHERE c.lto > 5
- 3.The data exchange service shuffles data shuffle, so all data with the same unique customer ID is sent to the same processing server for the next stage.
- 4.On each processing server, an inner JOIN is performed.
- 1.On each processing server, an inner JOIN is performed.
- After the join algorithm completes, the results are sent back to the broker, and then sent to clients.