Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to optimise this query?
    primarykey
    data
    text
    <p>there're 1 million records in jobs table. the execution time for the following query is 30 secs. The query is not elegant and it will return the number of records fit the criteria. Please help me with optimisation.</p> <pre><code>DECLARE @MaxIdValue varchar(100) DECLARE @SerchFilter varchar(100) = 'test' DECLARE @TotalRowCount int = ( SELECT Count(*) AS [RowCount] FROM [Jobs] INNER JOIN [Sites] ON [Jobs].[SiteId] = [Sites].[Id] INNER JOIN [JobStatusHistory] ON [Jobs].[JobStatusHistoryId] = [JobStatusHistory].[Id] INNER JOIN [JobStatuses] ON [JobStatusHistory].[StatusId] = [JobStatuses].[Id] INNER JOIN [JobTypes] ON [Jobs].[JobTypeId] = [JobTypes].[Id] LEFT JOIN [Customers] ON [Jobs].[CustomerId] = [Customers].[Id] LEFT JOIN [Priorities] ON [Jobs].[PriorityId] = [Priorities].[Id] LEFT JOIN [TaskTypes] ON [Jobs].[TaskTypeId] = [TaskTypes].[Id] LEFT JOIN [Areas] ON [Sites].[AreaId] = [Areas].[Id] WHERE ( [Sites].[Active]=1 AND ( [Jobs].[OwnedByCompanyId]=18 OR [Jobs].[OwnedByCompanyId] = 0) AND [Jobs].[Active]=1 ) AND ( [Customers].[Name] LIKE '%'+@SerchFilter+'%' OR [Sites].[Name] LIKE '%'+@SerchFilter+'%' OR [Sites].[Address1] LIKE '%'+@SerchFilter+'%' OR [Sites].[Postcode] LIKE '%'+@SerchFilter+'%' OR [Sites].[UPRN] LIKE '%'+@SerchFilter+'%' OR [Sites].[Contact] LIKE '%'+@SerchFilter+'%' OR [Sites].[Telephone] LIKE '%'+@SerchFilter+'%' OR [Sites].[Work] LIKE '%'+@SerchFilter+'%' OR [Sites].[MobileNumber] LIKE '%'+@SerchFilter+'%' OR [Areas].[Description] LIKE '%'+@SerchFilter+'%' OR [Jobs].[Id] LIKE '%'+@SerchFilter+'%' OR [Jobs].[OrderNumber] LIKE '%'+@SerchFilter+'%' OR [Jobs].[Description_PlainText] LIKE '%'+@SerchFilter+'%' OR [Jobs].[JobNumber] LIKE '%'+@SerchFilter+'%' OR [JobTypes].[Description] LIKE '%'+@SerchFilter+'%' OR [TaskTypes].[Description] LIKE '%'+@SerchFilter+'%' OR [Priorities].[Description] LIKE '%'+@SerchFilter+'%' ) ) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload