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
?>