2012-04-30 5 views
0

에서 실행 계획 XML을 최적화 할 수 있습니다. 그러나 쿼리가 처음 실행될 때 프로파일 러에 따라 ShowPlanXML 이벤트는 약 14 초 (만족스럽지 않습니다) 걸립니다.내가 한 번 SQL 서버를 실행하기 위해 초 정도 소요됩니다 상당히 복잡한 쿼리 (만족) 쿼리 계획을 설립했다가 SQL 서버

처음으로 그것이 더 빨리 완료 실행되도록 ShowPlanXML을 최적화 할 수있는 방법이 있나요?

또는 내가 계획 지침을 작성해야 할 것입니까?

SELECT top 20 this_.UserId as UserId55_0_, this_.User_Version as User2_55_0_, this_.User_ApplicationId as User3_55_0_, this_.User_DeletedOn as User4_55_0_, this_.User_CreatedOn as User5_55_0_, this_.User_ModifiedOn as User6_55_0_, this_.User_CreatedById as User7_55_0_, this_.User_CreatedByName as User8_55_0_, this_.User_ModifiedById as User9_55_0_, this_.User_ModifiedByName as User10_55_0_, this_.User_Name as User11_55_0_, this_.User_ExternalId as User12_55_0_, this_.User_DynamicFields as User13_55_0_, 
this_.User_FirstName as User14_55_0_, this_.User_LastName as User15_55_0_, this_.User_Prefix as User16_55_0_, this_.User_Gender as User17_55_0_, this_.User_Language as 
User18_55_0_, this_.User_Code as User19_55_0_, this_.User_Nationality as User20_55_0_, this_.User_FirstLanguage as User21_55_0_, this_.User_DrivingLicence as User22_55_0_, 
this_.User_Category as User23_55_0_, this_.User_UserStatus as User24_55_0_, this_.User_UserType as User25_55_0_, this_.User_WorkPhone as User26_55_0_, this_.User_MobilePhone as 
User27_55_0_, this_.User_Fax as User28_55_0_, this_.User_Mail as User29_55_0_, this_.User_Login as User30_55_0_, this_.User_Password as User31_55_0_, this_.User_BornOn as 
User32_55_0_, this_.User_StartedOn as User33_55_0_, this_.User_FinishedOn as User34_55_0_, this_.User_Address as User35_55_0_, this_.User_PostalCode as User36_55_0_, 
this_.User_City as User37_55_0_, this_.User_Country as User38_55_0_, this_.User_PositionTitle as User39_55_0_, this_.User_Comments as User40_55_0_, this_.User_OptionalField1 as 
User41_55_0_, this_.User_OptionalField2 as User42_55_0_, this_.User_OptionalField3 as User43_55_0_, this_.User_PasswordConsecutiveFailedAttempts as User44_55_0_, 
this_.User_PasswordModificationDate as User45_55_0_, this_.User_WrongPasswordAttemptDate as User46_55_0_, this_.User_PictureUrl as User47_55_0_, this_.User_PasswordModificationStatus as User48_55_0_, this_.User_SecretQuestionConsecutiveFailedAttempts as User49_55_0_, this_.User_PlatformMailTransfer as User50_55_0_, this_.User_TimeZoneId as User51_55_0_, this_.User_ConnectionState as User52_55_0_, this_.User_LastConnectionId as User53_55_0_, this_.User_TotalPercentRealized as User54_55_0_ 
FROM Dir_User this_ 
WHERE this_.UserId in (
     SELECT distinct this_0_.UserId as y0_ 
     FROM Dir_User this_0_ inner join Dir_UserDynamicGroup dynamicgro3_ on this_0_.UserId=dynamicgro3_.UsDy_UserId 
     inner join Dir_Group dynamicgro1_ on dynamicgro3_.UsDy_DynamicGroupId=dynamicgro1_.GroupId 
     WHERE dynamicgro1_.GroupId = (51904517) 
     and this_0_.User_ApplicationId = 65536 
     and this_0_.User_DeletedOn is null 
     and this_0_.UserId in (
      SELECT distinct this_0_0_.TargetUserId as y0_ 
      FROM Dir_UserGroupMember this_0_0_ 
      WHERE this_0_0_.OwnerUserId = 7341195 
      and ((this_0_0_.Scope & 139280) != 0 or ((this_0_0_.Scope & 139280) != 0 
      and this_0_0_.GroupId = this_0_0_.SubGroupId)))) 
      ORDER BY this_.User_Name asc 
+0

당신은 쿼리가 컴파일에 의한 실행 또는 처음 실행할 긴 것을 그대로 실행 계획이 그렇게 오래 걸리는 것을 걸리는 건가요? 후자의 경우, 나는 그것에 대해 걱정하지 말라. 응용 프로그램에서 쿼리를 실행하지 않고 실행 계획 결과를 다시 가져 오지 않습니다. 튜닝 및 문제 해결만을위한 진단 도구입니다. –

+0

이것은 이전입니다. 프로파일 러에 따르면 ShowPlanXml 이벤트는 쿼리가 SSMS에서 실행될 때마다 실행됩니다. 처음으로 컴파일하는 데 14 초가 걸리며, 그 다음부터 계획은 캐시에서 액세스됩니다. DBCC DROPCLEANBUFFERS를 실행하면 캐시가 지워지고 계획은 14 초가 지나면 다시 계산됩니다. –

+0

이 (http://msdn.microsoft.com/en-us/library/ms188661.aspx)에 따르면 해당 이벤트는 쿼리가 실행되고 "이 이벤트 클래스를 포함하는 흔적이 심각한 성능 오버 헤드를 초래할 수 있습니다." 쿼리의 성능을 살펴 보려면 sys.dm_exec_query_stats 및 해당 형제 대신 DMV를 살펴 보시기 바랍니다. –

답변

1

이 쇼-계획 프로파일 이벤트 (sqlserver.query_post_execution_showplan Performance Impact 참조) SQL 서버의 성능에 상당한 영향을 미칠 수 있습니다 : 여기 정보에 대한

은 (NHibernate에 의해 생성된다) SQL 쿼리입니다. 저장 프로 시저를 컴파일하는 데 걸리는 시간을 정확히 나타내려면 다른 방법을 사용해야합니다. , Identifying High Compile Time Statements from the Plan Cache를 참조

당신은 계획이 직접 계획 캐시를보고 컴파일하는 데 걸린 많은 시간을 식별 할 수 있어야한다.

불행하게도 나는 단순히 쿼리의 복잡성을 감소 이외의 SQL Server 쿼리에 대한 컴파일 시간을 단축하는 방법에는 여러 가지 잘 모르는 것 같아요. 계획 캐싱을 통해 컴파일 계획을 수립하는 빈도를 줄이려는 시도가 성능 향상을위한 표준 접근 방식입니다.