Explaining Wrong Queries Using Small Examples
Not on the map. Why?
Abstract (arXiv)
For testing the correctness of SQL queries, e.g., evaluating student submissions in a database course, a standard practice is to execute the query in question on some test database instance and compare its result with that of the correct query. Given two queries Q1 and Q2, we say that a database instance D is a counterexample (for Q1 and Q2) if Q1(D) differs from Q2(D); such a counterexample can serve as an explanation of why Q1 and Q2 are not equivalent. While the test database instance may serve as a counterexample, it may be too large or complex to read and understand where the inequivalence comes from. Therefore, in this paper, given a known counterexample D for Q1 and Q2, we aim to find the smallest counterexample D' subseteq D where Q1(D') neq Q2(D'). The problem in general is NP-hard. We give a suite of algorithms for finding the smallest counterexample for different classes of queries, some more tractable than others. We also present an efficient provenance-based algorithm for SPJUD queries that uses a constraint solver, and extend it to more complex queries with aggregation, group-by, and nested queries. We perform extensive experiments indicating the effectiveness and scalability of our solution on student queries from an undergraduate database course and on queries from the TPC-H benchmark. We also report a user study from the course where we deployed our tool to help students with an assignment on relational algebra.
Key facts. Cited by 4 papers in the map (data through 7 Oct 2026). First posted on arXiv 9 Apr 2019.
Builds on
No reference list yet.
Built on by
Citing papers per year: 2022: 1; 2023: 0; 2024: 1; 2025: 1; 2026: 1.
4 papers.
- 2022Non-Programmers Can Label Programs Indirectly via Active Examples: A Case Study with Text-to-SQLcited by 12
- 2024Using LLM to select the right SQL Query from candidatescited by 12
- 2025Database Views as Explanations for Relational Deep Learningcited by 1
- 2026EXPO-SQL: Execution-based Clause-level Policy Optimization for Text-to-SQLcited by 1
- 2026EXPO-SQL: Execution-based Clause-level Policy Optimization for Text-to-SQL29 Apr 2026
- 2025Database Views as Explanations for Relational Deep Learning11 Sep 2025
- 2024Using LLM to select the right SQL Query from candidates4 Jan 2024
- 2022Non-Programmers Can Label Programs Indirectly via Active Examples: A Case Study with Text-to-SQL25 May 2022