3

I have 1 stored procedure which can return more than 1000 of records.

I want to Create temporary Non cluster index on my searching table columns as because i have heard that non cluster index will speed up data retrieval (SELECT) operations and slow down data updates(UPDATE and DELETE) operations and remove that non cluster index after my Operation have been completed.

Like I am having 2 Tables UserDetails and CategoryMaster and my searching fieds:

  • UserDetails(ServiceDescription,Skills)
  • CategoryMaster(Name)

This is my stored procedure:

ALTER PROCEDURE [dbo].[SearchworkerProcedure1]
    @SearchKeyword nvarchar(70)

AS
 DECLARE @Keywords TABLE
   (    
      sno INT IDENTITY(1,1) PRIMARY KEY,
      keyname VARCHAR(100),
      Shortkeyname as  substring(keyname,0,5)
    )

DECLARE @SearchKeywordTable TABLE
(
        [VendorId] [int]  NULL,
        [ServiceDescription] [nvarchar](max) NULL,
        [Skills] [nvarchar](max) NULL
)  
INSERT INTO @Keywords SELECT * FROM [splitstring_to_table](@SearchKeyword,',')
BEGIN

                    --My Query
END

My UserDetails Create Query:

CREATE TABLE [dbo].[UserDetails](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [Fullname] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_UserDetails] 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]

So is that Possible to create temporary non cluster index in stored procedure and remove that non cluster index after Select Operation????

1 Answers1

2

The temporary index is a bad idea. To index a table, a table needs to be scanned - just as it would if you were doing a SELECT on it with the current setup.

Permanent (and temporary) indexes on the fields that you have mentioned would have absolutely no effect whatsoever because your search criteria has leading wildcards. This will result in a table scan anyway.

The only place where indexes may help are on your foreign key columns used in joins. However without having any meaningful sizing stats in regards to yoiur tables, it's a guess.

DB101
  • 633
  • 4
  • 8
  • so what do you suggest to increase performance for my stored procedure? –  Dec 10 '14 at 03:31
  • 1
    Post an execution plan and we can take a look at that to see if there are any indicators. However the big problem is your use of leading wildcards in your search predicates. – DB101 Dec 11 '14 at 11:49
  • sorry i didnt get you.what is execution plan?? –  Dec 12 '14 at 04:54
  • 2
    When you run a query in SSMS, there is an option to Include Actual Execution plan. Hit Ctrl-M, run your query and then select the Execution plan tab. This will show you the steps that the query took graphically. This is what we need to see before being able to give further advice on tuning the query. – DB101 Dec 12 '14 at 11:00