Performance Issue on my Query Execution

Last post 10-08-2008 4:01 AM by kumaravel v. 31 replies.
Page 1 of 3 (32 items) 1 2 3 Next >
Active Topics My Discussions Unanswered Sort Posts: Previous Next
  • 10-05-2008 4:53 PM

    Performance Issue on my Query Execution

    hi

     

    I am facing performance problem when i execute the below query.

    The table call tEvent which contains more than 2million records.

    another one Tunit table contains 3500 records.

     

    SELECT 13893,

    CAST ( CAST ( YearPart AS VARCHAR ) + '-' + RIGHT ( '0' + CAST ( MonthPart AS VARCHAR ), 2 ) + '-' + RIGHT ( '0' + CAST ( DayPart AS VARCHAR ), 2 ) AS SMALLDATETIME ) AS DataCapturePeriodStart,

    DataCaptureCount, MaxParkEventTimeDetected, MaxParkEventLastModified,

    CASE

    WHEN StatusCode = 'A' THEN 100

    WHEN StatusCode = 'W' THEN 101

    WHEN StatusCode = 'O' THEN 102

    WHEN StatusCode = 'S' THEN 103

    ELSE 104

    END AS DataType

    FROM

    (select count(1) AS DataCaptureCount, a.StatusCode,

    MAX ( a.TimeDetected ) AS MaxTimeDetected, MAX ( a.LastModified ) AS MaxLastModified,

    DATEPART ( yy, a.TimeDetected ) AS YearPart, DATEPART ( mm, a.TimeDetected ) AS MonthPart, DATEPART ( dd, a.TimeDetected ) AS DayPart

    from tEvent a, tunit b

    where a.unitidsource=b.unitid and b.unitserialNumber = '20538'

    AND ( '2008-09-14 00:00:00' <= A.TimeDetected AND A.TimeDetected < '2008-09-15 00:00:00' )

    GROUP BY a.StatusCode, b.SerialNumber, DATEPART ( yy, a.TimeDetected ), DATEPART ( mm, a.TimeDetected ), DATEPART ( dd, a.TimeDetected )

    ) AS TT1

     

     

    ----

    when i execute this script,, it takes more than 5 to 6 min.

    can anyone suggest me how to reduce the execution time to less than 1min. Any solution no problem.

     

    thanks and advance

    kumar

    Filed under:
  • 10-06-2008 1:56 AM In reply to

    Re: Performance Issue on my Query Execution

    What indexes do you have on those tables?

  • 10-06-2008 2:19 AM In reply to

    Re: Performance Issue on my Query Execution

    TParkEvent Table :

                      Pk_TparkEvent (clustered), wms_ix_criticalValues (non-unique, Non_clustered), wms_ix_InsertNotificationBuffer(Non-Unique, Non-Clustered), wms_ix_ParkEventLastModified (Non-Unique, Non-Clustered), wms_ix_ParkEventTimeDetected(non-Unique, non-Clustered)

     TParkUnit Table :

                      Pk_TparkUnit (Clustered)

  • 10-06-2008 3:31 AM In reply to

    Re: Performance Issue on my Query Execution

    You might use CONVERT(VARCHAR(10), A.TimeDetected, 120) or DATEADD(hh, DATEDIFF(hh, 0,  A.TimeDetected), 0) to get rid of the time of day, and group on that expression.

    The DATEPART calls may be slowing you down.

  • 10-06-2008 5:11 AM In reply to

    Re: Performance Issue on my Query Execution

    i tried that too. But no Use.   

    Is there any other way to find out the performance solution ?  Is the index keys are right??

  • 10-06-2008 6:05 AM In reply to

    Re: Performance Issue on my Query Execution

    Other option - do the filtering and date manipulation in a derived table embedded within your derived table.

  • 10-06-2008 6:24 AM In reply to

    Re: Performance Issue on my Query Execution

    sorry can you little brief about what you said. I dont understand.

     thanks

  • 10-06-2008 7:03 AM In reply to

    Re: Performance Issue on my Query Execution

    Inside your derived table (TT1) move the DATEPART bits to and the WHERE clause for the date filtering to a derived table. This often helps SQL doing first things first, instead doing everything in aggregate.

  • 10-06-2008 7:14 AM In reply to

    Re: Performance Issue on my Query Execution

    thanks man.

     I have changed my query below:

     

    SELECT
    13893, DayMonthYearPart AS DataCapturePeriodStart,DataCaptureCount, MaxParkEventTimeDetected, MaxParkEventLastModified,

    CASE

    WHEN ParkEventStatusCode = 'A' THEN 100

    WHEN ParkEventStatusCode = 'W' THEN 101

    WHEN ParkEventStatusCode = 'O' THEN 102

    WHEN ParkEventStatusCode = 'S' THEN 103

    ELSE 104 END AS DataType

    FROM

    (select count(1) AS DataCaptureCount, a.ParkEventStatusCode,

    MAX ( a.ParkEventTimeDetected ) AS MaxParkEventTimeDetected, MAX ( a.ParkEventLastModified ) AS MaxParkEventLastModified,

    convert(varchar(12),a.ParkEventTimeDetected,105) AS DayMonthYearPart

    from tparkEvent a INNER JOIN tparkunit b

    ON a.parkunitidsource=b.parkunitid and b.parkunitserialNumber = '20538'

    AND (A.ParkEventTimeDetected BETWEEN '2008-09-14' AND '2008-09-15')

    GROUP BY a.ParkEventStatusCode, b.ParkUnitSerialNumber, convert(varchar(12),a.ParkEventTimeDetected,105) ) AS TT1

     

    --------------

    Is it ok what you were suggesting me ?  If i run this query, it takes 1.40min. i gave parameter just 1 day only....

    my people are expecting less than 30sec .

    awaiting your reply.

  • 10-06-2008 7:52 AM In reply to

    Re: Performance Issue on my Query Execution

    Well, you've already taken off about 75% of execution time by using one CONVERT instead of three DATEPART calls.

    You might try adding OPTION (MAXDOP 1) after the TT1 alias to see if you're suffering from unwanted parallellism.

  • 10-06-2008 8:12 AM In reply to

    Re: Performance Issue on my Query Execution

    thanks for your immediate reply yar.

    As per your suggession, i have added the OPTION (MAXDOP 1) after alias TT1.

    But it takes long time after i add this OPTION. I dont know why?

  • 10-06-2008 8:16 AM In reply to

    Re: Performance Issue on my Query Execution

    That means that SQL was using parallellism exactly the way that it was intended, and you can drop the OPTION clause.

    Check the execution plans - which operations are taking up the biggest percentages?

  • 10-06-2008 8:28 AM In reply to

    Re: Performance Issue on my Query Execution

    Sort cost is 62%

    Clustered Index seek cost : 19%

    Index Seek Cost : 18%

     

    the rest are all 0%.  This status i am see from the begin of the query. Still it shows the same status.

     

  • 10-06-2008 8:31 AM In reply to

    Re: Performance Issue on my Query Execution

    Check the details - sorting what, seeking which (clustered) index? And give us the details of the index: which colums, and in which order.

  • 10-06-2008 8:38 AM In reply to

    Re: Performance Issue on my Query Execution

    As per your requisition, i have mentioned my table information.

    tParkEvent Table

    It contains more that 3millions recordz and the index keys are in the order:

    ParkUnitIdSource(Non-Unique, Non-Cluster),  PK_TParkEvent(clustered), WMS_IX_InsertNotificationBuffer(Non-Unique, Non-Clusterd),   WMS_IX_ParkEventLastModified (non-clustered),   WMS_IX_ParkEventTimeDetected(non-clustered),

     

    tParkUnit table

    It contains 4000 rows.

    Index key is : PK_TParkUnit (clustered)

     

Page 1 of 3 (32 items) 1 2 3 Next >
Active Topics   My Discussions    Unanswered Posts


© 2000 - 2007 vDerivatives Limited All Rights Reserved.