SQL Server Performance Tuning notes (iv)

Source: Internet
Author: User

When the system is finished, performance problems are often an important issue in warranty and later maintenance.

These days, the customer has to reflect that there is a very slow query. This query uses a primary key query, because the primary key is a clustered index and is fragmented. should be very fast. But the phenomenon of seeing is very slow (10 seconds or so, the worst is more than 18 seconds). Eliminates the problem of hardware, resource locking, etc., and does not have to reach the tunning level at the database end. The basic judgments are related to SQL, and you want to look at the execution plan for the SQL text.

First, find the SQL.

SELECT A.awb_no,
A.bwb_no,
A.cwb_no,
A.origin,
A.dest,
A.MODIFY_ON,
A.CREATED_ON,
A.consignor_customer_code,
A.consignor_code,
A.consignor_name,
A.consignee_name,
A.cwb_status,
A.cwb_type,
ISNULL (a.pcs, 0) as PCS,
A.bwblist,
B.pweight
From TB_CWB as a
Left JOIN Tb_cwbweight as B
On a.cwb_no = B.cwb_no
and b.available = ' Y '
WHERE a.available = ' Y '
and (A.cwb_no = @CWB_NO OR
((@CWB_NO is NULL)
and (A.awb_no = @AWB_NO OR @AWB_NO is NULL)
and (A.bwb_no = @BWB_NO OR @BWB_NO is NULL)
and (A.ie_type = @IE_TYPE OR @IE_TYPE is NULL)
and (a.created_on >= @DateFrom OR @DateFrom is NULL)
and (a.created_on <= @DateTo OR @DateTo is NULL)
and (a.payment = @PAYMENT OR @PAYMENT is NULL)
and (A.origin = @ORIGIN OR @ORIGIN is NULL)
and (a.dest = @DEST OR @DEST is NULL)
and (A.consignor_customer_code = @CONSIGNOR_CUSTOMER_CODE OR @CONSIGNOR_CUSTOMER_CODE is NULL)
and (A.consignor_name like '% ' + @CONSIGNOR_NAME + '% ' OR @CONSIGNOR_NAME is NULL)
and (A.consignee_name like '% ' + @CONSIGNEE_NAME + '% ' OR @CONSIGNEE_NAME is NULL)
and (A.cwb_type = @CWB_TYPE OR @CWB_TYPE is NULL))

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.