-
unknown authored
The problem was that store_top_level_join_columns() incorrectly assumed that the left/right neighbor of a nested join table reference can be only at the same level in the join tree. The fix checks if the current nested join table reference has no immediate left/right neighbor, and if so chooses the left/right neighbors of the nearest upper level, where these references are != NULL. mysql-test/r/group_min_max.result: Test for BUG#21007. mysql-test/t/group_min_max.test: Test for BUG#21007. sql/sql_base.cc: After computing and materializing the columns of all NATURAL joins in a FROM clause, the procedure store_top_level_join_columns() has to change the current natural join into a leaf table reference for name resolution. For this it needs to make the left neighbor point to the natural join table reference, and the natural join itself point to its left neighbor. This fix correctly determines the left/right neighbors of a table reference, even if the neghbors are at higher levels in the nested join tree. The rule is that if a table reference has no immediate left/right neighbors, we recursively pick the left/right neighbor of the level(s) above.
2ce5582a