What is the weight of a subquery for the query?

4

During the development of some queries in the database, I come across the situation of the need to perform a new query, but another solution in some cases may be the subquery.

So what is the best solution to perform a second query or use subquery in such situations? What is the weight of a subquery for my query? Is it valid to the extent that you do not need to re-query the bank?

    
asked by anonymous 08.05.2014 / 15:37

1 answer

1

Between getting the result through a subquery or performing a second query, the subquery under normal conditions will be less expensive because it does not lead to the execution of the communication algorithms between client and > server . However, you must consider that for each row in the main query, the subquery will be executed; So you need to weigh if in fact you would do the same amount of queries in isolation.

The actual weight of a subquery depends on the algorithms of your SGDB and the modeling of your bank. This is an impossible answer to give without analyzing its structure.

My final advice is that, if possible, replace the subquerys with Joins. That will optimize performance, and in my experience, this is almost always possible (and do not forget the indexes).

    
09.05.2014 / 15:00