Skip to main content
QUICK REVIEW

[Paper Review] Bao: Learning to Steer Query Optimizers

Ryan Marcus, Parimarjan Negi|arXiv (Cornell University)|Apr 8, 2020
Data Stream Mining TechniquesComputer Science59 references16 citations
TL;DR

Bao is a reinforcement learning-based system that enhances traditional query optimizers by learning to issue coarse-grained hints—such as disabling specific join operators—to improve query performance. By combining tree convolutional neural networks with Thompson sampling in a contextual multi-armed bandit framework, Bao achieves faster learning (within ~1 hour), reduces both median and tail latency, and maintains performance under workload, data, and schema changes, outperforming both open-source and commercial optimizers.

ABSTRACT

Query optimization remains one of the most challenging problems in data management systems. Recent efforts to apply machine learning techniques to query optimization challenges have been promising, but have shown few practical gains due to substantive training overhead, inability to adapt to changes, and poor tail performance. Motivated by these difficulties and drawing upon a long history of research in multi-armed bandits, we introduce Bao (the BAndit Optimizer). Bao takes advantage of the wisdom built into existing query optimizers by providing per-query optimization hints. Bao combines modern tree convolutional neural networks with Thompson sampling, a decades-old and well-studied reinforcement learning algorithm. As a result, Bao automatically learns from its mistakes and adapts to changes in query workloads, data, and schema. Experimentally, we demonstrate that Bao can quickly (an order of magnitude faster than previous approaches) learn strategies that improve end-to-end query execution performance, including tail latency. In cloud environments, we show that Bao can offer both reduced costs and better performance compared with a sophisticated commercial system.

Motivation & Objective

  • To address the limitations of existing learned query optimizers, including high training overhead, brittleness to data/schema changes, and poor tail performance.
  • To improve end-to-end query execution performance—especially tail latency—without replacing traditional query optimizers.
  • To enable fast adaptation to dynamic workloads, data, and schema changes through efficient, incremental learning.
  • To provide customizable optimization goals (e.g., CPU time, I/O) for multi-tenant cloud environments.
  • To integrate machine learning enhancements atop existing optimizers rather than replacing them, preserving decades of hand-optimized wisdom.

Proposed method

  • Bao frames query hint selection as a contextual multi-armed bandit problem, where each hint set is an 'arm' and query plans are selected based on predicted performance.
  • It uses tree convolutional neural networks to embed query logical plans and extract structural features for context representation.
  • Thompson sampling is employed to balance exploration and exploitation in selecting hint sets, ensuring efficient learning with low regret.
  • For each incoming query, Bao selects a hint set, executes the query via the underlying optimizer, and observes the reward (e.g., execution time, I/O count) to update its policy.
  • The system learns a policy that maps query structure to optimal hint sets, minimizing regret relative to the best possible hint set for each query.
  • Training is efficient: Bao achieves significant performance gains after only ~1 hour of training on real-world workloads.

Experimental results

Research questions

  • RQ1Can a learned system improve query optimizer performance with minimal training time and without replacing the underlying optimizer?
  • RQ2Can such a system maintain performance gains under dynamic changes in data, schema, or query workload?
  • RQ3Can the system reduce both median and tail latency, especially in scenarios with sparse training data?
  • RQ4Can the system be customized to optimize for different performance metrics (e.g., CPU time, I/O)?
  • RQ5Can the system avoid catastrophic regressions that commonly plague learned optimizers?

Key findings

  • Bao reduces median regret below that of PostgreSQL after just one hour of training, achieving performance improvements across both IMDb and Stack workloads.
  • In tail performance, Bao never selects a plan requiring more than 30 CPU seconds, while PostgreSQL selects plans requiring over 720 seconds in some cases.
  • For the Join Order Benchmark, Bao incurs regressions on only three of 113 queries, all under 3 seconds, and improves performance by over 20 seconds on ten queries.
  • Bao achieves lower median regret than PostgreSQL across both CPU time and I/O metrics, regardless of which metric it was trained on.
  • When trained to minimize CPU time, Bao achieves significantly lower median and tail regret than PostgreSQL, even in warm-cache scenarios.
  • Bao’s ability to customize optimization goals enables it to reduce costs and improve performance in multi-tenant cloud environments.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.