Page 1 of 1

MySQL UNION performance vs separate queries

Posted: Fri Aug 28, 2009 12:57 pm
by batfastad
Hi guys

On our intranet system I'm getting counts of related records from various tables... there's 8 record counts I need to get.
There's already 4 other queries on this particular page which get more specific information.
At the moment I'm using UNION to combine all these into a single query then lopping through those results in PHP and setting them to variable variables.

In theory what should give better performance:
8 individual queries from PHP?
Or just a single query with 8 statements joined by UNION?

I would think UNION should give slightly better performance because there'd be less overheard but I'm no expert... there's probably something with UNION that I'm missing.

Cheers, B

Re: MySQL UNION performance vs separate queries

Posted: Fri Aug 28, 2009 1:04 pm
by Eran
UNION should give better concurrency (since there's less overhead than 8 separate queries). It might give a small performance boost, but probably nothing significant