0

90% of the cost for following query is according to execution plan related to clustered scan against the primary key index. The average duration is around 2 seconds per execution. The execution count for this in our applications is very high and therefore this results in large load. Can you help me improve this either with index or restructure of query?

   CREATE TABLE [dbo].[EventLog](
    [Id] [uniqueidentifier] NOT NULL,
    [StartTime] [datetime] NOT NULL,
    [StopTime] [datetime] NULL,
    [executionStatus] [smallint] NOT NULL,
    [executionType] [smallint] NOT NULL,
    [Info] [xml] NULL,
 CONSTRAINT [PK_Log] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY];
GO


SELECT TOP(1) execution.Id,
                                StartTime,
                                StopTime,
                                executionStatus,
                                executionType,
                                execution.Info
                        FROM dbo.EventLog execution INNER JOIN
                                (SELECT Id,
                                        cast(Info as VARCHAR(MAX)) as Info
                                        FROM dbo.EventLog
                                        WHERE (executionType=1 OR executionType=4)
                                        AND executionStatus=1
                                        AND StopTime IS NOT NULL) as SUBQ
                                on execution.Id=SUBQ.Id 
                                WHERE SUBQ.Info LIKE '%<Name>For Trial</Name>%'
                                  AND SUBQ.Info LIKE '%<Type>2</Type>%'
                                ORDER BY StartTime DESC;
GO

Thanks in advance!

5

1 Answer 1

0

What's the use of Join at all? Just drop it and move all conditions inside 'where' branch.

1
  • Unfortunately I didn't make any progress. Any other hints that might help are highly appreciated.
    – pesi
    Jan 26, 2015 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.