﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 7,2000 / Performance Tuning  / Search query fluctuation in exection / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Wed, 22 May 2013 07:24:30 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>I think you're running into SQL Server not being able to detect that the two pieces of code are the same, and is not able to appropriate parameterize (using "simple" auto-parameterization), so when it runs into the second "similar" piece of code with the new criteria, it flushes the execution plan out, and starts over.You should take a look at BOL topics re: auto-parameterization, and/or forced auto-parameterization.  If any of that rings true - perhaps help out the CTE by actually manually parameterizing it and see if the plan stays the same and is then re-used.</description><pubDate>Fri, 25 Jan 2008 10:47:33 GMT</pubDate><dc:creator>Matt Miller (#4)</dc:creator></item><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>I'm not entirely clear on what you're asking.  Please post the code you have a question about (both CTE and the other version), and we can take a look at it.</description><pubDate>Fri, 25 Jan 2008 10:41:17 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>The query has ROW_NUMBER function and I am getting only rows with certain range like 50 to 100 which will be passed through variable using CTE.The same query if use with another logic like having one identity column it returns data in same time.Is that like CTE wont flush out the buffer...? Or some other thing is happening</description><pubDate>Thu, 24 Jan 2008 22:04:44 GMT</pubDate><dc:creator>aravind-305595</dc:creator></item><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>This is normal behavior in SQL databases.The first time you run it, it has to come up with an execution plan, so that takes the longest.After that, the first time you run it with one set of parameters, it has to find that data, but it saves the results in memory.  So, when you run the exact same thing again, it runs very fast.The whole idea is that, as the database is used more and more, it stores the most important and common data and the most important and common queries, so that they run very fast.</description><pubDate>Thu, 24 Jan 2008 15:29:22 GMT</pubDate><dc:creator>GSquared</dc:creator></item><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>When you run same query second time SQL Server does not actually execute it, it uses resultset stored in cache.Try to run DBCC FREEPROCCACHE after 1st execution and run query again.2nd time will be just like 1st time.:)</description><pubDate>Thu, 24 Jan 2008 15:12:42 GMT</pubDate><dc:creator>Sergiy</dc:creator></item><item><title>RE: Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>Can you post the query please, the schema of the tables and any indexes on those tables?Thanks</description><pubDate>Thu, 24 Jan 2008 07:04:17 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>Search query fluctuation in exection</title><link>http://www.sqlservercentral.com/Forums/Topic446874-65-1.aspx</link><description>I have complex query with joins with necessary index. The query searches based on a given text value. The query returns the data in 11 seconds for the first time. The same query with same search text returns data in less than a second from the next executions.The same thing happens when I change the search text to some other value. It takes 5 seconds for first time and less than 1 second from then on.Please suggest things that I have to check.I am using SQL Server 2005 with SP2Thanks in advance.</description><pubDate>Thu, 24 Jan 2008 06:24:56 GMT</pubDate><dc:creator>aravind-305595</dc:creator></item></channel></rss>