一句话:提出 NoREC,将查询重写为不可优化形式以构造非优化参考引擎,差分检测数据库优化缺陷。
数据库管理系统依赖复杂优化来高效访问数据,但错误优化会产生逻辑 bug,使查询返回错误结果集。为此,论文提出 NoREC 全自动方法:将任意(可随机生成)的优化查询重写为 DBMS 无法优化的等价查询,以此模拟非优化参考引擎,并比较优化版本与非优化版本返回结果集的差异来检测 bug。作者在 PostgreSQL、MariaDB、SQLite 和 CockroachDB 四个广泛使用的 DBMS 上开展大规模测试,共发现 159 个此前未知的 bug,其中 141 个已被开发者修复;51 个属于优化 bug,其余为错误和崩溃 bug。结果表明 NoREC 有效、通用且实现成本低。
Database Management Systems (DBMS) are used ubiquitously. To efficiently access data, they apply sophisticated optimizations. Incorrect optimizations can result in logic bugs, which cause a query to compute an incorrect result set. We propose Non-Optimizing Reference Engine Construction (NoREC), a fully-automatic approach to detect optimization bugs in DBMS. Conceptually, this approach aims to evaluate a query by an optimizing and a non-optimizing version of a DBMS, to then detect differences in their returned result set, which would indicate a bug in the DBMS. Obtaining a non-optimizing version of a DBMS is challenging, because DBMS typically provide limited control over optimizations. Our core insight is that a given, potentially randomly-generated optimized query can be rewritten to one that the DBMS cannot optimize. Evaluating this unoptimized query effectively corresponds to a non-optimizing reference engine executing the original query. We evaluated NoREC in an extensive testing campaign on four widely-used DBMS, namely PostgreSQL, MariaDB, SQLite, and CockroachDB. We found 159 previously unknown bugs in the latest versions of these systems, 141 of which have been fixed by the developers. Of these, 51 were optimization bugs, while the remaining were error and crash bugs. Our results suggest that NoREC is effective, general and requires little implementation effort, which makes the technique widely applicable in practice.