Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Slow performance remains after query rebuild only gets resolved after updting statistics ? Expand / Collapse
Author
Message
Posted Tuesday, January 15, 2013 8:32 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 7:46 AM
Points: 331, Visits: 879
1 of the query's of a colleague of mine has been slowing down recently.
He looked to the execution plans and the index fragmentation and found a fragmented index, which he then rebuild.
No resolve, fragmentation was gone but the performance remained slow.

He then did an update statistics which resolved it.
Now I'm confused,and the the things I found searching about it are contradicting.

If you rebuild an index the statistics get updated,is this the case or not.
I've requested more info on the table and query.

But anyone who can tell me why you would need an update statistics after an index rebuild please do.
Is there a way to check all statistics of a table
Post #1407298
Posted Wednesday, January 16, 2013 12:23 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
USE AdventureWorks2012;

DECLARE @schema_name SYSNAME,
@table_name SYSNAME;

SELECT @schema_name = N'HumanResources',
@table_name = N'Department';

SELECT st.name AS StatsName,
STATS_DATE(st.object_id, st.stats_id) AS [LastUpdated]
FROM sys.objects AS tbl
INNER JOIN sys.stats st ON st.object_id = tbl.object_id
WHERE tbl.name = @table_name
AND SCHEMA_NAME(tbl.schema_id) = @schema_name;



__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1407633
Posted Wednesday, January 16, 2013 12:39 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 3:40 PM
Points: 1,077, Visits: 1,496
It wasn't the statistics that fixed the issue, it was the query plan being invalidated and recompiled (ie. new plan).

From BOL:
http://msdn.microsoft.com/en-us/library/ms187348%28v=sql.105%29.aspx
Updating statistics ensures that queries compile with up-to-date statistics. However, updating statistics causes queries to recompile. We recommend not updating statistics too frequently because there is a performance tradeoff between improving query plans and the time it takes to recompile queries.


Also see
http://www.sqlskills.com/blogs/kimberly/what-caused-that-plan-to-go-horribly-wrong-should-you-update-statistics/
Post #1407634
Posted Wednesday, January 16, 2013 12:42 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
foxxo (1/16/2013)
It wasn't the statistics that fixed the issue, it was the query being recompiled (ie. new plan).

From BOL:
http://msdn.microsoft.com/en-us/library/ms187348.aspx
Updating statistics ensures that queries compile with up-to-date statistics. However, updating statistics causes queries to recompile. We recommend not updating statistics too frequently because there is a performance tradeoff between improving query plans and the time it takes to recompile queries.


rebuilding an index automatically rebuilds the statistics on that index


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1407637
Posted Wednesday, January 16, 2013 12:44 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:52 AM
Points: 41,530, Visits: 34,446
Could well be that the stats that the query depends on are column stats, not index stats. REbuilding an index only updates the stats associated with that index (and invalidates any plans that use it)


Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1407638
Posted Wednesday, January 16, 2013 12:48 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Wednesday, April 16, 2014 9:25 AM
Points: 7,070, Visits: 12,523
Column stats is the likely reason given the info.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato

Believe you can and you're halfway there. --Theodore Roosevelt

Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein

The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein

1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
Post #1407643
Posted Wednesday, January 16, 2013 1:19 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 7:46 AM
Points: 331, Visits: 879
GilaMonster (1/16/2013)
Could well be that the stats that the query depends on are column stats, not index stats. REbuilding an index only updates the stats associated with that index (and invalidates any plans that use it)

opc.three (1/16/2013)
Column stats is the likely reason given the info.


From the data I have and I've requested more an out of date statistic that is not part of the index he rebuild is the most likely cause of the problems. (I've came to the conclusion of this yesterday)
Post #1407659
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse