Yeah, seeing "sort" in the union-based plan also threw me for a moment about why that would be any faster. Normally sorts kill performance, especially compared to the merge join in the "ugly" version.
I think the key is in the description afterwards, where each subquery only returns 1 row. Which just reinforces: measure everything, this advice may not be generally applicable.
I think the key is in the description afterwards, where each subquery only returns 1 row. Which just reinforces: measure everything, this advice may not be generally applicable.