How WeTune 2.0 Automates SQL Query Rewrite for GaussDB Performance Boost
WeTune 2.0, a revolutionary tool developed by Shanghai Jiao Tong University and GaussDB experts, automatically discovers and validates SQL rewrite rules, dramatically improving query performance in Huawei Cloud GaussDB by eliminating manual rule creation, supporting extensive rule enumeration, equivalence verification, and cost‑based evaluation, while addressing scalability challenges.
Introduction
In the database world, query rewrite is a critical step for boosting performance. WeTune is a revolutionary tool that can automatically discover new rewrite rules, breaking the reliance on manual rule discovery and significantly improving database query performance.
Technical Talk Overview
Shanghai Jiao Tong University Software School Deputy Dean Wang Zhaoguo and GaussDB optimizer expert Ethan jointly held a technical discussion titled "Intelligent Optimization Revealed – Automatic Mining and Generation of GaussDB Query Rewrite Rules" . The talk covered the background of the WeTune 2.0 project, its automatic rule discovery method and implementation, advantages of version 2.0, its application and technical translation in GaussDB, and future prospects.
Project Background
Query rewrite is an essential part of SQL optimization. Traditionally, adding rewrite rules relies on the accumulated experience of database experts. With external frameworks and large‑language models now able to generate SQL automatically, existing rewrite rules often become insufficient.
WeTune Core Idea
WeTune automatically discovers rewrite rules for specific scenarios. The tool was developed by Wang Zhaoguo’s team and successfully integrated into GaussDB through deep collaboration.
Automatic Rule Discovery Methods
Method 1: Brutally enumerate all syntactically valid rewrite rules.
Method 2: Use formal verification to check whether the enumerated rules are semantically equivalent (input and output SQLs).
Method 3: Borrow database cost‑estimation techniques to verify whether the rewritten SQL yields better performance.
Practical Challenges
The three automatic discovery approaches face real‑world challenges such as high computational cost for exhaustive enumeration, complexity of equivalence verification, and the need to assess performance gains accurately.
Solutions Implemented
The first challenge is mitigated by enumerating only small rules and extrapolating larger ones, reducing compute waste.
Equivalence verification is achieved by converting SQL equivalence into linear‑algebra problems, enabling scalable and decidable checks; WeTune 2.0 supports verification of all SQL:1999 syntax.
Cost‑estimation validation and actual execution on database instances ensure that rewritten queries truly improve performance.
Performance Evaluation
In 2022, Wang’s team evaluated WeTune 1.0 on 20 open‑source applications covering e‑commerce, forums, etc., collecting over 8,500 SQL statements. WeTune 1.0 optimized approximately 674 statements, whereas other commercial databases optimized only 427, demonstrating a clear advantage.
Advantages of WeTune 2.0
Enhanced enumeration capability: faster and able to handle more complex rules.
Improved verification ability: supports a broader range of SQL features.
Human‑readable, loadable, and even hand‑writable rule language, eliminating the need for code compilation.
No‑code deployment: users can write rules directly, submit them via GaussDB interfaces, and see immediate effect.
Client‑side deployment option for isolated rule loading.
Impact on GaussDB
Integrating WeTune 2.0 into GaussDB introduces thousands of rewrite rules, which can increase optimization overhead. Efficient matching algorithms and scenario‑based rule classification are employed to mitigate performance impact.
Future Outlook
The collaboration between Huawei and academia will continue, fostering research on database query rewrite, enhancing automated testing via differential testing, and expanding educational applications where WeTune assists in grading database assignments.
Huawei Cloud Developer Alliance
The Huawei Cloud Developer Alliance creates a tech sharing platform for developers and partners, gathering Huawei Cloud product knowledge, event updates, expert talks, and more. Together we continuously innovate to build the cloud foundation of an intelligent world.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
