简体   繁体   English

特定查询可以直接运行良好,也可以进行任何更改,但在当前状态下运行时间更长

[英]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.

相关问题 查询在database(derby)中运行良好,但是在Java中执行时会引发异常 - Query runs fine in database(derby) ,but when executed in java, an exception is thrown 是否有特定的API可以验证PLAY STORE直接购买的付费应用的购买信息? - Is there any specific API to verify the purchase information of PAID APPS made directly by PLAY STORE? 当我在 VSCode 中运行时程序运行良好,但是 package maven 扩展构建不运行 - Program runs fine when I run in VSCode, but the package the maven extension builds doesn't run 使用 maven 运行时,测试套件挂起。 在 IDEA 中使用 Junit 运行配置运行良好 - Test suite hangs when run with maven. Runs fine with a Junit run configuration in IDEA 代码在IDE中可以正常运行,但不能作为Jar文件运行 - Code runs fine in IDE but not run as Jar file Scala无法运行编译的类,但直接运行它 - Scala fails to run compiled class, but runs it directly 运行应用程序时eclipse挂起(应用程序运行正常,eclipse是什么挂起) - eclipse hangs when run application (application runs fine, eclipse is what hangs) JavaFX应用程序在IntelliJ中运行Main时运行良好,内置jar无法运行 - JavaFX application runs fine when running Main in IntelliJ, built jar doesn't run Java Swing应用程序在正常模式下运行时挂起,但在调试模式下运行良好 - Java Swing app hangs when run in normal mode but runs fine in debug mode 查询在mysql和php中运行良好,但在Java中却没有 - query runs fine in mysql and php but not in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM