2010-08-04 2 views
0

은 내가 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 

난을 정확히 똑같은 쿼리를 실행합니다. 저는 여기에 이렇게 붙여 넣었습니다. 매개 변수를 포함하여 쿼리가 적게 걸리는 모든 것을 포함합니다.

왜 이런 일이 일어나고 있는지 알 수는 없지만 성능이 현재로서는 간단하지 않습니다.

인사말.

+1

어떤 프로파일 러를 사용하고 있습니까? ADO.NET을 사용하여이 쿼리의 성능 테스트를 실행 했습니까? 문제가 발생한 곳에서 제공 한 정보로는 명확하지 않습니다. –

+0

거래와 관련이 있습니까? 아마도 Nhibernate에서 serializable과 같은 것을 사용하고 있습니까? – DanP

+0

프로파일 러는 SQL Server Profiler만을 사용하고 있습니다. 특별한 것은 없습니다. 이 쿼리에 대한 특정 성능 테스트를 실행하지 않았습니다. 두 번째 나는 SQL 관리 스튜디오에서 쿼리를 실행합니다. MSQL MS에서 질의는 적은 시간에 실행되지만 NHibernate에서는 느려집니다. NHibernate의 Serializable이 정확히 무엇인지 모르겠습니다. 아무 것도 업데이트되지 않았기 때문에이 쿼리가 트랜잭션 외부에서 실행된다는 것을 알고 있습니다. –

답변

1

있었 (나중에 값을 제거/변경해야합니다) 당신의 매핑을 확인 이 주제를 방문한 이후로 일부 쿼리를 수정하고 더 많은 인덱스를 추가했지만 더 중요한 것은 이제 더 강력한 서버에서 실행됩니다.

이 모든 난에 있던 문제가 스니핑 매개 변수 중 하나 믿고 말했다

http://www.simple-talk.com/sql/t-sql-programming/parameter-sniffing/

이어야가 해결되어 지금은이 문제 (들).

0

쿼리 자체가 범인입니까? 느린 쿼리의 실행이 아니라 맵핑 된 엔티티를 수화하는 과정, 특히 게으른로드를 비활성화 한 경우 콜렉션 및/또는 다 대일 연결 및 해당 콜렉션을 고려하는 것이 좋습니다.

먼저 열망 페치를 설정 한 경우, 그냥 가져 오는 열망 자동 제한하기 위해 NH의 설정에

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

을 설정하려고