Skip to main content
QUICK REVIEW

[Paper Review] Learning to Optimize Join Queries With Deep Reinforcement Learning

Sanjay Krishnan, Zongheng Yang|arXiv (Cornell University)|Aug 9, 2018
Optimization and Search ProblemsComputer Science50 references82 citations
TL;DR

The paper proposes DQ, a deep reinforcement learning-based optimizer that learns join search strategies to replace fixed heuristics, achieving competitive plans with faster learnings across Calcite, PostgreSQL, and SparkSQL.

ABSTRACT

Exhaustive enumeration of all possible join orders is often avoided, and most optimizers leverage heuristics to prune the search space. The design and implementation of heuristics are well-understood when the cost model is roughly linear, and we find that these heuristics can be significantly suboptimal when there are non-linearities in cost. Ideally, instead of a fixed heuristic, we would want a strategy to guide the search space in a more data-driven way---tailoring the search to a specific dataset and query workload. Recognizing the link between classical Dynamic Programming enumeration methods and recent results in Reinforcement Learning (RL), we propose a new method for learning optimized join search strategies. We present our RL-based DQ optimizer, which currently optimizes select-project-join blocks. We implement three versions of DQ to illustrate the ease of integration into existing DBMSes: (1) A version built on top of Apache Calcite, (2) a version integrated into PostgreSQL, and (3) a version integrated into SparkSQL. Our extensive evaluation shows that DQ achieves plans with optimization costs and query execution times competitive with the native query optimizer in each system, but can execute significantly faster after learning (often by orders of magnitude).

Motivation & Objective

  • Motivate the limitations of fixed heuristics in non-linear join costs and large plan spaces.
  • Propose a reinforcement learning approach to learn join search strategies within a traditional optimizer framework.
  • Demonstrate integration of the DQ system into multiple DBMSs with minimal code changes.
  • Show that data-driven planning can match or surpass heuristic baselines in planning time and plan quality under non-linear cost models.
  • Highlight data-efficient training leveraging optimal substructure in join optimization.

Proposed method

  • Formulate join optimization as a Markov Decision Process where states are query graphs and actions are joins.
  • Use Deep Q-learning to approximate the Q-function Q(G,c) for a given join c on state G.
  • Featurize the query graph and joins with one-hot attribute indicators and inclusion of selections and physical operator choices.
  • Collect training data efficiently from native optimizers by exploiting optimal substructure to generate (G,c,J(c),G') samples.
  • Integrate the DQ optimizer as a learning-based replacement for traditional plan-search modules in Calcite, PostgreSQL, and SparkSQL.
  • Train offline on workloads from Join Order Benchmark and TPC-DS with minimal overhead and optional exploration (epsilon-greedy).
  • Justify using Q-learning over policy-based methods to produce scores for all joins in subplans and enable top-k planning.

Experimental results

Research questions

  • RQ1Can a deep RL model learn data-driven join search policies that perform well across different cost models and workloads?
  • RQ2How does integrating an RL-based search policy affect planning time and plan quality compared to native optimizers across Calcite, PostgreSQL, and SparkSQL?
  • RQ3Does the approach handle non-linear cost behaviors (e.g., memory spills, reusable hash tables) more robustly than fixed heuristics?
  • RQ4What data-efficiency can be achieved by leveraging optimal substructure data from native optimizers for training?

Key findings

  • DQ achieves planning times up to >200x faster than exhaustive dynamic programming enumeration in some scenarios.
  • DQ delivers plans competitive with native optimizers in each system.
  • DQ can improve plan quality over fixed heuristics under non-linear cost models by substantial factors (e.g., 1.7x to 3x over six baselines in simulated costs).
  • Training data is efficiently generated by exploiting optimal subplans from a native optimizer, yielding large training datasets from a single plan.
  • Integration into PostgreSQL and SparkSQL required fewer than 300 lines of code changes per system.
  • DQ enables broader plan spaces (e.g., bushy plans and cartesian products) due to planning speedups, with potential execution-time benefits.

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.