In last couple of weeks there has been a tide of ORDER/GROUP BY-related optimization bugs, where I was the fixer or the reviewer. This wasn’t an easy job because there is no sane description of how GROUP BY/ORDER BY handling is supposed to work. To figure it out, I had to write an explanation of how it works. The first part is about ORDER BY. Hopefully there will be subsequent parts that will show
![How MySQL executes ORDER BY](https://cdn-ak-scissors.b.st-hatena.com/image/square/dd516161ef9c0fe9462956a1def13a3aa115f471/height=288;version=1;width=512/https%3A%2F%2Fsergeipetrunia.files.wordpress.com%2F2020%2F11%2F0bdb4-nl-join-order-last-tbl.png)