Optimizing UNION
UNION has an interesting optimization that exists across a few different databases. It's obvious when you think about how it works. UNION gives you the rows from two tables that don't exist in the other. So implicitly, you are removing duplicates. To do this the MySQL database must return distinct rows, and thus must sort the data. Sorting, as we know is expensive, especially for large tables.UNION has an interesting optim