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 3696090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:41:48+00:00 2026-05-19T04:41:48+00:00

The web-site in question usually performs pretty good, but over time it becomes slower

  • 0

The web-site in question usually performs pretty good, but over time it becomes slower and slower.

We have a huge query to find the products that the user is searching for, and they are mostly in this form:

WHERE ProductName LIKE @ProductName OR @ProductName IS NULL
  AND ProductGroup LIKE @ProductGroup or @ProductGroup IS NULL
  AND (...)

That way we do not have to pass all the parameters if we are searching for only the Product Number. Could this be the reason that the queries are getting slower? Something to do with that the query is cached the first time, and the next time, when the parameters has changed, it uses the old query plan?

If so; What would be the best way to fix this? Dynamic SQL?

  • 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. Editorial Team
    Editorial Team
    2026-05-19T04:41:49+00:00Added an answer on May 19, 2026 at 4:41 am

    From the small snippet of the query you have shown it is difficult to see whether you are likely to have a Parameter sniffing issue but it sounds like it if you suddenly get a better plan after freeing the cache

    But that is generally a bad way of writing queries anyway. (WHERE x=@x OR @X IS NULL type of query) as it leads to an unnecessary scan. It might not make any difference in this case dependant on whether your LIKE has a leading wildcard or not.

    But SQL Server can convert the LIKE into a range seek on an index anyway so you will be unnecessarily penalising queries without a leading wildcard. (e.g. compare the plans for the queries below)

    DECLARE @T nchar(3) 
    SET @T='%f'
    
    
    SELECT [name]
      FROM [master].[dbo].[spt_values]
    where type like @T
    
    
    SELECT [name]
      FROM [master].[dbo].[spt_values]
    where type like @T OR @T IS NULL
    

    Plan

    You could try splitting these cases out or generating the dynamic search conditions with dynamic SQL.

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

Sidebar

Related Questions

hi I have a question I'am using for my web site wscf in vs2010
I have a web site in asp.net that uses a master page. In this
one question about NDBCLUSTER. I inherited the writing of a web site basing on
I have a PHP web site that has two directories: An application directory and
I know this is a pretty basic question, but I don't know how to
I'm using asp.net 3.5 and c# on my web site. Here is my question:
I am writing a small web site for a company Intranet and have the
this may be a simple question but until now I always created a web
I have a web site with .htacess file looks like this: RewriteEngine On RewriteCond
I have a question about tables in MySQL. I'm currently making a website where

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.