A Set-Theoretic Approach to Detecting Logic Bugs in DBMS Inner Join Optimizations
CLCe LyuChangzheng WeiYWYanhao WangJLJie LiangLi LinHanghang WuMinghao ZhaoYing YanAoying Zhou
CLCe Lyu
Changzheng Wei
YWYanhao Wang
JLJie Liang
Li Lin
Hanghang Wu
Minghao Zhao
Ying Yan
Aoying Zhou
+9
This paper introduces JoinEquiv, a metamorphic testing approach that detects logical bugs in INNER JOIN optimizations by treating each join as a set intersection. It generates semantically equivalent queries from a simple NATURAL/INNER JOIN using three set-theoretic transformation rules: symmetric join, asymmetric difference, and symmetric difference. Comparing the results of original and transformed queries exposes inconsistencies in DBMS query processing. JoinEquiv found 29 previously unknown issues in MySQL, TiDB, DuckDB, and Percona, with 27 confirmed, revealing deep logical flaws in optimizers and executors.

arXiv ·
· June 22, 2026