Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


INDEX REBUILD


INDEX REBUILD

Author
Message
mw112009
mw112009
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 921
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 ?
Attachments
index.jpg (77 views, 34.00 KB)
GilaMonster
GilaMonster
SSC Guru
SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)

Group: General Forum Members
Points: 75510 Visits: 45025
How big is the index in question? How many pages?

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
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


mw112009
mw112009
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 921
You will be surprised. This table does not have more than 100 rows.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)

Group: General Forum Members
Points: 75510 Visits: 45025
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, MVP, M.Sc (Comp Sci)
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


mw112009
mw112009
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 921
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 ?
GilaMonster
GilaMonster
SSC Guru
SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)

Group: General Forum Members
Points: 75510 Visits: 45025
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, MVP, M.Sc (Comp Sci)
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


Bhuvnesh
Bhuvnesh
SSCarpal Tunnel
SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)SSCarpal Tunnel (4.6K reputation)

Group: General Forum Members
Points: 4622 Visits: 4076
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;-)
mw112009
mw112009
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 921
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 )
GilaMonster
GilaMonster
SSC Guru
SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)SSC Guru (75K reputation)

Group: General Forum Members
Points: 75510 Visits: 45025
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, MVP, M.Sc (Comp Sci)
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


mw112009
mw112009
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 921
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 ?
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search