sql server query running slow from java

前端 未结 13 1930
渐次进展
渐次进展 2020-12-05 12:21

I have a java program that runs a bunch of queries against an sql server database. The first of these, which queries against a view returns about 750k records. I can run t

13条回答
  •  时光取名叫无心
    2020-12-05 12:54

    Sometimes it could be due to the way parameters are binding to the query object. I found the following code is very slow when executing from java program.

    Query query = em().createNativeQuery(queryString)                    
                    .setParameter("param", SomeEnum.DELETED.name())
    

    Once I remove the "deleted" parameter and directly append that "DELETED" string to the query, it became super fast. It may be due to that SQL server is expecting to have all the parameters bound to decide the optimized plan.

提交回复
热议问题