Databases
Set-Theoretic Testing Uncovers 29 Logic Bugs in DBMS Join Optimizers
Researchers use metamorphic testing based on set operations to detect previously unknown logical errors in mainstream database systems including MySQL, TiDB, and DuckDB.
Researchers have developed a novel approach to detecting logical bugs in database management systems' query optimizers—specifically targeting errors in inner join optimization that cause incorrect query results.
The problem is significant: while existing fuzzing tools have been effective at finding crash and performance-related bugs, they struggle to identify logical bugs where systems return wrong answers. This gap leaves production databases vulnerable to silent data integrity issues.
The Set-Theoretic Solution#
The team proposes a metamorphic testing approach grounded in set theory. Their method generates semantically equivalent queries using three transformation rules:
- Symmetric join transformation - rewrites joins while preserving semantics
- Asymmetric difference transformation - applies set difference operations
- Symmetric difference transformation - combines symmetric properties
These rules transform simple NATURAL/INNER JOIN queries into more complex, mathematically equivalent forms. By comparing results between original and transformed queries, the system acts as a testing oracle to detect inconsistencies.
Real-World Impact#
The researchers implemented this design in JoinEquiv and tested it against major databases:
- MySQL - multiple issues uncovered
- TiDB - logical inconsistencies detected
- DuckDB - bugs confirmed
- Percona - flaws identified
Across all platforms, they discovered 29 previously unknown issues, with 27 officially confirmed by the respective development teams. The bugs reveal "deep logical flaws" in DBMS optimizers and executors.
The work underscores how formal methods rooted in mathematics can expose subtle database correctness problems that traditional fuzzing misses.

