一句话:提出黑盒技术 CERT,通过构造更受限查询检测基数估计违例,从而发现 DBMS 性能问题。
数据库管理系统通过查询计划执行查询,但常因选择低效计划而出现性能问题;由于缺少期望执行时间的基准真值,这类问题长期难以发现。本文提出基数估计限制测试(CERT):给定数据库上的一个查询,CERT 派生出一个更受限的查询(例如把 LEFT JOIN 替换为 INNER JOIN),并断言其估计行数不应超过原查询的估计行数,从而检测基数估计中的违例。CERT 专门针对基数估计,因为它是查询优化中最重要的环节,修复其问题可能带来最大性能收益;同时作者发现其他类型的查询优化问题也可借由异常的估计基数暴露出来。CERT 是黑盒技术,无需源码,仅通过 EXPLAIN 语句获取查询计划,且不执行查询,避免了执行开销与性能波动。作者在 MySQL、TiDB 和 CockroachDB 三个成熟且广泛使用的 DBMS 上评估,共发现 13 个独特问题,其中 2 个已被修复、9 个被开发者确认。
Database Management Systems (DBMSs) process a given query by creating a query plan, which is subsequently executed, to compute the query's result. Deriving an efficient query plan is challenging, and both academia and industry have invested decades into researching query optimization. Despite this, DBMSs are prone to performance issues, where a DBMS produces an unexpectedly inefficient query plan that might lead to the slow execution of a query. Finding such issues is a longstanding problem and inherently difficult, because no ground truth information on an expected execution time exists. In this work, we propose Cardinality Estimation Restriction Testing (CERT), a novel technique that finds performance issues through the lens of cardinality estimation. Given a query on a database, CERT derives a more restrictive query (e.g., by replacing a LEFT JOIN with an INNER JOIN), whose estimated number of rows should not exceed the estimated number of rows for the original query. CERT tests cardinality estimation specifically, because it was shown to be the most important part for query optimization; thus, we expect that finding and fixing cardinality-estimation issues might result in the highest performance gains. In addition, we found that other kinds of query optimization issues can be exposed by unexpected estimated cardinalities, which can also be found by CERT. CERT is a black-box technique that does not require access to the source code; DBMSs expose query plans via the EXPLAIN statement. CERT eschews executing queries, which is costly and prone to performance fluctuations. We evaluated CERT on three widely used and mature DBMSs, MySQL, TiDB, and CockroachDB. CERT found 13 unique issues, of which 2 issues were fixed and 9 confirmed by the developers. We expect that this new angle on finding performance bugs will help DBMS developers in improving DMBSs' performance.