I have Sql Server database and my table has 1500000 rows …because of large amount of data
execution time of my following procedure is very high
TABLE—–
CREATE TABLE [dbo].[MyTable](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Link] [text] NULL,
[Title] [text] NULL,
[Duration] [text] NULL,
[Image] [text] NULL,
[Embbed] [text] NULL,
[Keywords] [text] NULL,
[Category] [text] NULL,
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
PROCEDURE——
ALTER PROCEDURE [dbo].[Search]
@SearchQuery varchar(1000),
@Id bigint
As
BEGIN
Select top 100 * from MyTable
where Id > @Id and Title like '%'+@SearchQuery+'%'
can any one help me how do I minimise execution time of sql query on table of 1500000 rows?
You force a table scan by:
Actually no – you force definitely the non-use of an index on Title. As indices go “left to right” the “some point in the middle” query thing just turns off index use.
if ID leaves a lot to search – there you go, especially when you combine that with inappropriately slow hardware (after all 1.5 million is small data).
You either get rid of the first “%” in the LIKE statement – so an index can be used – or use full text search, which will already break up the words in the index, but even then you better get rid of the first “%”.