Performance/efficiency of 2 SELECT statements vs UNION vs anything else in MySQL-PHP

旧城冷巷雨未停 提交于 2019-12-02 03:11:23

It totally depends on the environment and the way you are managing- I have to say- everything else. If the server is located on another network, on the other side of the planet, network is your bottleneck.
To make a better call I would make some assumptions: the server is on localhost, the connections are managed properly, and it is just the query itself that should be optimized. If that's the case for you, you could use Explain command the usage as explained here is very simple:

Explain select col1 from table1 Union select col2 from table2

There are tons of article out there explaining for you how to use Explain. here is one.

One last thing, it is not just the number of rows that matter. It is also important how many times your select code is being executed too. Assume you have a loop which returns 11 rows on each run and has 1000 iterations. Just assume that the rows are different in each iteration, then you will see the effect of your connection management and caching.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!