The UNION
operator requires duplicate tuples (rows) be removed the result set before any rows are returned. That's effectively a SORT UNIQUE operation. That's relatively inexpensive for small result sets, but for massive sets, it can be resource intensive on the server time (i.e. take a long time.)
In theory, combining the queries with a UNION ALL
operator rather than a UNION
operator would be fastest, since it would eliminate (n-1) roundtrips to the database, vs running queries separately. But for large values of n, you are going to run into practical limits on the size of the SQL text (max packet size).
Given the choice between UNION
operator and separate queries, for a large result set, the separate queries are going to be less resource intensive on the server side.
In short, it's really a tradeoff between the heavy lifting for each query, vs. the heavy lifting of a SORT UNIQUE operation.