arXiv:2608.23402cs.DBAug 2026

Manuscript Offprint

arXiv:2608.23402

EXPLAIN Yourself! Finding Query Planner Stalls Across DBMSes

Geoffrey X. Yu, Ryan Marcus, Tim Kraska

Abstract

Query planners are typically expected to produce optimized plans quickly, leading many researchers (including the authors of this paper) and practitioners to design systems that assume query planning is a low-cost operation. Using a lightweight agentic search, we show that this assumption does not always hold. Across seven DBMSes, including four commercial systems, we find at least one query per system that takes more than three minutes to plan. In addition to being slow to plan, such queries risk tying up database resources without performing useful work, creating a potential denial-of-service vector. We analyze the queries our search uncovers and compare how the seven systems respond to each pattern. We find that although the queries triggering slow planning are largely DBMS-specific, recurring pathologies involving correlated subqueries, CTE expansion, repeated subquery expressions, disjunctive joins, and constant folding affect multiple systems. We release our uncovered queries along with a curated suite of parameterized query pathologies that researchers and database engineers can use to test planner robustness. Overall, our results show that query planning cannot always be treated as a predictably inexpensive operation and that its latency and robustness deserve further attention from both database researchers and engineers.

1 Introduction

Query planners are designed to quickly produce physical plans. Recently, researchers (including the authors of this paper) and practitioners have treated this design goal as an assumption, developing components that assume query plans can be cheaply generated. For example, learned cost models and query run time predictors, which are used to make time-sensitive decisions such as query scheduling, featurize physical query plans [9,17–19,26,32,37,38][9, 17–19, 26, 32, 37, 38] in order to make their predictions. This is not only an academic assumption; production-grade schedulers like Auto-WLM [30][30] and query performance predictors like Stage [37][37] both rely on featurizing query plans and making fast decisions under single-digit milliseconds [37][37].

Unfortunately, this assumption is unsafe in practice. Consider the query shown in Listing 1. Despite taking only 6 milliseconds to plan on DuckDB, this query takes over 14 minutes to plan on an unnamed [25] commercial database system, whose vendor is aware of this behavior. This example shows how even a conceptually simple query can take surprisingly long to plan in practice.

We call such instances of slow query planning a query planner stall. In addition to delaying query execution, stalls raise system robustness concerns because the planner may consume substantial CPU time or memory before even executing the query. Furthermore, a malicious user could expend planner resources simply by issuing adversarial EXPLAIN commands, creating a potential denial-of-service risk: a risk amplified by agentic workloads which are expected to issue arbitrary and novel queries. Planner stalls

SELECT COUNT(*) FROM lineitem AS 11 WHERE EXISTS (SELECT 1 FROM lineitem AS 12 WHERE 12.1_orderkey = 11.1_orderkey AND 12.1_suppkey <> 11.1_suppkey) AND NOT EXISTS (SELECT 1 FROM lineitem AS 13 WHERE 13.1_suppkey <> 11.1_suppkey AND 13.1_receiptdate > 13.1_commitdate AND 13.1_orderkey = 11.1_orderkey)

Listing 1. This TPC-H-derived query takes about 14 minutes to EXPLAIN on DBMS A, but 6 milliseconds on DuckDB.

could thus threaten robustness even when no user intentionally constructs an adversarial query.

In this work, we demonstrate that stalls occur across diverse DBMSes and can be easily generated: we give an LLM agent a single tool that measures the planning time of a submitted SQL query and ask it to find slow-planning queries. Despite the simplicity of this approach, the agent uncovers planner stalls on all seven DBMSes we tested, including four commercial systems. On all seven systems, we find at least one query that takes more than three minutes to plan. Some of the queries we find are not obviously contrived or adversarial; indeed, we encountered one such query incidentally while investigating an unrelated problem [39][39]. Our results suggest that query planner stalls are not just an isolated problem in a single DBMS, but rather a recurring phenomenon across many modern, production-grade DBMSes.

We study the queries uncovered by our agent and identify recurring pathologies involving correlated subqueries, CTEs, repeated subquery expressions, disjunctive joins, and constant folding. Across these cases, we find that planner transformations and search procedures can cause planning time to grow sharply, and sometimes exponentially, as modest amounts of query structure are added. Which patterns trigger stalls varies across DBMSes, suggesting that these queries are not necessarily fundamentally difficult to plan, but instead expose problematic cases in a specific planner's optimization strategy or implementation.

Looking broadly, our findings motivate future research on practical query planner robustness. A robust query planner should guarantee that it produces a usable plan within a bounded time, degrade gracefully when optimization becomes difficult, and resist adversarial inputs that trigger pathological planning behavior. Similarly, downstream systems that rely on physical plans should tolerate delayed or unavailable plans. Toward this goal, we contribute (i) an analysis of query pathologies that lead to planner stalls on existing DBMSes, and (ii) our uncovered queries, along with a suite of parameterized query pathology families distilled from our analysis, for testing planner robustness. 1^{1} We will also release the lightweight agentic search tool we used to find the queries.

1^{1}https://github.com/geoffxy/explain-yourself/

Figure

Figure 1: An overview of our agentic search procedure.

References (16)