Home > database >  Urgent, low efficiency, who can see how to optimize?
Urgent, low efficiency, who can see how to optimize?

Time:09-28

A the main table, will link many child table, the main table to store the primary key of the communications department ID, only now these fields need to related queries, and displayed,


Generally in order to facilitate to be such a query, for example:
SELECT the main table. COLUM_A
And the main table. COLUM_B
Associated, (SELECT TOP 1 table 1. COLUM_A FROM relational table 1 WHERE the primary key=foreign key... ) AS a new field 1
Associated, SELECT the TOP 1 in table 2. COLUM_A FROM relational table 2 WHERE primary key=foreign key... ) AS the new fields 2
Associated, (SELECT TOP 1 table 3. COLUM_A FROM relational table 2 WHERE the primary key=foreign key... 3) AS the new fields
.
FROM the main table

.




What is the other queries found speed is slow, so replaced or optimization method?

CodePudding user response:

Is there such a query according to
SELECT the main table. COLUM_A
And the main table. COLUM_B
Associated, (SELECT TOP 1 table 1. COLUM_A, associative table 1. COLUM_B,... The FROM relational table 1 WHERE the primary key=foreign key... )
FROM the main table

CodePudding user response:

You can use in the query analyzer "shows the estimated implementation plan" to analyze, where time is spent on,
Frequently, a kind of illusion: we think should be optimized, but should not do,

CodePudding user response:

Query condition field and index