---
title: "query engine"
description: "A query engine parses, optimizes, and executes SQL queries against data sources. Learn its core architecture, how it differs from a database, and see examples like DuckDB and Presto."
canonical: "https://motherduck.com/glossary/query-engine/"
related:
  - title: "Why Use DuckDB for Analytics?"
    url: "https://motherduck.com/blog/six-reasons-duckdb-slaps/"
  - title: "Results | MotherDuck Docs"
    url: "https://motherduck.com/docs/concepts/results/"
  - title: "Glossary | MotherDuck Docs"
    url: "https://motherduck.com/docs/troubleshooting/glossary/"
---

# query engine

> A query engine parses, optimizes, and executes SQL queries against data sources. Learn its core architecture, how it differs from a database, and see examples like DuckDB and Presto.

A **query engine** is the component of a data system that runs your analysis. It acts as the brain for your SQL requests, responsible for parsing a query, creating an efficient execution plan, and retrieving the requested data from sources like databases, data lakes, or local files.

## How a Query Engine Works: Core Architecture

A query engine typically processes a query in three main stages:

1.  **Parser:** The parser first receives the raw SQL query string. It checks the query for syntactical correctness and translates it into a logical, tree-like structure that the machine can understand.
2.  **Optimizer/Planner:** This is the most critical component for performance. The optimizer analyzes the parsed query and determines the most efficient way to execute it. It considers factors like available indexes, table sizes, and data distribution to create an execution plan that minimizes resource usage (like time, CPU, and memory).
3.  **Executor:** The executor takes the execution plan from the optimizer and runs it against the data source. It physically retrieves the data from storage (like disk or memory), performs the required operations (like joins, filters, and aggregations), and returns the final results to the user.

Modern query engines like [DuckDB](https://duckdb.org/) or [Presto](https://prestodb.io/) are designed to handle large-scale data analytics workloads, often supporting features like columnar storage, vectorized execution, and parallel processing. They aim to provide fast query response times, even on massive datasets, by employing advanced optimization techniques and leveraging in-memory processing where possible.

<glossary-callout guide="duckdb-cheatsheet-full" />

## Types of Query Engines: A Comparison

Query engines can be categorized by their architecture, which determines their ideal use case. Here’s a brief comparison:

| Category | How it Works | Examples | Best For |
|---|---|---|---|
| **Distributed** | Distributes a single query across a cluster of many servers to process massive datasets. | Presto, Trino, Spark SQL | Petabyte-scale data lake queries. |
| **Relational (OLTP)** | Bundled with a traditional database; optimized for transactional reads and writes. | PostgreSQL, MySQL | Application backends, transactional data. |
| **In-Process (OLAP)** | Runs directly inside an application, processing data locally with high speed. | DuckDB | Interactive analytics, embedded dashboards. |
| **Search-Based** | Optimized for fast text search and retrieval on unstructured or semi-structured data. | Elasticsearch | Log analysis, full-text search. |
