Our exprience in solving query optimizer problems shows that a good chunk of optimization problems are incorrect choice of join order. The most frequent causes of the problems are
- Table engine returns index statistics or records-in-range numbers that are very far from reality;
- The WHERE clause has high-selectivity conditions for one table and low-selectivity conditions for the other. The optimizer is not aware of this and chooses a poor join order;
- Bugs or shortcomings in the optimizer or the table engine;
At the moment investigation of those kinds of problems is hard and time-consuming:
- There is no easy way to find out what the storage engine has returned to the optimizer from records-in-range calls. One has to manually repeat the steps taken by equality propagation, constant table detection and other query rewrites, construct the table's condition and run the …