﻿<?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 2008 / SQL Server 2008 - General  / rebuild index worsens query performance / 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 03:24:50 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>actually .... [b]nothing[/b] !it only exports sqlplans and consumption data ( as stated in the query to be run by the script ).( I must have misinterpreted your previous replies [url]http://www.sqlservercentral.com/Forums/FindPost1390116.aspx[/url] )Powershell is just a scripting means that can facilitate stuff for you. That's it.But it has great potential because it is :1) .net capable2) you just reference the namespace / dll you want it to use and ... you can just do the things your devs are trying to, but without the hassle of visual studio. This way any dba will be capable of supporting the dev-teams way better because he can actually show them "their" code to be used, just not using their UI. :w00t:</description><pubDate>Mon, 03 Dec 2012 00:01:26 GMT</pubDate><dc:creator>ALZDBA</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>I am able to get the est plan and actual plan via other means (query analyser, dmv's) -- before I tyr running this somewhere, what will this script provide that is not available elsewhere?</description><pubDate>Fri, 30 Nov 2012 08:56:03 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>If you're in for some [b]Powershell[/b], maybe the attached [b]ps1 [/b]script can help out :w00t:It will prompt for a sqlserver name ( servername\instance or just servername if you have a default instance )and will write a consumption file and one file for every [b]top (n)[/b] sqlplan. ( location: C:\temp\powershell )It will execute the query using sys.dm_exec_text_query_plan, so you can get the full ( and long ) query plan.Maybe this can get you a step further.</description><pubDate>Thu, 29 Nov 2012 06:28:28 GMT</pubDate><dc:creator>ALZDBA</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>the ddl and query are attached to this post:http://www.sqlservercentral.com/Forums/FindPost1385962.aspx</description><pubDate>Wed, 28 Nov 2012 13:56:21 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Thanks JohanI tried the 2301 flag described in that article (option querytraceon 2301)the actual plan it generated was WAY different from the actual without the flag, and identitifed a missing indexI would like to take that plan and force it into the query, but (per my previous posts) the plan XML seems to exceed a limit on length -- any thoughts as to how to work around that?</description><pubDate>Wed, 28 Nov 2012 13:53:07 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>I'd like to get you some sample data -- what is the best way to get it to you?  (BAK file [would prefer], etc.)</description><pubDate>Wed, 28 Nov 2012 13:48:15 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>If you have the full query, just attach it to your forum reply.You may also want to take a look at dmv [url=http://msdn.microsoft.com/en-us/library/ms181929(v=sql.105).aspx]sys.dm_exec_sql_text(sql_handle | plan_handle)[/url] and/or[url=http://msdn.microsoft.com/en-us/library/bb326654(v=sql.105).aspx]sys.dm_exec_text_query_plan[/url] (         plan_handle         , { statement_start_offset | 0 | DEFAULT }        , { statement_end_offset | -1 | DEFAULT })[b]to get your full query text and plan.[/b]</description><pubDate>Tue, 27 Nov 2012 06:16:23 GMT</pubDate><dc:creator>ALZDBA</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>this is the post:On a related note, I am trying to pass as a query hint the XML from what I believe to be the plan that the query was using before purgeI can see the plan just fine as a sqplan, but when I try to retrive the XML, the "StatementText" gets truncated. If I try to paste into the hint the missing part of the statement from the original query, I get this at run time" "XML parsing: line 104, character 17, well formed check: no '&amp;lt;' in attribute value"I suspect there is some limit to the length of "StatementText", on both the retrieval and the use in a query option -- is there a way to circumvent that limit? Or, can the complete XML live apart from the query option (for ex. a text file) and still be referenced by the query option?</description><pubDate>Tue, 27 Nov 2012 06:02:47 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>this is the post:On a related note, I am trying to pass as a query hint the XML from what I believe to be the plan that the query was using before purgeI can see the plan just fine as a sqplan, but when I try to retrive the XML, the "StatementText" gets truncated. If I try to paste into the hint the missing part of the statement from the original query, I get this at run time" "XML parsing: line 104, character 17, well formed check: no '&amp;lt;' in attribute value"I suspect there is some limit to the length of "StatementText", on both the retrieval and the use in a query option -- is there a way to circumvent that limit? Or, can the complete XML live apart from the query option (for ex. a text file) and still be referenced by the query option?</description><pubDate>Tue, 27 Nov 2012 05:59:10 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/26/2012)[/b][hr]look at my post from 4:34:43 PM[/quote]The times change according to each of our local times.  So there is no such entry according to what I can see.  Use the Post # instead.</description><pubDate>Tue, 27 Nov 2012 05:38:59 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Because estimates and actuals are that much dissimilar, maybe have a look at Daves article "[url=http://sqlblogcasts.com/blogs/sqlandthelike/archive/2012/11/26/when-row-estimation-goes-wrong.aspx]When estimation goes wrong[/url]".http://sqlblogcasts.com/blogs/sqlandthelike/archive/2012/11/26/when-row-estimation-goes-wrong.aspxI think trying out his workaround is worth the test.</description><pubDate>Tue, 27 Nov 2012 00:46:33 GMT</pubDate><dc:creator>ALZDBA</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>look at my post from 4:34:43 PM</description><pubDate>Mon, 26 Nov 2012 12:39:10 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/26/2012)[/b][hr]no "divide-and-conquer", etc. until we figure out what happened that weekend[/quote]Unless you can resurrect a Before'n'After of the actual Execution Plan, that could be a very long wait.  In the meantime, you're stuck with an underperforming sproc.  It's your database and you should, of course, do what you think is right for it but I'd make a copy of that proc and start fixing the code because it's a problem now and the code wasn't durable enough to withstandeven a reindexing.</description><pubDate>Mon, 26 Nov 2012 12:21:14 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>no "divide-and-conquer", etc. until we figure out what happened that weekend</description><pubDate>Mon, 26 Nov 2012 11:00:06 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>what would be the best way to get you sample data?  (backup file, etc.)</description><pubDate>Mon, 26 Nov 2012 10:55:14 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>anyone?(re:)On a related note, I am trying to pass as a query hint the XML from what I believe to be the plan that the query was using before purgeI can see the plan just fine as a sqplan, but when I try to retrive the XML, the "StatementText" gets truncated. If I try to paste into the hint the missing part of the statement from the original query, I get this at run time" "XML parsing: line 104, character 17, well formed check: no '&amp;lt;' in attribute value"I suspect there is some limit to the length of "StatementText", on both the retrieval and the use in a query option -- is there a way to circumvent that limit? Or, can the complete XML live apart from the query option (for ex. a text file) and still be referenced by the query option?</description><pubDate>Mon, 26 Nov 2012 09:34:43 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/21/2012)[/b][hr]I dont have time to fabricate sample dataI will see what my boss says about this and get back to you after Thanksgiving break[/quote]On this one, I agree.... way too many tables involved.  That does get back to my suggestion, though.  You could probably turn this sproc into a real screamer if you did the Divide'n'Conquer thing.</description><pubDate>Wed, 21 Nov 2012 16:24:44 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>I dont have time to fabricate sample dataI will see what my boss says about this and get back to you after Thanksgiving break</description><pubDate>Wed, 21 Nov 2012 11:58:26 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/21/2012)[/b][hr]DDL attached, we are not able to provide sample data, per my boss's instructions:"Everything but sample data. Column definition should allow them to generate what they need"[/quote]Just so you know, we don't know your problem domain so for us making up data for testing doesn't really work.  Sample data is something you can fabricate and then build the expected results.We DON'T want live data.</description><pubDate>Wed, 21 Nov 2012 11:29:58 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>DDL attached, we are not able to provide sample data, per my boss's instructions:"Everything but sample data. Column definition should allow them to generate what they need"</description><pubDate>Wed, 21 Nov 2012 10:43:00 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>thanks Jeffnote that the table I deleted from is not referenced in the query</description><pubDate>Wed, 21 Nov 2012 08:26:49 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/20/2012)[/b][hr]All:This was literally a "switch-flip" -- the query run time doubled exactly right after I made the changes noted in my original post(note:  on that day I rebuilt indexes but NOT stats -- update stats came 2 weeks later and made no difference either way)No other operations took place on either database that dayWe need to track down what changed such that the query run time doubled, before we start making SQL changesDid I do something wrong that day?[/quote]No.  You did fine.  As a sidebar, rebuilding (not reorging) indexes will rebuild the stats anyway.Depending on the queries, of course, it is possible that a previous query plan could survive through something like this.  It may be that you just have a different query plan in cache than what's needed to support the rebuilt indexes.  I don't know your system or what the load is on it but it might be worth trying to run the query with a "recompile" built into it or, as a last resort, clearing proc cache altogether.  Note that clearing proc cache will cause every query to recompile during first usage so things could slow down quite a bit.  I've not been able to check on your actual execution plans so read on before you try any of that.I've also run into situations where a new query plan is worse than the old one.  For example, I found one query that shifted from doing a single table scan on several hundred thousand rows to what looked like a nice index seek.  Looking at the properties of the index seek, it turned out that the index seek was being executed thousands of times and that's actually quite a bit slower than a single table scan.In stark contrast to the above, I've also seen where the optimizer has decided that, because of the reduction in data (you did remove about 50% of the data IIRC), the optimizer suddenly decides that it would be more cost efficient to do scans instead of seeks, sometimes much to the detriment of performance.This all falls under the umbrella frequently described as "**it happens'  :-D  and, at this point, I'd recommend not wasting much more time on trying to figure out precisely what happened and begin making tuning efforts on the troublesome query.Cosidering all of the OR inequalites in the query, the non-sargable criteria, and the "all-in-one" nature of the query, I'd say that using a bit of "Divide'n'Conquer" technology would not only go a long way in improving the performance of the query but would also make it much more "bullet proof" for such future actions as reducting data and reindexing.</description><pubDate>Wed, 21 Nov 2012 06:52:23 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/20/2012)[/b][hr]thats all the code for the misbehaving query, moot point anyway as no code is changing until we figure out what went wrong that day[/quote]Rechecked what you posted, sorry, for some reason I thought there were some UDF's in the main code.  The only other piece of code not provided is the code for ParseIdListToTable.Still, we need the DDL for the tables, including index definitions, some sample data for each of the tables that is representative of the problem domain (SAMPLE data, not real data), and expected results based on the sample data.Sorry, but I'm not spending my time deciphering the information from the sp_helps.txt file.  As one of many volunteers on this site, I have better things to do with my time considering it would be easier for you to just generate what is required.</description><pubDate>Tue, 20 Nov 2012 18:17:02 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>thats all the code for the misbehaving query, moot point anyway as no code is changing until we figure out what went wrong that day</description><pubDate>Tue, 20 Nov 2012 15:15:40 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/20/2012)[/b][hr]All:This was literally a "switch-flip" -- the query run time doubled exactly right after I made the changes noted in my original post(note:  on that day I rebuilt indexes but NOT stats -- update stats came 2 weeks later and made no difference either way)No other operations took place on either database that dayWe need to track down what changed such that the query run time doubled, before we start making SQL changesDid I do something wrong that day?[/quote]Have dug into it.  One thing I noticed was the orders of magnatude difference between actual counts and estimated count (much lower) which indicates possible problem with statistics since the paln may not be the best for the number of rows.Not messing with the query though since you haven't provided any DDL for the tables, sample data, expected results.  Also not sure if we have all the code involved in the query.</description><pubDate>Tue, 20 Nov 2012 14:46:26 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>All:This was literally a "switch-flip" -- the query run time doubled exactly right after I made the changes noted in my original post(note:  on that day I rebuilt indexes but NOT stats -- update stats came 2 weeks later and made no difference either way)No other operations took place on either database that dayWe need to track down what changed such that the query run time doubled, before we start making SQL changesDid I do something wrong that day?</description><pubDate>Tue, 20 Nov 2012 13:44:40 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Does this run from a stored proc with parameters?  Is parameter sniffing a problem here?  Perhaps add an OPTION(OPTIMIZE FOR if params are used and see what shakes out?</description><pubDate>Tue, 20 Nov 2012 13:26:43 GMT</pubDate><dc:creator>DiverKas</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Any luck with the plan?On a related note, I am trying to pass as a query hint the XML from what I believe to be the plan that the query was using before purgeI can see the plan just fine as a sqplan, but when I try to retrive the XML, the "StatementText" gets truncated.  If I try to paste into the hint the missing part of the statement from the original query, I get this at run time"  "XML parsing: line 104, character 17, well formed check: no '&amp;lt;' in attribute value"I suspect there is some limit to the length of "StatementText", on both the retrieval and the use in a query option -- is there a way to circumvent that limit?  Or, can the complete XML live apart from the query option (for ex. a text file) and still be referenced by the query option?</description><pubDate>Tue, 20 Nov 2012 11:34:47 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/17/2012)[/b][hr]my apologies for the runaround on the query plan -- I thought sys.dm_exec_text_query_plan yielded an actual, apparently that's not the case[/quote]Definition of an 'actual plan' is a plan with run-time information in it (actual row counts, actual executions). Plans pulled from cache have no run-time information in them (why would they), and hence are 'estimated plans', plans without run-time information, only estimated, compile-time information (estimated row count, estimated executions).</description><pubDate>Sat, 17 Nov 2012 15:13:33 GMT</pubDate><dc:creator>GilaMonster</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>stepping out, will be back online Monday, thank you for your help todaymy apologies for the runaround on the query plan -- I thought sys.dm_exec_text_query_plan yielded an actual, apparently that's not the case</description><pubDate>Sat, 17 Nov 2012 14:16:33 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>okay, that's not what I've heard elsewhere (re: column stats) but so be ittry this plan -- I generated it via "Include Actual Execution Plan" (vs sys.dm_exec_text_query_plan, from which I got the other plans)</description><pubDate>Sat, 17 Nov 2012 13:27:03 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Another FYI.  I haven't used maintenance plans in years to maintain my indexes or satistics.  I developed my own processes using T-SQL to manage these in a more intelligent manner.  Maintenance plans are a shot gun method that isn't always the best.There are also several routines out there on the web that you can get to do the same thing if you are interested.  Unfortunately I don't have the links to them.  Perhaps others reading this do have the links and can provide them for you.</description><pubDate>Sat, 17 Nov 2012 13:23:12 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/17/2012)[/b][hr]the stats which were rebuilt were COLUMN statisticsI thought table index rebuild only updated TABLE statistics (fullscan)Are you trying to tell me that this is not the case, i.e. table index rebuild updates both table AND column stats at 100%?[/quote]An index rebuild rebuilds the statistics on the columns for the index just as a statistics rebuild with a full scan.</description><pubDate>Sat, 17 Nov 2012 13:19:24 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>the stats which were rebuilt were COLUMN statisticsI thought table index rebuild only updated TABLE statistics (fullscan)Are you trying to tell me that this is not the case, i.e. table index rebuild updates both table AND column stats at 100%?</description><pubDate>Sat, 17 Nov 2012 13:16:51 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/17/2012)[/b][hr]A new development:As previously stated, the "trans" and "asset" tables are subscribed tablesI re-initialized the subscription this morningNow the query appears to be back to normal run time(no changes in table definition [indexes, etc.] compared to before the purge/etc)My understanding is that a re-initialization does the following:- Drops and re-creates the table on the subscriber side- Bulk inserts into the subscribed table- Re-creates indexes, constraints, etc.So what is the difference between doing all of the above, versus just running a maintenance plan to rebuild all the table's indexes?I am suspending the weekly index rebuild/update stats for now -- I don’t want the table to get fragmented again, but I also don’t want this performance degradation to resurface.  Also, a re-initialization of this subscription would be too time-consuming and disruptive to do on a regular basis.Thoughts?[/quote]Takes me back to what I originally stated.  After rebuilding the indexes you rebuilt the the statistics on those indexes using a sample size intead of a full scan.  This means that by rebuilding the statistics on those indexes, you made them less accurate than there were immediately following the index rebuild, which essentially rebuilds the statistics for the index using a full scan.</description><pubDate>Sat, 17 Nov 2012 13:02:52 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>[quote][b]jgenovese (11/17/2012)[/b][hr]"One other thing would really help, the actual execution plan."This IS the ACTUAL execution plan"Also, do you really drop the temporary table as soon as it is populated as it appears in the code you posted?"NO -- I extracted the query from the stored proc in which it resides[/quote]As for this being an actual execution plan, no it isn't.  All that is shown in the plan are estimates.  If this were the actual execution plan there would be actual counts shown in addition to the the estimates.</description><pubDate>Sat, 17 Nov 2012 12:55:55 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>A new development:As previously stated, the "trans" and "asset" tables are subscribed tablesI re-initialized the subscription this morningNow the query appears to be back to normal run time(no changes in table definition [indexes, etc.] compared to before the purge/etc)My understanding is that a re-initialization does the following:- Drops and re-creates the table on the subscriber side- Bulk inserts into the subscribed table- Re-creates indexes, constraints, etc.So what is the difference between doing all of the above, versus just running a maintenance plan to rebuild all the table's indexes?I am suspending the weekly index rebuild/update stats for now -- I don’t want the table to get fragmented again, but I also don’t want this performance degradation to resurface.  Also, a re-initialization of this subscription would be too time-consuming and disruptive to do on a regular basis.Thoughts?</description><pubDate>Sat, 17 Nov 2012 12:28:22 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>"One other thing would really help, the actual execution plan."This IS the ACTUAL execution plan"Also, do you really drop the temporary table as soon as it is populated as it appears in the code you posted?"NO -- I extracted the query from the stored proc in which it resides</description><pubDate>Sat, 17 Nov 2012 12:16:05 GMT</pubDate><dc:creator>jgenovese</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Also, no one is really going to dive into what you recently posted in an effort to help you figure out what be going on.  We really need the information posted as DDL scripts, plus you should put together some sample data (i.e. NOT REAL data) for the tables that is representative of the problem.  One other thing would really help, the actual execution plan.Also, do you really drop the temporary table as soon as it is populated as it appears in the code you posted?</description><pubDate>Sat, 17 Nov 2012 12:08:15 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item><item><title>RE: rebuild index worsens query performance</title><link>http://www.sqlservercentral.com/Forums/Topic1385783-391-1.aspx</link><description>Just an FYI, your parse routing is slow.  Take a look at this one, then read the article and its discussion that is referenced in the comments.Be sure to tread the comments.[code="sql"]/****** Object:  UserDefinedFunction [dbo].[DelimitedSplit8K]    Script Date: 11/17/2012 11:57:10 ******/IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[DelimitedSplit8K]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))DROP FUNCTION [dbo].[DelimitedSplit8K]GO/****** Object:  UserDefinedFunction [dbo].[DelimitedSplit8K]    Script Date: 11/17/2012 11:57:10 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO CREATE FUNCTION [dbo].[DelimitedSplit8K]/********************************************************************************************************************** Purpose: Split a given string at a given delimiter and return a list of the split elements (items). Notes: 1.  Leading a trailing delimiters are treated as if an empty string element were present. 2.  Consecutive delimiters are treated as if an empty string element were present between them. 3.  Except when spaces are used as a delimiter, all spaces present in each element are preserved. Returns: iTVF containing the following: ItemNumber = Element position of Item as a BIGINT (not converted to INT to eliminate a CAST) Item       = Element value as a VARCHAR(8000) Statistics on this function may be found at the following URL: http://www.sqlservercentral.com/Forums/Topic1101315-203-4.aspx CROSS APPLY Usage Examples and Tests:--=====================================================================================================================-- TEST 1:-- This tests for various possible conditions in a string using a comma as the delimiter.  The expected results are-- laid out in the comments--=====================================================================================================================--===== Conditionally drop the test tables to make reruns easier for testing.     -- (this is NOT a part of the solution)     IF OBJECT_ID('tempdb..#JBMTest') IS NOT NULL DROP TABLE #JBMTest;--===== Create and populate a test table on the fly (this is NOT a part of the solution).     -- In the following comments, "b" is a blank and "E" is an element in the left to right order.     -- Double Quotes are used to encapsulate the output of "Item" so that you can see that all blanks     -- are preserved no matter where they may appear. SELECT *   INTO #JBMTest   FROM (                                               --# &amp; type of Return Row(s)         SELECT  0, NULL                      UNION ALL --1 NULL         SELECT  1, SPACE(0)                  UNION ALL --1 b (Empty String)         SELECT  2, SPACE(1)                  UNION ALL --1 b (1 space)         SELECT  3, SPACE(5)                  UNION ALL --1 b (5 spaces)         SELECT  4, ','                       UNION ALL --2 b b (both are empty strings)         SELECT  5, '55555'                   UNION ALL --1 E         SELECT  6, ',55555'                  UNION ALL --2 b E         SELECT  7, ',55555,'                 UNION ALL --3 b E b         SELECT  8, '55555,'                  UNION ALL --2 b B         SELECT  9, '55555,1'                 UNION ALL --2 E E         SELECT 10, '1,55555'                 UNION ALL --2 E E         SELECT 11, '55555,4444,333,22,1'     UNION ALL --5 E E E E E          SELECT 12, '55555,4444,,333,22,1'    UNION ALL --6 E E b E E E         SELECT 13, ',55555,4444,,333,22,1,'  UNION ALL --8 b E E b E E E b         SELECT 14, ',55555,4444,,,333,22,1,' UNION ALL --9 b E E b b E E E b         SELECT 15, ' 4444,55555 '            UNION ALL --2 E (w/Leading Space) E (w/Trailing Space)         SELECT 16, 'This,is,a,test.'                   --E E E E        ) d (SomeID, SomeValue);--===== Split the CSV column for the whole table using CROSS APPLY (this is the solution) SELECT test.SomeID, test.SomeValue, split.ItemNumber, Item = QUOTENAME(split.Item,'"')   FROM #JBMTest test  CROSS APPLY dbo.DelimitedSplit8K(test.SomeValue,',') split;--=====================================================================================================================-- TEST 2:-- This tests for various "alpha" splits and COLLATION using all ASCII characters from 0 to 255 as a delimiter against-- a given string.  Note that not all of the delimiters will be visible and some will show up as tiny squares because-- they are "control" characters.  More specifically, this test will show you what happens to various non-accented -- letters for your given collation depending on the delimiter you chose.--=====================================================================================================================WITH cteBuildAllCharacters (String,Delimiter) AS ( SELECT TOP 256         'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',        CHAR(ROW_NUMBER() OVER (ORDER BY (SELECT NULL))-1)   FROM master.sys.all_columns) SELECT ASCII_Value = ASCII(c.Delimiter), c.Delimiter, split.ItemNumber, Item = QUOTENAME(split.Item,'"')   FROM cteBuildAllCharacters c  CROSS APPLY dbo.DelimitedSplit8K(c.String,c.Delimiter) split  ORDER BY ASCII_Value, split.ItemNumber;----------------------------------------------------------------------------------------------------------------------- Other Notes: 1. Optimized for VARCHAR(8000) or less.  No testing or error reporting for truncation at 8000 characters is done. 2. Optimized for single character delimiter.  Multi-character delimiters should be resolvedexternally from this     function. 3. Optimized for use with CROSS APPLY. 4. Does not "trim" elements just in case leading or trailing blanks are intended. 5. If you don't know how a Tally table can be used to replace loops, please see the following...    http://www.sqlservercentral.com/articles/T-SQL/62867/ 6. Changing this function to use NVARCHAR(MAX) will cause it to run twice as slow.  It's just the nature of     VARCHAR(MAX) whether it fits in-row or not. 7. Multi-machine testing for the method of using UNPIVOT instead of 10 SELECT/UNION ALLs shows that the UNPIVOT method    is quite machine dependent and can slow things down quite a bit.----------------------------------------------------------------------------------------------------------------------- Credits: This code is the product of many people's efforts including but not limited to the following: cteTally concept originally by Iztek Ben Gan and "decimalized" by Lynn Pettis (and others) for a bit of extra speed and finally redacted by Jeff Moden for a different slant on readability and compactness. Hat's off to Paul White for his simple explanations of CROSS APPLY and for his detailed testing efforts. Last but not least, thanks to Ron "BitBucket" McCullough and Wayne Sheffield for their extreme performance testing across multiple machines and versions of SQL Server.  The latest improvement brought an additional 15-20% improvement over Rev 05.  Special thanks to "Nadrek" and "peter-757102" (aka Peter de Heer) for bringing such improvements to light.  Nadrek's original improvement brought about a 10% performance gain and Peter followed that up with the content of Rev 07.   I also thank whoever wrote the first article I ever saw on "numbers tables" which is located at the following URL and to Adam Machanic for leading me to it many years ago. http://sqlserver2000.databases.aspfaq.com/why-should-i-consider-using-an-auxiliary-numbers-table.html----------------------------------------------------------------------------------------------------------------------- Revision History: Rev 00 - 20 Jan 2010 - Concept for inline cteTally: Lynn Pettis and others.                        Redaction/Implementation: Jeff Moden         - Base 10 redaction and reduction for CTE.  (Total rewrite) Rev 01 - 13 Mar 2010 - Jeff Moden        - Removed one additional concatenation and one subtraction from the SUBSTRING in the SELECT List for that tiny          bit of extra speed. Rev 02 - 14 Apr 2010 - Jeff Moden        - No code changes.  Added CROSS APPLY usage example to the header, some additional credits, and extra           documentation. Rev 03 - 18 Apr 2010 - Jeff Moden        - No code changes.  Added notes 7, 8, and 9 about certain "optimizations" that don't actually work for this          type of function. Rev 04 - 29 Jun 2010 - Jeff Moden        - Added WITH SCHEMABINDING thanks to a note by Paul White.  This prevents an unnecessary "Table Spool" when the          function is used in an UPDATE statement even though the function makes no external references. Rev 05 - 02 Apr 2011 - Jeff Moden        - Rewritten for extreme performance improvement especially for larger strings approaching the 8K boundary and          for strings that have wider elements.  The redaction of this code involved removing ALL concatenation of           delimiters, optimization of the maximum "N" value by using TOP instead of including it in the WHERE clause,          and the reduction of all previous calculations (thanks to the switch to a "zero based" cteTally) to just one           instance of one add and one instance of a subtract. The length calculation for the final element (not           followed by a delimiter) in the string to be split has been greatly simplified by using the ISNULL/NULLIF           combination to determine when the CHARINDEX returned a 0 which indicates there are no more delimiters to be          had or to start with. Depending on the width of the elements, this code is between 4 and 8 times faster on a          single CPU box than the original code especially near the 8K boundary.        - Modified comments to include more sanity checks on the usage example, etc.        - Removed "other" notes 8 and 9 as they were no longer applicable. Rev 06 - 12 Apr 2011 - Jeff Moden        - Based on a suggestion by Ron "Bitbucket" McCullough, additional test rows were added to the sample code and          the code was changed to encapsulate the output in pipes so that spaces and empty strings could be perceived           in the output.  The first "Notes" section was added.  Finally, an extra test was added to the comments above. Rev 07 - 06 May 2011 - Peter de Heer, a further 15-20% performance enhancement has been discovered and incorporated           into this code which also eliminated the need for a "zero" position in the cteTally table. **********************************************************************************************************************/--===== Define I/O parameters        (@pString VARCHAR(8000), @pDelimiter CHAR(1))RETURNS TABLE WITH SCHEMABINDING AS RETURN--===== "Inline" CTE Driven "Tally Table" produces values from 0 up to 10,000...     -- enough to cover NVARCHAR(4000)  WITH E1(N) AS (                 SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL                  SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL                  SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1                ),                          --10E+1 or 10 rows       E2(N) AS (SELECT 1 FROM E1 a, E1 b), --10E+2 or 100 rows       E4(N) AS (SELECT 1 FROM E2 a, E2 b), --10E+4 or 10,000 rows max cteTally(N) AS (--==== This provides the "base" CTE and limits the number of rows right up front                     -- for both a performance gain and prevention of accidental "overruns"                 SELECT TOP (ISNULL(DATALENGTH(@pString),0)) ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM E4                ),cteStart(N1) AS (--==== This returns N+1 (starting position of each "element" just once for each delimiter)                 SELECT 1 UNION ALL                 SELECT t.N+1 FROM cteTally t WHERE SUBSTRING(@pString,t.N,1) = @pDelimiter                ),cteLen(N1,L1) AS(--==== Return start and length (for use in substring)                 SELECT s.N1,                        ISNULL(NULLIF(CHARINDEX(@pDelimiter,@pString,s.N1),0)-s.N1,8000)                   FROM cteStart s                )--===== Do the actual split. The ISNULL/NULLIF combo handles the length for the final element when no delimiter is found. SELECT ItemNumber = ROW_NUMBER() OVER(ORDER BY l.N1),        Item       = SUBSTRING(@pString, l.N1, l.L1)   FROM cteLen l;GO[/code]</description><pubDate>Sat, 17 Nov 2012 11:59:27 GMT</pubDate><dc:creator>Lynn Pettis</dc:creator></item></channel></rss>