一句话:提出查询计划引导(QPG),通过变异数据库状态使 DBMS 生成更多未见查询计划,从而发现数据库逻辑 bug。
数据库系统测试中,逻辑 bug 会导致查询结果错误,但自动生成能触发此类 bug 的测试用例仍具挑战。论文提出查询计划引导(QPG)概念:SQL 是声明式语言,DBMS 会将查询算子翻译为物理算子树(查询计划);通过变异数据库状态,逐步施加有希望的变异,使后续查询产生此前未见的查询计划,从而引导测试探索更多有趣行为。方法被实现为黑盒测试技术,应用于 SQLite、TiDB、CockroachDB 三个成熟系统,共发现 53 个此前未知的唯一 bug;相比朴素随机生成,探索的唯一查询计划多 4.85–408.48 倍,比代码覆盖率引导方法多 7.46 倍。作者认为 QPG 普适且可推广到测试套件质量度量等场景。
Database systems are widely used to store and query data. Test oracles have been proposed to find logic bugs in such systems, that is, bugs that cause the database system to compute an incorrect result. To realize a fully automated testing approach, such test oracles are paired with a test case generation technique; a test case refers to a database state and a query on which the test oracle can be applied. In this work, we propose the concept of Query Plan Guidance (QPG) for guiding automated testing towards “interesting” test cases. SQL and other query languages are declarative. Thus, to execute a query, the database system translates every operator in the source language to one of the potentially many so-called physical operators that can be executed; the tree of physical operators is referred to as the query plan. Our intuition is that by steering testing towards exploring a variety of unique query plans, we also explore more interesting behaviors-some of which are potentially incorrect. To this end, we propose a mutation technique that gradually applies promising mutations to the database state, causing the DBMS to create potentially unseen query plans for subsequent queries. We applied our method to three mature, widely-used, and extensively-tested database systems-SQLite, TiDB, and CockroachDB-and found 53 unique, previously unknown bugs. Our method exercises $4.85-408.48\times$ more unique query plans than a naive random generation method and $7.46\times$ more than a code coverage guidance method. Since most database systems-including commercial ones-expose query plans to the user, we consider QPG a generally applicable, black-box approach and believe that the core idea could also be applied in other contexts (e.g., to measure the quality of a test suite).