Nhibernate 查询性能波动

Nhibernate 查询性能波动,nhibernate,Nhibernate,我正在运行来自NHibernate的查询,并将我的探查器设置为跟踪任何缓慢的查询,在我的探查器中有一些似乎需要10秒以上的时间: exec sp_executesql N'SELECT top 50 this_.Debiteur_ID as Debiteur1_44_6_, this_.Debiteurnaam as Debiteur2_44_6_, this_.Debiteurnummer as Debiteur3_44_6_, this_.IsBedrijf_NeeJa as IsBedr

我正在运行来自NHibernate的查询,并将我的探查器设置为跟踪任何缓慢的查询,在我的探查器中有一些似乎需要10秒以上的时间:

exec sp_executesql N'SELECT top 50 this_.Debiteur_ID as Debiteur1_44_6_, this_.Debiteurnaam as Debiteur2_44_6_, this_.Debiteurnummer as Debiteur3_44_6_, this_.IsBedrijf_NeeJa as 
IsBedrijf4_44_6_, this_.Bedrijfsnaam as Bedrijfs5_44_6_, this_.Achternaam as Achternaam44_6_, this_.Tussenvoegsel as Tussenvo7_44_6_, this_.Voorletters as Voorlett8_44_6_, 
this_.Geboortedatum as Geboorte9_44_6_, this_.Titel_ID as Titel10_44_6_, this_.ManVrouw as ManVrouw44_6_, this_.Entiteit_ID as Entiteit12_44_6_, this_.Rechtsvorm_ID as Rechtsvorm13_44_6_, 
this_.Account_ID as Account14_44_6_, this_.Vestiging_Postcode as Vestiging15_44_6_, this_.Vestiging_Adres as Vestiging16_44_6_, this_.Vestiging_Plaats as Vestiging17_44_6_, 
this_.Vestiging_Huisnummer as Vestiging18_44_6_, this_.Vestiging_Land_ID as Vestiging19_44_6_, this_.Correspondentie_Postcode as Corresp20_44_6_, this_.Correspondentie_Adres as 
Corresp21_44_6_, this_.Correspondentie_Plaats as Corresp22_44_6_, this_.Correspondentie_Huisnummer as Corresp23_44_6_, this_.Correspondentie_Land_ID as Corresp24_44_6_, this_.Telefoonnummer as Telefoo25_44_6_, this_.Email as Email44_6_, this_.Mobiel as Mobiel44_6_, title3_.Titel_ID as Titel1_65_0_, title3_.Omschrijving as Omschrij2_65_0_, gender4_.Geslacht_ID as Geslacht1_30_1_, gender4_.Omschrijving as Omschrij2_30_1_, typeofcomp5_.Rechtsvorm_ID as Rechtsvorm1_8_2_, typeofcomp5_.Omschrijving as Omschrij2_8_2_, country6_.Land_ID as Land1_7_3_, country6_.Omschrijving as Omschrij2_7_3_, country6_.ISO as ISO7_3_, country6_.ISO_3166_a3 as ISO4_7_3_, country7_.Land_ID as Land1_7_4_, country7_.Omschrijving as Omschrij2_7_4_, country7_.ISO as ISO7_4_, country7_.ISO_3166_a3 as ISO4_7_4_, debtorreac1_.Debiteur_ID as Debiteur1_3_5_, debtorreac1_.DateOfOldestReaction as DateOfOl2_3_5_, debtorreac1_.TotalAmountOfReactions as TotalAmo3_3_5_, debtorreac1_.AmountOfResolvedReactions as AmountOf4_3_5_, debtorreac1_.AmountOfUnresolvedReactions as AmountOf5_3_5_, debtorreac1_.TotalOpenAmount as TotalOpe6_3_5_, debtorreac1_.UnresolvedOpenAmount as Unresolv7_3_5_, debtorreac1_.ResolvedOpenAmount as Resolved8_3_5_ FROM tbl_Debiteur this_ left outer join tbl_Titel title3_ on this_.Titel_ID=title3_.Titel_ID left outer join tbl_Geslacht gender4_ on this_.ManVrouw=gender4_.Geslacht_ID left outer join tbl_Rechtsvorm typeofcomp5_ on this_.Rechtsvorm_ID=typeofcomp5_.Rechtsvorm_ID left outer join tbl_Land country6_ on this_.Vestiging_Land_ID=country6_.Land_ID left outer join tbl_Land country7_ on this_.Correspondentie_Land_ID=country7_.Land_ID left outer join vw_DebtorReactionDetails debtorreac1_ on this_.Debiteur_ID=debtorreac1_.Debiteur_ID WHERE this_.Entiteit_ID = @p0 and debtorreac1_.AmountOfUnresolvedReactions > @p1 ORDER BY this_.Debiteur_ID asc',N'@p0 int,@p1 int',@p0=1104,@p1=0
当我运行完全相同的查询时,我只是像这样粘贴在这里,因此包括参数和查询所需的所有内容不到一秒钟

我不知道为什么会发生这种情况,但目前的表现根本不起作用


问候。

您确定查询本身就是罪魁祸首吗? 我很确定,不是查询的执行速度慢,而是相应映射实体的水合过程,特别是在禁用延迟加载时考虑集合和/或多对一关联及其集合

首先检查映射,如果您已设置了即时抓取, 尝试设置

<property name="max_fetch_depth">1</property>
1

在您的NH配置中,只是为了限制自动即时抓取(请记住在之后删除/更改值)

自从我访问本主题以来,我们对查询进行了一些调整,添加了一些索引,但更重要的是,现在在功能更强大的服务器上运行

这一切都表明我相信我遇到的问题是参数嗅探:


至少目前问题已解决。

您使用的是什么探查器?您是否使用ADO.NET对此查询运行了性能测试?从您提供的信息来看,问题出在哪里并不清楚。这可能与交易有关吗?也许您在Nhibernate中使用了类似serializable的东西?我使用的探查器只是SQL Server探查器,没有什么特别之处。我没有对此查询运行特定的性能测试。我第二次运行查询是在SQL Management studio中。在MSQL MS中,查询运行不到一秒钟,但从NHibernate开始,运行速度非常慢。我不确定NHibernate中可序列化的内容到底是什么。我知道这个查询是在事务之外运行的,因为没有任何内容被更新。