Query Engines
A query engine takes a SQL query and runs it over data stored somewhere else: Parquet files on S3, tables in Hive or Iceberg, even PostgreSQL or Kafka. Unlike a database it usually does not own the storage; it only reads (and sometimes writes) files and asks a catalog where tables live and what their schemas are. Splitting compute from storage lets you keep one copy of the data on cheap object storage and point many engines at it. Distributed engines such as Trino, Presto, Spark SQL and Hive spread each query over many machines so a scan of terabytes takes seconds or minutes instead of hours.
How a distributed query runs
Every engine in this section follows the same shape: one node plans, many nodes scan in parallel, and data is shuffled (exchanged) between them so rows with the same key meet on the same machine.
- The client sends SQL to the coordinator. The table orders is three Parquet files on object storage.
- The coordinator parses and optimizes the query, asks the catalog which files make up the table, and hands each worker a split (a file or part of one).
- Workers scan their splits in parallel, reading only the city and amount columns (with a
WHEREclause they would also skip row groups the filter rules out). - Each worker computes a partial aggregate over its own rows. Three rows become two or three small sums, so far less data moves next.
- Exchange: partial results are routed by hash(city), so every NYC row lands on the same task, every TOR row on another. This is the shuffle.
- Each task adds up its partial sums into the final aggregate, and the result streams back to the client.
The steps hide the hard parts: a cost-based optimizer picks join order and join strategy (broadcast the small table or shuffle both), pushdown sends filters and column lists into the connector or file reader, and the exchange is where most network traffic, memory pressure and skew problems appear.
The engines in this section
| Engine | Execution model | Strength | Status in 2026 |
|---|---|---|---|
| Apache Hive | Compiles SQL to Tez DAGs (MapReduce is deprecated) | Batch ETL on Hadoop; the Hive Metastore catalog | Hive 4.x is the maintained line. The engine is legacy for new projects; the Metastore is still everywhere. |
| Spark SQL | Stages separated by shuffle files; tasks retried on failure | Large ETL, mixing SQL with Python/Scala, ML | Spark 4.x (4.0 released in 2025) is current; the default batch engine of the lakehouse. |
| Trino | MPP, pipelined in memory; optional fault-tolerant mode | Interactive analytics and federation across many sources | Very active; powers Amazon Athena and Starburst. |
| Presto | MPP, pipelined in memory; C++ native workers (Velox) | Interactive analytics at Meta-scale | Active under the Linux Foundation, led by Meta, IBM and Uber. |
Other engines worth knowing: DuckDB and Polars (single-machine, in-process, often enough for data up to hundreds of GB), StarRocks and Apache Doris (MPP engines with their own storage that also query lakes), Dremio, Apache DataFusion (a Rust library many new engines build on), and managed services such as BigQuery, Athena and Snowflake. Apache Drill, once a popular schema-free engine, sees little activity today.
Choosing
- Interactive dashboards and ad hoc SQL on the lake → Trino (or Presto), or a managed variant such as Athena or Starburst.
- Heavy nightly ETL, joins over huge tables, Python in the same job → Spark SQL.
- Data fits on one machine → DuckDB. Do not run a cluster you do not need.
- Existing Hive warehouse → keep the Metastore (or migrate to an Iceberg REST catalog), and move the queries to Spark or Trino.
Common mistakes
- Many small files. Each file is at least one split and one request; a million 100 KB files will be slower than a hundred 1 GB files.
- No partition or sort strategy, so every query scans the full table. Partition by date and filter on it.
- Joining two huge tables without thinking about skew. One hot key (a single customer with 30 % of orders) makes one task run for an hour while others idle.
- Using an interactive engine for 6-hour ETL without enabling its fault-tolerant mode: one worker loss restarts the whole query.
Learning Resources
- How Query Engines Work: Andy Grove’s free book, build one step by step
- CMU 15-445/645 Intro to Database Systems: query processing and optimization lectures
- Presto: SQL on Everything (ICDE 2019): the architecture paper behind Presto and Trino
- Spark SQL: Relational Data Processing in Spark (SIGMOD 2015)
- Dremel: Interactive Analysis of Web-Scale Datasets: the system behind BigQuery