Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 53131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:00:55+00:00 2026-05-10T17:00:55+00:00

I have an SP that takes 10 seconds to run about 10 times (about

  • 0

I have an SP that takes 10 seconds to run about 10 times (about a second every time it is ran). The platform is asp .net, and the server is SQL Server 2005. I have indexed the table (not on the PK also), and that is not the issue. Some caveats:

  • usp_SaveKeyword is not the issue. I commented out that entire SP and it made not difference.
  • I set @SearchID to 1 and the time was significantly reduced, only taking about 15ms on average for the transaction.
  • I commented out the entire stored procedure except the insert into tblSearches and strangely it took more time to execute.

Any ideas of what could be going on?

set ANSI_NULLS ON  go  ALTER PROCEDURE [dbo].[usp_NewSearch]    @Keyword VARCHAR(50),    @SessionID UNIQUEIDENTIFIER,    @time SMALLDATETIME = NULL,    @CityID INT = NULL  AS  BEGIN    SET NOCOUNT ON;    IF @time IS NULL SET @time = GETDATE();      DECLARE @KeywordID INT;    EXEC @KeywordID = usp_SaveKeyword @Keyword;    PRINT 'KeywordID : '    PRINT @KeywordID    DECLARE @SearchID BIGINT;         SELECT TOP 1 @SearchID = SearchID      FROM tblSearches      WHERE SessionID = @SessionID       AND KeywordID = @KeywordID;      IF @SearchID IS NULL BEGIN          INSERT INTO tblSearches                (KeywordID, [time], SessionID, CityID)           VALUES                (@KeywordID, @time, @SessionID, @CityID)          SELECT Scope_Identity();    END    ELSE BEGIN          SELECT @SearchID    END    END 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:00:56+00:00Added an answer on May 10, 2026 at 5:00 pm

    Why are you using top 1 @SearchID instead of max (SearchID) or where exists in this query? top requires you to run the query and retrieve the first row from the result set. If the result set is large this could consume quite a lot of resources before you get out the final result set.

    SELECT TOP 1 @SearchID = SearchID       FROM tblSearches      WHERE SessionID = @SessionID         AND KeywordID = @KeywordID; 

    I don’t see any obvious reason for this – either of aforementioned constructs should get you something semantically equivalent to this with a very cheap index lookup. Unless I’m missing something you should be able to do something like

    select @SearchID = isnull (max (SearchID), -1)   from tblSearches  where SessionID = @SessionID    and KeywordID = @KeywordID 

    This ought to be fairly efficient and (unless I’m missing something) semantically equivalent.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The Popup control has this ability built-in. You can use… May 11, 2026 at 2:16 pm
  • added an answer I had similar problem with much more tables involved. We… May 11, 2026 at 2:16 pm
  • added an answer I think this is a fine way to make such… May 11, 2026 at 2:16 pm

Related Questions

Here's a very simple question. I have an SP that inserts a row into
I have an absolutely positioned div containing several children, one of which is a
I have an array in Perl: my @my_array = (one,two,three,two,three); How do I remove
I have an images folder with a png in it. I would like to
I have a legacy VB6 application that was built using MSDE. As many client's
I have an MSSQL2005 stored procedure here, which is supposed to take an XML
I have a table-valued, inline UDF. I want to filter the results of that
I am presenting to a final authority evaluation scores for employees. Each row is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.