Lune

VLDB2022Top-tier venue

A Learned Query Rewrite System using Monte Carlo Tree Search

Xuanhe Zhou, Guoliang Li, Chengliang Chai, Jianhua Feng

Abstract

Query rewrite transforms a SQL query into an equivalent one but with higher performance. However, SQL rewrite is an NP-hard problem, and existing approaches adopt heuristics to rewrite the queries. These heuristics have two main limitations. First, the order of applying different rewrite rules significantly affects the query performance. However, the search space of all possible rewrite orders grows exponentially with the number of query operators and rules and it is rather hard to find the optimal rewrite order. Existing methods apply a pre-defined order to rewrite queries and will fall in a local optimum. Second, different rewrite rules have different benefits for different queries. Existing methods work on single plans but cannot effectively estimate the benefits of rewriting a query. To address these challenges, we propose a policy tree based query rewrite framework, where the root is the input query and each node is a rewritten query from its parent. We aim to explore the tree nodes in the policy tree to find the optimal rewrite query. We propose to use Monte Carlo Tree Search to explore the policy tree, which navigates the policy tree to efficiently get the optimal node. Moreover, we propose a learning-based model to estimate the expected performance improvement of each rewritten query, which guides the tree search more accurately. We also propose a parallel algorithm that can explore the tree search in parallel in order to improve the performance. Experimental results showed that our method significantly outperformed existing approaches.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

28 top-tier papers have cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • Adaptive Code Learning for Spark Configuration Tuning cites Query Performance Prediction for Concurrent Queries using Graph Embedding
  • Adaptive Code Learning for Spark Configuration Tuning cites An End-to-End Learning-based Cost Estimator
  • Adaptive Code Learning for Spark Configuration Tuning cites Reinforcement Learning with Tree-LSTM for Join Order Selection
  • Learned Cardinality Estimation: A Design Space Exploration and A Comparative Evaluation cites Query Performance Prediction for Concurrent Queries using Graph Embedding
  • Learned Cardinality Estimation: A Design Space Exploration and A Comparative Evaluation cites Deep Unsupervised Cardinality Estimation
  • Learned Cardinality Estimation: A Design Space Exploration and A Comparative Evaluation cites An End-to-End Learning-based Cost Estimator
  • Learned Cardinality Estimation: A Design Space Exploration and A Comparative Evaluation cites Reinforcement Learning with Tree-LSTM for Join Order Selection
  • Query Performance Prediction for Concurrent Queries using Graph Embedding cites An End-to-End Learning-based Cost Estimator
  • LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency cites WeTune: Automatic Discovery and Verification of Query Rewrite Rules
  • GenRewrite: Query Rewriting via Large Language Models cites LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query Efficiency
  • GenRewrite: Query Rewriting via Large Language Models cites WeTune: Automatic Discovery and Verification of Query Rewrite Rules
  • An End-to-End Learning-based Cost Estimator cites Reinforcement Learning with Tree-LSTM for Join Order Selection
  • Reinforcement Learning with Tree-LSTM for Join Order Selection cites An End-to-End Learning-based Cost Estimator
  • Cost-based or Learning-based? A Hybrid Query Optimizer for Query Plan Selection cites Learned Cardinality Estimation: A Design Space Exploration and A Comparative Evaluation
  • Cost-based or Learning-based? A Hybrid Query Optimizer for Query Plan Selection cites Deep Unsupervised Cardinality Estimation
  • Cost-based or Learning-based? A Hybrid Query Optimizer for Query Plan Selection cites An End-to-End Learning-based Cost Estimator
  • Cost-based or Learning-based? A Hybrid Query Optimizer for Query Plan Selection cites Reinforcement Learning with Tree-LSTM for Join Order Selection
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers28

  1. Cost-based or Learning-based? A Hybrid Query Optimizer for Query Plan SelectionXiang Yu, Chengliang Chai, Guoliang Li, Jiabin LiuVLDB 2022 · 82 citations
  2. LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for Boosting Query EfficiencyZhaodonghui Li, Haitao Yuan, Huiming Wang, Gao Cong et al.VLDB 2025 · 52 citations
  3. WeTune: Automatic Discovery and Verification of Query Rewrite RulesZhaoguo Wang, Zhou Zhou, Yicun Yang, Haoran Ding et al.SIGMOD 2022 · 35 citations
  4. Adaptive Code Learning for Spark Configuration TuningChen Lin, Junqing Zhuang, Jiadong Feng, Hui Li et al.ICDE 2022 · 28 citations
  5. GenRewrite: Query Rewriting via Large Language ModelsJie Liu, Barzan MozafariSIGMOD 2026 · 27 citations

Builds on8

  1. An End-to-End Learning-based Cost EstimatorJi Sun, Guoliang LiVLDB 2020 · 251 citations
  2. Deep Unsupervised Cardinality EstimationZongheng Yang, Eric Liang, Amog Kamsetty, Chenggang Wu et al.VLDB 2020 · 206 citations
  3. Reinforcement Learning with Tree-LSTM for Join Order SelectionXiang Yu, Guoliang Li, Chengliang Chai, Nan TangICDE 2020 · 168 citations
  4. Query Performance Prediction for Concurrent Queries using Graph EmbeddingXuanhe Zhou, Ji Sun, Guoliang Li, Jianhua FengVLDB 2020 · 96 citations
  5. Learned Cardinality Estimation: A Design Space Exploration and A Comparative EvaluationJi Sun, Jintao Zhang, Zhaoyan Sun, Guoliang Li et al.VLDB 2022 · 90 citations

Related papers

  1. ReSequel: Robust LLM-assisted Query Rewriting and Optimization using Templatization and SamplingSaeed Fathollahzadeh, Essam Mansour, Matthias BoehmVLDB 2026
  2. Efficient Query Rewrite Rule Discovery via Standardized Enumeration and Learning-to-RankYuan Zhang, Yuxing Chen, Yuekun Yu, Jinbin Huang et al.ICDE 2026
  3. QueryBooster: Improving SQL Performance Using Middleware Services for Human-Centered Query RewritingQiushi Bai, Sadeem Alsudais, Chen LiVLDB 2023 · 14 citations
  4. SlabCity: Whole-Query Optimization using Program SynthesisRui Dong, Jie Liu, Yuxuan Zhu, Cong Yan et al.VLDB 2023 · 11 citations
  5. ARG: Testing Query Rewriters via Abstract Rule Guided FuzzingDawei Li, Yuxiao Guo, Qifan Liu, Jie Liang et al.ASE 2025
Dusk over the sea between two cliffs drawn in fine vertical lines