I write a CMS system for a publishing service in php/mysql.
On many of the pages I have several queries, usually more than 10. most of them even return the same result set though not all of them.
I wanted to ask if it is performance-wise to combine all those separate queries into 1 unioned query?
My logic tells me that accessing the database only once is faster than accessing it several times synchronisly, and that the accumulative query time of all queries will be the same as the query time of the union.
Am I right?
Of course there is a downgrade in the code - I have to select dummy nulls in several queries to comply with the entire union result set, but i can live with that if the improvement in response time is significant.