What are the advantages and disadvantages of data Association and direct use of association query in applications?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.