I am reviewing code that a co-worker is claiming "Ready for Production" and from what I see putting this online will shutdown our severs and I’m wondering if someone can help me convince them to refactor the base code before putting this online.Here is the situation:We are trying to mimic Google’s Search Suggestions which is an AJAX call functioned on a javascript onkeyup function. So in short this is going to get hammered with lots of traffic.I have placed code for the current table and the stored procedure and added some sample data that they are intending to use from a web interface and I think this is not as optimized as it should be. I think it should be fairly easy to follow but if you have questions please ask.Can I get some opinions on how I should proceed please? BTW, I see the clustered index in the wrong place but they insist this is ready to go not to mention the 2 scans on the table from the SP. Suggestions would be very helpful.The TableCREATE TABLE [dbo].[en]( [ID] [int] IDENTITY(1,1) NOT NULL, [Key] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [Keyword] [varchar](250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, CONSTRAINT [PK_en] PRIMARY KEY NONCLUSTERED ( [ID] ASC)WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]GO
The Stored ProcCreate PROCEDURE [dbo].[GetSuggestions] @firstSeach varchar(50) , @secondSearch varchar(50) = ''ASBEGIN SET NOCOUNT ON; IF EXISTS(SELECT 1 FROM dbo.en WHERE [Key] = @firstSeach) BEGIN SELECT TOP 10 KEYWORD FROM dbo.en WHERE [Key] = @firstSeach; END; ELSE BEGIN SELECT TOP 10 KEYWORD FROM dbo.en WHERE [Key] = @secondSearch; END; END
Sample Data Select top 50 *ID Key Keyword----------- -------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------1 A amazon2 A american idol3 A aol5 A american airlines6 A addicting games7 A abc8 A autotrader9 A american express10 A apple261 AA aaa262 AA aa.com263 AA aarp264 AA aafes265 AA aarons266 AA aaa discounts267 AA aaron brothers268 AA aaliyah269 AA aaa travel270 AA aaron schock7019 AAA aaa discounts7020 AAA aaa.com7021 AAA aaa travel7022 AAA aaa california7023 AAA aaamath7024 AAA aaa maps7025 AAA aaas7026 AAA aaa cooper7027 AAA aaa texas7028 AAA aaa carolinas181076 AAAA aaa insurance181077 AAAA aaaa battery181078 AAAA aaaa driving school181079 AAAA aaaa storage181080 AAAA aaaa swimming181081 AAAA aaaa.org181082 AAAA aaaai181083 AAAA aaaai 2009181084 AAAA aaaamon.dll181085 AAAA aaaasf181086 AAAB aaa backgrounds181087 AAAB aaa restaurant equipment181088 AAAB aaaba181089 AAAB aaabiz.com181090 AAAB aaable auto insurance181091 AAAB aaabodybuilding.com181092 AAAB aaabor.com181093 AAAB aaabrasives181094 AAAB abor181095 AAAC aaa carolinas181096 AAAC aaace(50 row(s) affected)