How SQL Deletes a member's published N Records from millions records-sql retrieval efficiency issues

Source: Internet
Author: User
Tags rowcount

How SQL Deletes a member's published N Records from millions records-sql retrieval efficiency issues

Delete from table200 where mid=xxxxxxx timeout

If you use the SELECT * from table200 where mid=xxxxxxx is also timed out

But if you use the Select top table200 where mid=xxxxxxx will be retrieved quickly

Solution One

Delete Data is updated for all other indexes

So manually set the query timeout, you can use the following statement:
sp_configure ' show advanced options ', 1
Go
Reconfigure
Go
sp_configure ' query wait ', 2147483647
Go
Reconfigure
Go

Workaround Two

Now that the select top * from table200 where mid=xxxxxxx quickly, try
While 1=1
Begin
SET ROWCOUNT 100;
Delete from table200 where mid=xxxxxxx;
If @ @rowcount =0 break;
End

Method Three

Select Top * from table200 where mid=xxxxxxx 0.x~10

Method Four

SELECT * from table200 where mid=xxxxxxx first query 50 seconds before executing 30 seconds, 10 seconds and seconds.

For the first time, this data is not cached in memory and needs to be read from the hard disk, so it will be slow.
The second execution, the data has entered the memory, do not need to read from the hard disk, directly from the memory read, so quickly
?>

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.