Skip to content

SIGMOD 2026Published in Proceedings of the ACM on Management of Data (PACMMOD)

GenRewrite: Query Rewriting via Large Language Models

Jie Liu, Barzan Mozafari

Abstract

Query rewriting is an effective technique for refining poorly written queries before they reach the query optimizer. However, manual rewriting is not scalable, as it is prone to errors and requires deep expertise. Traditional query rewriting algorithms fall short too; rule-based approaches fail to generalize to new query patterns, while synthesis-based methods struggle with complex queries. Large language models possess broad knowledge and advanced reasoning capabilities, making them a promising solution for these challenges. GenRewrite is a holistic system that leverages LLMs for query rewriting beyond traditional rules. It introduces Natural Language Rewrite Rules as hints and a means of transferring knowledge across queries, alongside a counterexample-guided technique that iteratively corrects syntactic and semantic errors in rewritten queries.