What are the advantages and disadvantages of associating data in an application (that is, executing multiple queries and associating the results) and directly using associated queries? In what scenarios can these two methods achieve better performance? What are the advantages and disadvantages of associating data in an application (that is, executing multiple queries and associating the results) and directly using associated queries?
In what scenarios can these two methods achieve better performance?
Reply content:
What are the advantages and disadvantages of associating data in an application (that is, executing multiple queries and associating the results) and directly using associated queries?
In what scenarios can these two methods achieve better performance?
In general, direct join queries are used, because this is not unnecessary. If you want to reduce the efficiency of associated queries, you need to do a lot of extra work, which is simply a variety of caches.
The simplest example: Order. StuatsId is associated with OrderStatus. Id.
To display the order status
Method 1: join query
Method 2: OrderStatus is cached, and Helper of the getStatusTitleById method is provided to the foreground to avoid association.
Therefore, projects with low concurrency pressure do not need to pay too much attention to this, and there is almost no impact. projects with high concurrency pressure will specifically treat this as a long-term task.
Conclusion: generally, the performance loss caused by association queries is imperceptible to visitors, but too many associations must be avoided (for example, only two tables are required, the actually queried SQL statement is associated with five tables)
From the perspective of efficiency, the efficiency of associated queries must be higher.
From the code readability point of view, it should be separated to make the code more readable. And can be reused.
The specific selection depends on the size of your project.