Sqlserver: Performance Diagnosis case: In the stored procedure, select the result set for the same table and then delete it, resulting in performance impact!

Source: Internet
Author: User

For example:

Create procedure test_proc

As

Begin

Set nocount on

Declare @ ID int

Select @ ID = ID from test_table where left (C1, 3) = 'xxx'

Select * From test_table where id = @ ID

Delete from test_table where id = @ ID

End

 

The data volume in the table is small. There are about a thousand entries, and the ID and C1 columns are indexed.

In this example, if you simply use the query analyzer to execute the task, you can view the execution plan without any exception.

However, for concurrent client execution, a problem occurs: the execution time of the stored procedure is long and long, but it is not a deadlock!

This is a problem encountered in actual production. after a long time of troubleshooting, the Select result set is saved to the temporary table by introducing a temporary table, finally, the temporary table result set is returned at the end of the stored procedure to solve the problem.

 

 

The internal mechanism of the Final Cause is unknown. continue to pay attention to it .............

 

 

 

 

 

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.