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 123»»»

INDEX REBUILD Expand / Collapse
Author
Message
Posted Monday, June 14, 2010 2:00 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 12:13 PM
Points: 178, Visits: 252
Here is what I did

1. Ran the following command

ALTER INDEX ALL ON APPOINTMENTS Rebuild;


2. Ran the following query

select index_id, avg_page_space_used_in_percent,
avg_fragmentation_in_percent
from
sys.dm_db_index_physical_stats( DB_ID('NGDEVL'), OBJECT_ID ('appointments'),NULL, NULL, 'DETAILED' )
WHERE
index_id <> 0



3. The results seems find except for one little problem ( Please see attached index.jpg)

Why is Sql server telling me that the avg_fragmentation_in_percent for index 1 is 75 ?

I thought after doing a rebuild it should say 0 for all indexes ?






  Post Attachments 
index.jpg (63 views, 34.42 KB)
Post #937110
Posted Monday, June 14, 2010 2:50 PM


SSC-Forever

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

Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 40,456, Visits: 36,912
How big is the index in question? How many pages?


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 #937139
Posted Monday, June 14, 2010 2:55 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 12:13 PM
Points: 178, Visits: 252
You will be surprised. This table does not have more than 100 rows.
Post #937145
Posted Monday, June 14, 2010 3:03 PM


SSC-Forever

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

Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 40,456, Visits: 36,912
Not surprised in the slightest, that's exactly what I expected.

For reasons that have to do with the way the first few pages are allocated, there's virtually no point in rebuilding an index that occupies less than 24 pages. It's generally recommended not to worry about fragmentation for indexes with less than 1000 pages.



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 #937148
Posted Monday, June 14, 2010 3:10 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 12:13 PM
Points: 178, Visits: 252
What would be the command to use to drop a particular index and then recreate it ?
What I mean is I'd like to build the index but not have to worry about the details ( how it was originally defined ).

Is there a general command available ?
Post #937153
Posted Monday, June 14, 2010 11:35 PM


SSC-Forever

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

Group: General Forum Members
Last Login: Yesterday @ 8:31 AM
Points: 40,456, Visits: 36,912
Drop/create?
Create index ... with drop existing?
Alter index ... disable/rebuild?

What's the point? What are you trying to achieve?



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 #937246
Posted Tuesday, June 15, 2010 1:20 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 1:11 AM
Points: 2,840, Visits: 3,976
mw112009 (6/14/2010)
What I mean is I'd like to build the index but not have to worry about the details
what does it mean ?


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #937280
Posted Tuesday, June 15, 2010 7:01 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 12:13 PM
Points: 178, Visits: 252
OK here is my point.
Lets go to the begining of this thread.

Here is what I did

1. Ran the following command
ALTER INDEX ALL ON APPOINTMENTS Rebuild;


2. Ran the following query

select index_id, avg_page_space_used_in_percent,
avg_fragmentation_in_percent
from
sys.dm_db_index_physical_stats( DB_ID('NGDEVL'), OBJECT_ID ('appointments'),NULL, NULL, 'DETAILED' )
WHERE
index_id <> 0


3. The query says that the fragmentation rate is 75 on index 1 ( I mean even after doing a rebuild why do a I get a fragmentation rate of 75 only on one particular index ? )

4. I also mentioned that the table had less than 100 rows.

5. So then why is SQl server returning wrong information ?

6. How else can we rebuild the indexes so that we get a fragmentation rate of 0 for all indexes. Is there another command out there that I don't know ( besides the Alter Index... Rebuild command )

Post #937455
Posted Tuesday, June 15, 2010 8:27 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: Yesterday @ 8:31 AM
Points: 40,456, Visits: 36,912
mw112009 (6/15/2010)
3. The query says that the fragmentation rate is 75 on index 1 ( I mean even after doing a rebuild why do a I get a fragmentation rate of 75 only on one particular index ? )

Because the index is too small for rebuild to have much if any effect.

4. I also mentioned that the table had less than 100 rows.

And i mentioned that it is not worth worrying about fragmentation for indexes under about 1000 pages

5. So then why is SQl server returning wrong information ?

It's not, it's perfectly correct, the fragmentation of that index is 75%

6. How else can we rebuild the indexes so that we get a fragmentation rate of 0 for all indexes. Is there another command out there that I don't know ( besides the Alter Index... Rebuild command )


There's no guarantee that any index rebuild of any form will leave you with 0% fragmentation. Don't worry about small amounts of fragmentation and don't worry about fragmentation on very small indexes. I'm willing to bet this index is 4 pages in size, well under the size where you should start worrying.



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 #937555
Posted Tuesday, June 15, 2010 8:38 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, October 14, 2014 12:13 PM
Points: 178, Visits: 252
So is there a command out there that I can use to count the size of the index in pages ?
You mentioned the size of the above index may be less than 4 pages ? How do we find that out ?

Post #937568
« Prev Topic | Next Topic »

Add to briefcase 123»»»

Permissions Expand / Collapse