Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
rebuild index worsens query performance
52 posts, Page 1 of 6
1
2
3
4
5
»
»»
rebuild index worsens query performance
Rate Topic
Display Mode
Topic Options
Author
Message
jgenovese
jgenovese
Posted Friday, November 16, 2012 10:34 AM
SSC Rookie
Group: General Forum Members
Last Login: Friday, December 07, 2012 3:23 PM
Points: 42,
Visits: 238
we have a query which runs several times a day
reads from several tables in one database ("W"), and two tables in another database ("P") (both db's reside on the same server)
the two tables in database "P" never had their indexes rebuilt or statistics updated, and were significantly fragmented
I purged some old information from another table in database "P" (about 50% worth), and shrank database "P" (to reclaim disk space which we were running out of)
I rebuilt the indexes/updated statistics in "P" immediately afterward, and now weekly, via a maintenance plan (rebuild index task [original amount of free space], update statistics task [column stats only, initially at 10%, then 50% weekly])
From that point forward the aforementioned query takes twice as long to run
Thoughts?
FYI:
the two tables in the query, and the table I purged, are subscribed tables in replication, the publisher being on another server in the same domain
I dropped replication on the purged table, purged it on both the publisher and subscriber, and re-created replicarecreatedthe "replication support only" option
the two tables in the query had replication active the whole time (purge of the third table, shrink, index rebuild, etc.) -- no information was flowing at that time
database "P" has not expanded since the shrink
a comparison (via RedGate Compare) between the database pre-purge/shrink/index rebuild and present show no structural differences between the two tables used by the query
Is it possible that the plan the query was using prior to the index rebuild was running faster despite the fragmentation? I would think that any reduction in index fragmentation would be cause for improvement in query performance
*** UPDATE (11-20-2012) -- it was determined that, on that day, I rebuilt indexes but NOT stats -- update stats came 2 weeks later and made no difference either way
Post #1385783
GSquared
GSquared
Posted Friday, November 16, 2012 10:50 AM
SSCoach
Group: General Forum Members
Last Login: 2 days ago @ 1:55 PM
Points: 15,442,
Visits: 9,571
Index defragmentation shouldn't cause a performance degradation, but it won't necessarily speed things up either. It depends on how the index is being used.
Single-row seeks, for example, aren't significantly impacted by fragmentation.
Before I can suggest anything about the issue, I'd need to see the execution plan at the very least. Table definitions and the query are usually also needed, but the execution plan is the bare minimum. Can you attach that as an sqlplan file? (Don't copy-and-paste the XML into the forum, in other words. Save the plan as a file and attach that to a post in the forum.)
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1385787
jgenovese
jgenovese
Posted Friday, November 16, 2012 12:08 PM
SSC Rookie
Group: General Forum Members
Last Login: Friday, December 07, 2012 3:23 PM
Points: 42,
Visits: 238
note: the emphasis is on what happened when the aforementioned operations were performed on database "P" such that the query doubled in run time, not so much on what code to change in order to improve performance
the 1st letter of the two databases in the plan will be either "W" or "P" (per opening post)
Post Attachments
query_plan1c - Copy.sqlplan
(
22 views,
241.53 KB
)
Post #1385819
Lynn Pettis
Lynn Pettis
Posted Friday, November 16, 2012 9:48 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:36 AM
Points: 21,617,
Visits: 27,451
After completing the index rebuild, did you then rebuild all the statistics? If so did you use a sample size or full scan?
If you used a sample size on the statistics for the indexes you rebuilt, you made them worse. The statistics for the indexes are rebuilt when you rebuild the indexes and is done with a full scan, meaning the statistics were better before you rebuilt the statistics separately.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1385901
jgenovese
jgenovese
Posted Saturday, November 17, 2012 6:29 AM
SSC Rookie
Group: General Forum Members
Last Login: Friday, December 07, 2012 3:23 PM
Points: 42,
Visits: 238
I dont think I rebuilt stats that day,just the indexes.
I added a update stats task to the maint plan about a week later (after the index rebuild), however it updates COLUMN stats only -- my understanding is that index rebuild updates TABLE stats but not COLUMN stats, correct me if I'm wrong
Post #1385935
Jeff Moden
Jeff Moden
Posted Saturday, November 17, 2012 6:39 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 5:13 AM
Points: 32,906,
Visits: 26,793
I suppose that it's possible that an index rebuild could cause a slow down of this nature because of the stats rebuild that also occurs. That may have caused the execution plan to change. I've also see that adding an index (found this out in the code for one of my articles) can cause code to run much slower. The optimizer isn't magic... it was written by humans and it sometimes makes bad choices.
Whatever was the cause, I think you're now to the point where you have to treat it like a new query and tune it. If you want, check the article at the second link in my signature below for how to post what folks need to help you for such problems.
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #1385938
Lynn Pettis
Lynn Pettis
Posted Saturday, November 17, 2012 10:52 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:36 AM
Points: 21,617,
Visits: 27,451
I have to agree with Jeff at this point. I have looked at the estimated execution plan, but one of the things we really need is the actual execution plan from the slow running process. That is in addition to the information also mentioned in the article Jeff recommended you read.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1385956
Lynn Pettis
Lynn Pettis
Posted Saturday, November 17, 2012 10:56 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 6:36 AM
Points: 21,617,
Visits: 27,451
Taking a guess here, but is the table valued function you use in this process a multi-statement table valued function?
Also, looks like you may have several scalar functions being used, are this in the select list of any tables queried or in the where or join clauses between tables?
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #1385958
jgenovese
jgenovese
Posted Saturday, November 17, 2012 11:01 AM
SSC Rookie
Group: General Forum Members
Last Login: Friday, December 07, 2012 3:23 PM
Points: 42,
Visits: 238
that IS the actual plan:
select
(SELECT SUBSTRING(text, r.statement_start_offset/2,(CASE WHEN r.statement_end_offset = -1 THEN LEN(CONVERT(nvarchar(max), text)) * 2 ELSE r.statement_end_offset END - r.statement_start_offset)/2 ) FROM sys.dm_exec_sql_text(r.sql_handle) ) AS query_text
,
(SELECT convert(xml, query_plan) FROM sys.dm_exec_text_query_plan (r.plan_handle , r.statement_start_offset, r.statement_end_offset )) AS query_plan
--,
--(SELECT query_plan FROM sys.dm_exec_query_plan (r.plan_handle )) AS query_plan_batch
-- , qs.*
from sys.dm_exec_requests r
left join sys.dm_exec_query_stats qs
on r.statement_start_offset = qs.statement_start_offset
and r.sql_handle = qs.sql_handle
where 1=1
and session_id = ...
Post #1385959
jgenovese
jgenovese
Posted Saturday, November 17, 2012 11:02 AM
SSC Rookie
Group: General Forum Members
Last Login: Friday, December 07, 2012 3:23 PM
Points: 42,
Visits: 238
I believe it is multi-line
Note that the query did not change -- the emphasis is on what could have happened that weekend that caused the query to double in time
Post #1385960
« Prev Topic
|
Next Topic »
52 posts, Page 1 of 6
1
2
3
4
5
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.