See https://www.reddit.com/r/ESECFSE/comments/jizgby/detecting_optimization_bugs_in_database_engines/.
Detecting Optimization Bugs in Database Engines viaNon-optimizing Reference Engine ConstructionManuel Rigger Zhendong SuETH Zurich, SwitzerlandESEC/FSE 2020@RiggerManuel @ast_eth https://people.inf.ethz.ch/suz/
View Slide
2Database Management Systems (DBMSs)PostgreSQL
3Database Management Systems (DBMSs)PostgreSQLSQLite is used in mobile phones,web browsers, OSs, TVs, …
4PostgreSQLDatabase Management Systems (DBMSs)We found 159 unique bugs in thesesystems, 141 of which have been fixed
5Optimization BugsCREATE TABLE t0(c0 UNIQUE);INSERT INTO t0 VALUES (-1) ;SELECT * FROM t0 WHERE t0.c0 GLOB '-*';c0-1t0{}Optimizerhttps://www.sqlite.org/src/tktview?name=0f0428096f
6Optimization BugsCREATE TABLE t0(c0 UNIQUE);INSERT INTO t0 VALUES (-1) ;SELECT * FROM t0 WHERE t0.c0 GLOB '-*';c0-1t0Optimizer-1✓https://www.sqlite.org/src/tktview?name=0f0428096f
7Non-optimizingReference EngineConstruction(NoREC)NoRECIdea: Rewrite the query so thatthe DBMS cannot optimize it
8NoRECSELECT * FROM t0WHERE t0.c0 GLOB '-*'; {}Optimizer
9SELECT t0.c0 GLOB '-*'FROM t0;NoRECSELECT * FROM t0WHERE t0.c0 GLOB '-*'; {}Optimizer
10SELECT t0.c0 GLOB '-*'FROM t0;NoRECSELECT * FROM t0WHERE t0.c0 GLOB '-*';TRUE{}OptimizerOptimizer
11SELECT t0.c0 GLOB '-*'FROM t0;NoRECSELECT * FROM t0WHERE t0.c0 GLOB '-*';TRUE{}Resultshouldcontainone rowOptimizerOptimizer
12SELECT t0.c0 GLOB '-*'FROM t0;NoRECSELECT * FROM t0WHERE t0.c0 GLOB '-*';TRUE{}Resultshouldcontainone rowOptimizerOptimizer
13Implementationhttps://github.com/sqlancer