[英]Spring JdbcTemplate is extremely slow when call SQLserver Stored procedure
I'm using JdbcTemplate.execute() to call a SP connected with SQLServer database.我正在使用 JdbcTemplate.execute() 调用与 SQLServer 数据库连接的 SP。 With the same parameters, when I execute the SP directly in SQL Server Management Studio it finishes within 1s, but when I use JdbcTemplate in java it execute over minutes with causes severe performance issue.
使用相同的参数,当我直接在 SQL Server Management Studio 中执行 SP 时,它会在 1 秒内完成,但是当我在 Java 中使用 JdbcTemplate 时,它会执行几分钟,导致严重的性能问题。
Note the stored procedure contains "SET ANSI_NULLS ON" and "SET QUOTED_IDENTIFIER ON"注意存储过程包含“SET ANSI_NULLS ON”和“SET QUOTED_IDENTIFIER ON”
After some testing I finally find that the issue lies on blank values judgement in my SP:经过一些测试,我终于发现问题出在我的 SP 中的空白值判断上:
I have some default parameters for the SP and set them as @A nvarchar(255)='', then during the logic I need to use them as logic condition: if(@A is not null and rtrim(ltrim(@A)) <>'') Just that simple and it works totally good in the Management Studio.我有一些 SP 的默认参数并将它们设置为 @A nvarchar(255)='',然后在逻辑期间我需要将它们用作逻辑条件: if(@A is not null and rtrim(ltrim(@A) ) <>'') 就这么简单,它在 Management Studio 中运行良好。
After change that init to @A nvarchar(255) and use if(@A is not null), it also returns the results in JdbcTemplate... so there should be some inner logic for JdbcTemplate to do that empty check but I'm not sure why and how.将该 init 更改为 @A nvarchar(255) 并使用 if(@A is not null) 后,它还返回 JdbcTemplate 中的结果...所以 JdbcTemplate 应该有一些内部逻辑来执行空检查,但我是不知道为什么以及如何。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.