Table of Contents
Fetching ...

Qr-Hint: Actionable Hints Towards Correcting Wrong SQL Queries

Yihao Hu, Amir Gilad, Kristin Stephens-Martinez, Sudeepa Roy, Jun Yang

TL;DR

Qr-Hint tackles semantic debugging of SQL by delivering stagewise, repair-guided hints that transform a working query $Q$ into a semantically equivalent target $Q^\text{*}$. The framework decomposes the problem into FROM, WHERE, GROUP BY, HAVING, and SELECT stages, each secured by viability checks and repair bounds, and powered by SMT reasoning (Z3) and Boolean minimization (MinBoolExp). Key contributions include formalizing repair-site viability, a bound-pushing DeriveFixes procedure with an optional optimized variant, and mechanisms to ensure local optimality within each stage, plus experimental validation on real student data and TPCH with a user study. The results demonstrate that Qr-Hint can produce repairs that are optimal or near-optimal in practice and provide helpful guidance in educational settings, while acknowledging fundamental limits in SQL equivalence and some feature support. Overall, Qr-Hint offers a scalable, theory-grounded approach to automated, stepwise SQL feedback that can augment instructors and AI tutors alike.

Abstract

We describe a system called Qr-Hint that, given a (correct) target query Q* and a (wrong) working query Q, both expressed in SQL, provides actionable hints for the user to fix the working query so that it becomes semantically equivalent to the target. It is particularly useful in an educational setting, where novices can receive help from Qr-Hint without requiring extensive personal tutoring. Since there are many different ways to write a correct query, we do not want to base our hints completely on how Q* is written; instead, starting with the user's own working query, Qr-Hint purposefully guides the user through a sequence of steps that provably lead to a correct query, which will be equivalent to Q* but may still "look" quite different from it. Ideally, we would like Qr-Hint's hints to lead to the "smallest" possible corrections to Q. However, optimality is not always achievable in this case due to some foundational hurdles such as the undecidability of SQL query equivalence and the complexity of logic minimization. Nonetheless, by carefully decomposing and formulating the problems and developing principled solutions, we are able to provide provably correct and locally optimal hints through Qr-Hint. We show the effectiveness of Qr-Hint through quality and performance experiments as well as a user study in an educational setting.

Qr-Hint: Actionable Hints Towards Correcting Wrong SQL Queries

TL;DR

Qr-Hint tackles semantic debugging of SQL by delivering stagewise, repair-guided hints that transform a working query into a semantically equivalent target . The framework decomposes the problem into FROM, WHERE, GROUP BY, HAVING, and SELECT stages, each secured by viability checks and repair bounds, and powered by SMT reasoning (Z3) and Boolean minimization (MinBoolExp). Key contributions include formalizing repair-site viability, a bound-pushing DeriveFixes procedure with an optional optimized variant, and mechanisms to ensure local optimality within each stage, plus experimental validation on real student data and TPCH with a user study. The results demonstrate that Qr-Hint can produce repairs that are optimal or near-optimal in practice and provide helpful guidance in educational settings, while acknowledging fundamental limits in SQL equivalence and some feature support. Overall, Qr-Hint offers a scalable, theory-grounded approach to automated, stepwise SQL feedback that can augment instructors and AI tutors alike.

Abstract

We describe a system called Qr-Hint that, given a (correct) target query Q* and a (wrong) working query Q, both expressed in SQL, provides actionable hints for the user to fix the working query so that it becomes semantically equivalent to the target. It is particularly useful in an educational setting, where novices can receive help from Qr-Hint without requiring extensive personal tutoring. Since there are many different ways to write a correct query, we do not want to base our hints completely on how Q* is written; instead, starting with the user's own working query, Qr-Hint purposefully guides the user through a sequence of steps that provably lead to a correct query, which will be equivalent to Q* but may still "look" quite different from it. Ideally, we would like Qr-Hint's hints to lead to the "smallest" possible corrections to Q. However, optimality is not always achievable in this case due to some foundational hurdles such as the undecidability of SQL query equivalence and the complexity of logic minimization. Nonetheless, by carefully decomposing and formulating the problems and developing principled solutions, we are able to provide provably correct and locally optimal hints through Qr-Hint. We show the effectiveness of Qr-Hint through quality and performance experiments as well as a user study in an educational setting.
Paper Structure (36 sections, 11 theorems, 12 equations, 12 figures, 5 tables)

This paper contains 36 sections, 11 theorems, 12 equations, 12 figures, 5 tables.

Key Result

theorem 1

Let $Q_0 = Q$ denote the initial working query and $Q^\star$ denote the target query. Let $V_i$ denote the viability check for stage $i$, and $Q_i$ denote the working query upon clearing stage $i$, where $Q_i$ satisfies $V_1, V_2, \ldots, V_i$. We say that two queries are stage-$i$ consistent if the

Figures (12)

  • Figure 1: Syntax trees for $P^\star$ and $P$ in Example \ref{['ex:syntax-tree']}.
  • Figure 2: $\text{[1.0]{DeriveFixes}}$ vs. $\text{[1.0]{DeriveFixesOPT}}$ (Optimized) for conjunctive WHERE (TPCH)
  • Figure 3: $\text{[1.0]{DeriveFixes}}$ vs. $\text{[1.0]{DeriveFixesOPT}}$ (Optimized) for nested AND/OR (TPCH)
  • Figure 4: Cost of repairs found during course of execution
  • Figure 5: User performance with/without Qr-Hint
  • ...and 7 more figures

Theorems & Definitions (31)

  • Example 1
  • Example 2
  • Example 3
  • theorem 1
  • lemma 1
  • lemma 2
  • Definition 1
  • Example 4
  • Example 5
  • Definition 2: Repair for SQL Predicate
  • ...and 21 more