title: LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for
    Boosting Query Efficiency
summary: Query rewrite, which aims to generate more efficient queries by altering a
  SQL query's structure without changing the query result, has been an important
  research problem. In order to maintain equivalence between the rewritten query
  and the original one during rewriting, traditional query rewrite methods always
  rewrite the queries following certain rewrite rules. However, some problems
  still remain. Firstly, existing methods of finding the optimal choice or
  sequence of rewrite rules are still limited and the process always costs a lot
  of resources. Methods involving discovering new rewrite rules typically require
  complicated proofs of structural logic or extensive user interactions.
  Secondly, current query rewrite methods usually rely highly on DBMS cost
  estimators which are often not accurate. In this paper, we address these
  problems by proposing a novel method of query rewrite named LLM-R2, adopting a
  large language model (LLM) to propose possible rewrite rules for a database
  rewrite system. To further improve the inference ability of LLM in recommending
  rewrite rules, we train a contrastive model by curriculum to learn query
  representations and select effective query demonstrations for the LLM.
  Experimental results have shown that our method can significantly improve the
  query execution efficiency and outperform the baseline methods. In addition,
  our method enjoys high robustness across different datasets.
paper_authors._id: 6625f216fe61f6233049686b
paper_authors.name: Zhaodonghui Li
paper_authors.status: claimed_verified
paper_authors.statusLastChangedAt: 2024-04-22T11:53:24.832Z
paper_authors._id: 662620578c67281c9eb17f7b
paper_authors.avatarUrl: /avatars/0e9c26d2234a9f1898a380f183b1645a.svg
paper_authors.fullname: Li Zhaodonghui
paper_authors.type: user
paper_authors.user: LZ12DH
paper_authors._id: 6625f216fe61f6233049686c
paper_authors.name: Haitao Yuan
paper_authors.status: admin_assigned
paper_authors.statusLastChangedAt: 2024-04-22T14:05:56.838Z
paper_authors._id: 64a5224a49fe135745c715ad
paper_authors.avatarUrl: /avatars/a645e79b0f06eea3f0bf796535fac18d.svg
paper_authors.fullname: haitao yuan
paper_authors.type: user
paper_authors.user: yht520100
paper_authors._id: 6625f216fe61f6233049686d
paper_authors.name: Huiming Wang
paper_authors._id: 6625f216fe61f6233049686e
paper_authors.name: Gao Cong
paper_authors._id: 6625f216fe61f6233049686f
paper_authors.name: Lidong Bing
paper_authors.status: claimed_verified
paper_authors.statusLastChangedAt: 2024-04-22T09:19:13.753Z
paper_authors._id: 6454685a548f22be598414c4
paper_authors.avatarUrl: https://cdn-avatars.huggingface.co/v1/production/uploads/noauth/eMjMWKJ-AouF7eY1-RzGF.jpeg
paper_authors.fullname: Lidong Bing
paper_authors.type: user
paper_authors.user: LidongBing
paper_title: LLM-R2: A Large Language Model Enhanced Rule-based Rewrite System for
    Boosting Query Efficiency
paper_summary: Query rewrite, which aims to generate more efficient queries by altering a
  SQL query's structure without changing the query result, has been an important
  research problem. In order to maintain equivalence between the rewritten query
  and the original one during rewriting, traditional query rewrite methods always
  rewrite the queries following certain rewrite rules. However, some problems
  still remain. Firstly, existing methods of finding the optimal choice or
  sequence of rewrite rules are still limited and the process always costs a lot
  of resources. Methods involving discovering new rewrite rules typically require
  complicated proofs of structural logic or extensive user interactions.
  Secondly, current query rewrite methods usually rely highly on DBMS cost
  estimators which are often not accurate. In this paper, we address these
  problems by proposing a novel method of query rewrite named LLM-R2, adopting a
  large language model (LLM) to propose possible rewrite rules for a database
  rewrite system. To further improve the inference ability of LLM in recommending
  rewrite rules, we train a contrastive model by curriculum to learn query
  representations and select effective query demonstrations for the LLM.
  Experimental results have shown that our method can significantly improve the
  query execution efficiency and outperform the baseline methods. In addition,
  our method enjoys high robustness across different datasets.
paper_ai_summary: A new query rewriting method using large language models and contrastive learning improves query execution efficiency and robustness across various datasets.
paper_ai_keywords: large language model contrastive model curriculum learning query representations query demonstrations query rewriting query execution efficiency