SQL Server Performance Tuning notes (i)----failure effect of a fool's machine

Source: Internet
Author: User
Tags join

Recently, the following project encountered an urgent problem, my old horse and young people to fight together. The problem is that many queries are incredibly slow when the pressure data is poured into the database.

Said there must be some basic guidelines for performance issues. The order of performance problems tunning

1 Architecture design (software architecture and database design, poor design is almost fatal)

2 Code defects (90% of performance problems)

3 Add index (this is to be determined according to the actual situation)

4 Resource tuning (cpu-> Memory->disk IO)

The network here is not a factor.

Take a look at the program's SQL, and some look at a bunch of subqueries composed of join, basically a glance can be judged, need to rewrite. We use the system to configure the SQL is dynamic, this design for the current tuning has brought convenience.

A very interesting phenomenon came up suddenly. One of the queries was slow (a minute later) and checked for SQL. This is the SQL text

SELECT ISNULL(a.CWB_NO,b.CWB_NO) AS CWB_NO,a.IMPORT_AWB_NO,
a.IMPORT_BWB_NO,ISNULL(a.PCS,0) AS RS2PCS,ISNULL(b.PCS,0) AS DECPCS,a.CCC_STATUS
FROM 
(SELECT * FROM  TB_CWB WHERE IMPORT_AWB_NO = @IMPORT_AWB_NO) a
FULL JOIN 
(SELECT * FROM  TP_DECSUMMARY WHERE AWB_NO = @IMPORT_AWB_NO) b
ON  a.CWB_NO = b.CWB_NO AND  b.AVAILABLE = 'Y'
WHERE  a.AVAILABLE = 'Y'

Full join is not the core of the problem (because business rules are like this) or select *, but there may be differences between the SELECT * and the specified field, but there is no big difference.

I ran in the background for a little less than 0 seconds. But another programmer says it takes 59 seconds to run the same. Strange!!!

Take it and compare it to find the difference.

Because, what our system takes is to use. NET in the designation of the parameters of CMD, converted to the background of SQL, equal to the method of running sp_executesql. To put it simply, it is a substitution variable.

That is, the equivalent of the SQL text should be

SELECT ISNULL(a.CWB_NO,b.CWB_NO) AS CWB_NO,a.IMPORT_AWB_NO,
a.IMPORT_BWB_NO,ISNULL(a.PCS,0) AS RS2PCS,ISNULL(b.PCS,0) AS DECPCS,a.CCC_STATUS
FROM 
(SELECT * FROM  TB_CWB WHERE  IMPORT_AWB_NO = '25200000011') a
FULL JOIN 
(SELECT * FROM  TP_DECSUMMARY WHERE AWB_NO ='25200000011') b
ON  a.CWB_NO = b.CWB_NO AND  b.AVAILABLE = 'Y'
WHERE a.AVAILABLE = 'Y'

Related Article

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.