Home > database >  Complex queries, a SQL table more joint query or multiple SQL, recycled
Complex queries, a SQL table more joint query or multiple SQL, recycled

Time:09-20

For some complex logic, multiple conditions querying data, the conditional distribution in 2 ~ 4 tables, so usually in two ways:
1. Write a complex SQL, multi-table query associated, in the service layer code only need to use the SQL,
More than 2. Write a simple SQL, are generally single table query, write cycle, in the service layer code by using many times to get the data,
So, we should priority is in what way? What are their usage scenarios?

CodePudding user response:

Use the first way,

The second, basically there is no market,

CodePudding user response:

The amount of data, if the data is less, with the first way, data, with the second,

CodePudding user response:

If the application side don't do any processing, just simple loop, and then constantly invoke more simple SQL; Each network combined with SQL running back and forth time, data volume growth will lead to a sharp drop in performance,

Complex multi-table connection need to pay attention to the performance issue SQL statements, all kinds of indexes was set up,

Usually the first way will be more reliable, because you use a relational database, rather than no,

CodePudding user response:

Proposal 2
Is advantageous for the screening and subsequent problems, a complex SQL, is not recommended for general developer

If it is a development, follow-up without any changes, a proposal

CodePudding user response:

A proposal, more reliable, scheme 2 in code to do more operation call it is not recommended

CodePudding user response:

From the consideration on the performance, there is no doubt that option 1,
If the SQL is very complex, can consider to take apart into 2 ~ 3 SQL

The second solution is not recommended, unless the data volume is small, there is no performance problem

CodePudding user response:

Link performance is a big problem, you can refer to the "big master table performance optimization method of correlation" and "how to optimize performance of the JOIN these two articles
  • Related