0

默认情况下,我们的数据库服务器上有“SET NOCOUNT OFF”。我们使用“SET NOCOUNT ON”进行存储过程。正如 dba 所报告的,所有 nhibernate 生成的选择语句都使用“SET NOCOUNT OFF”。执行查询需要很长时间。我们正在尝试提高性能。我无法弄清楚为特定休眠会话或查询设置“SET NOCOUNT ON”的方法。有人可以对此发表一些意见。

问候

4

2 回答 2

1

I can't give you the option in nhibernate to set nocount off, however I know nhibernate is depending on the count to check if the query was succesfull. When you return the wrong count (0), nhibernate will think something is wrong and throws an excetion.

Besides that I do not think you will gain a lot from setting nocount off.

于 2013-07-09T14:25:54.257 回答
1

您可能误解了 SET NOCOUNT ON 的作用以及原因。

SET NOCOUNT 没有如此显着的影响,以至于它成为一个问题。在不返回数据的语句上将其设置为 ON只是一种优化。

另一方面,在查询中将其设置为 ON (您非常想知道返回了多少结果)是没有意义的。您的客户端不必快速检测有多少结果,而是必须枚举所有数据以查看返回了多少行。

您的服务器在任何情况下都会返回数据,因此告诉它不返回它返回的行数是没有意义的。

您可能还有其他性能问题。您应该检查执行了哪些查询,您的表是否具有正确的索引以及您是否强制 NHibernate 执行比您预期更多的查询(可怕的 N+1 问题)

于 2013-07-09T14:26:42.313 回答