Today, the server suffered a CC attack, causing the website on IIS to hang, and the website was hung up again after restarting, check the website error log as follows:
System.Data.Entity.Core.EntityCommandExecutionException: 执行命令定义时出错。有关详细信息,请参阅内部异常。 ---> System.Data.SqlClient.SqlException: 执行超时已过期。完成操作之前已超时或服务器未响应。 ---> System.ComponentModel.Win32Exception: 等待的操作过时。
A large number of query timeout exceptions cause the website to hang, and the query timeout SQL statements all come from a method of taking random data, the code is as follows:
The code roughly means: 10 pieces of data are randomly selected from the database, as long as they do not duplicate the current ID.
What seems like a simple requirement has caused the server to hang up! The SQL statement generated by the above code is as follows:
The implementation plan is as follows:
If the database has 1 million pieces of data, wouldn't it take 999,999 pieces of data first, and then take 10 pieces of data from these 999,999 pieces of data?
Ask the big guy of the dba group and get the answer: "yesOh my God, that must be slow, and you need to call this sql statement many times.
At first I thought it was an EF problem,In fact, if you write directly in sql, there is no good solution。
If so, please teach me!
|