用小例子解释错误
Explaining Wrong Queries Using Small Examples
摘要:
用于测试SQL查询的正确性,例如,在数据库课程中评估学生提交的内容时,标准做法是在一些测试数据库实例上执行有问题的查询,并将其结果与正确查询的结果进行比较。给定两个查询$Q_1$和$Q_2$,如果$Q_1(D)$与$Q_2(D)$不同,我们说数据库实例$D$是一个反例(对于$Q_1$和$Q_2$);这样的反例可以解释为什么$Q_1$和$Q_2$不等价。虽然测试数据库实例可以用作反例,但它可能太大或太复杂,无法阅读和理解不等价性的来源。因此,在本文中,给定一个已知的反例$D$为$Q_1$和$Q_2$,我们的目标是找到最小的反例$D' \subseteq D$其中$Q_1(D') \neq Q_2(D')$。这个问题一般是NP难的。我们给出了一套算法,找到最小的反例为不同类别的查询,一些更听话的比别人。我们还提出了一个有效的基于出处的算法SPJUD查询,使用约束求解器,并将其扩展到更复杂的查询与聚合,分组和嵌套查询。我们进行了大量的实验,表明我们的解决方案的有效性和可扩展性,从本科数据库课程的学生查询和查询TPC-H基准。我们还报告了一个用户研究,从课程中,我们部署我们的工具,以帮助学生与关系代数的作业。
英文摘要:
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 $Q_1$ and $Q_2$, we say that a database instance $D$ is a counterexample (for $Q_1$ and $Q_2$) if $Q_1(D)$ differs from $Q_2(D)$; such a counterexample can serve as an explanation of why $Q_1$ and $Q_2$ 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 $Q_1$ and $Q_2$, we aim to find the smallest counterexample $D' \subseteq D$ where $Q_1(D') \neq Q_2(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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。