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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:24:09+00:00 2026-05-16T15:24:09+00:00

My applications runs queries against a sql server database. In many cases I can

  • 0

My applications runs queries against a sql server database.

In many cases I can see the benefit of an execution plan: for example I click for the first time on a button to

SELECT * from Tasks
WHERE IdUser = 24 AND
  DATE < '12/12/2010' and DATE > '01/01/2010'

it takes 15 seconds the first time, 8 seconds the following times.

EDIT: I USE PARAMETRIZED QUERIES.

So I have a 7 seconds improvement the second time.

Now as I run the application again (so I do a new database connection) the first time it will take 15 seconds, the second time 7…

How is it possible to tell SQL Server to store the execution plans, at least to remember them for same days? Or however how can I get benefit of already calculated execution plans? If different users run the same query is it a way to tell sql server to be smart enough to use the same execution plan, even if in that case probably the IdUser will be different.

In software I have some parameters, so may be the next execution of the query will have different MinDate and MaxDate, but will this affect the query plan?

  • 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-16T15:24:09+00:00Added an answer on May 16, 2026 at 3:24 pm

    Use parametrised queries to maximise the chances that the plan will be cached

    SELECT * from MYTasks 
    WHERE IdUser = @UserId AND DATE < @enddate and DATE > @startdate
    

    SQL Server does do auto parametrisation but can be quite conservative about this.

    You can get some insight into plan reuse from the following

    SELECT usecounts, cacheobjtype, objtype, text, query_plan, value as set_options
    FROM sys.dm_exec_cached_plans 
    CROSS APPLY sys.dm_exec_sql_text(plan_handle) 
    CROSS APPLY sys.dm_exec_query_plan(plan_handle) 
    cross APPLY sys.dm_exec_plan_attributes(plan_handle) AS epa
    where text like '%MYTasks%' and attribute='set_options'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When any applications runs, we can see logs in eclipse console for example launching
My application runs SQL Server 2008 on Windows Server 2008 using Tomcat. I am
I'm having an issue with some SQL Server 2008 queries and I think I
I have an SQL Server (2008 R2) based (C# WinForms) application that predominantly runs
I'd like to monitor SQL queries executed by my application while it runs. I'm
I am working on a product that runs an SQL server which allows some
Currently we have a hybrid ASP/PHP setup connecting to a SQL Server 2005 database.
I created a Windows Qt C++ application that performs some SQL queries. This application
I've been attempting to architect a server side API that runs using a noSQL
I have made the following method which runs hard-coded xPath queries in a hard-coded

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.