[英]Specific Query runs fine directly or when any change to it is made but in current state takes longer to run
Major Update after a couple days of debugging: 经过几天调试后的主要更新:
I run a few queries similar to : 我运行一些类似的查询:
SELECT RTRIM(part) as part
FROM tableP pm
LEFT join tableS s on pm.id = s.id
INNER JOIN tableC cm ON cm.id = pm.id
WHERE name = 'NGW' AND status NOT IN ('NL', 'Z')
GROUP BY RTRIM(part), isnull(s.value,0)
ORDER BY isnull(s.value,0)
It is run in Java like so: 它以如下方式在Java中运行:
PreparedStatement select = con.prepareStatement(
"SELECT RTRIM(part) as part" +
"FROM tableP pm " +
"LEFT JOIN tableS s ON pm.id= s.id " +
"INNER JOIN tableC cm ON cm.id= pm.id " +
"WHERE name =? AND status NOT IN ('NL', 'Z') " +
"GROUP BY RTRIM(part), isnull(s.value,0) " +
"ORDER BY isnull(s.value,0) " );
select.setString(1, name);
ResultSet rs = select.executeQuery();
while(rs.next()){
... Data is Loaded...
The queries have been running fine inside of a Java application. 查询在Java应用程序内部运行良好。 Suddenly 3 or 4 queries of this form went from taking less then a second to over a minute.
突然,这种形式的3或4个查询从不到一秒钟的时间变成了超过一分钟的时间。
I have copied the exact query from SQL Profiler and when run directly on the database it preforms in less then a second. 我已经从SQL Profiler复制了确切的查询,当直接在数据库上运行时,它会在不到一秒钟的时间内完成。 I started to make changes to the query and found any change to the query would return it to 1 second performance even adding a single space between a statement.
我开始对查询进行更改,发现对查询的任何更改都会使它返回1秒性能, 即使在语句之间添加单个空格也是如此。 But as soon as I returned it to its original exact state it would take 60+ seconds.
但是,一旦我将其恢复为原始准确状态,将需要60秒钟以上的时间。
Core Question: So, I have a fix, but what could cause a query to run differently even with just a change as small as whitespace? 核心问题:因此,我有一个解决方法,但是即使是很小的更改,是什么导致查询以不同的方式运行呢?
Is it possible that the execution plan is corrupted? 执行计划是否可能已损坏? Can you try explicitly clearing the plan cache?
您可以尝试明确清除计划缓存吗? http://msdn.microsoft.com/en-us/library/aa175244(v=sql.80).aspx
http://msdn.microsoft.com/en-us/library/aa175244(v=sql.80).aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.