Showing posts with label execute. Show all posts
Showing posts with label execute. Show all posts

Thursday, March 29, 2012

DBCC ShrinkFile

How long does it take to execute DBCC Shrinkfile(DB_FILE, emptyfile) on a 10GB datafiles? If you put your datafiles together with the tempdb datafiles on the same logical drive do we have a performance issue?

Thanks

The time taken for this activity is depends.

THe other part of ur question, Temp db should always be in seperate physical drive if possible for better performance. Datafile is Random read/write but temp db will have moreor less sequential read./write. So if u keep both in same drive it will have performance hit

http://www.microsoft.com/technet/prodtechnol/sql/bestpractice/tempdb_capacity_planning_index.mspx

http://msdn2.microsoft.com/en-us/library/ms345368.aspx

Madhu

Sunday, March 25, 2012

DBCC SHOWCONTIG (No Lock)

Is there away to execute the DBCC SHOWCONTIG without this program creating a
table lock?
Thank You,
I think that the FAST option will take a light-weight lock (if any). And it is a lot faster.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Joe K." <JoeK@.discussions.microsoft.com> wrote in message
news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
> Is there away to execute the DBCC SHOWCONTIG without this program creating a
> table lock?
> Thank You,
|||The FAST option will only take a table IS lock rather than a table S lock.
That's as non-blocking as it can do.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:unLlLucvEHA.3640@.TK2MSFTNGP10.phx.gbl...
> I think that the FAST option will take a light-weight lock (if any). And
it is a lot faster.[vbcol=seagreen]
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Joe K." <JoeK@.discussions.microsoft.com> wrote in message
> news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
creating a
>

DBCC SHOWCONTIG (No Lock)

Is there away to execute the DBCC SHOWCONTIG without this program creating a
table lock?
Thank You,I think that the FAST option will take a light-weight lock (if any). And it
is a lot faster.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Joe K." <JoeK@.discussions.microsoft.com> wrote in message
news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
> Is there away to execute the DBCC SHOWCONTIG without this program creating
a
> table lock?
> Thank You,|||The FAST option will only take a table IS lock rather than a table S lock.
That's as non-blocking as it can do.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:unLlLucvEHA.3640@.TK2MSFTNGP10.phx.gbl...
> I think that the FAST option will take a light-weight lock (if any). And
it is a lot faster.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Joe K." <JoeK@.discussions.microsoft.com> wrote in message
> news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
creating a[vbcol=seagreen]
>

DBCC SHOWCONTIG (No Lock)

Is there away to execute the DBCC SHOWCONTIG without this program creating a
table lock?
Thank You,I think that the FAST option will take a light-weight lock (if any). And it is a lot faster.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Joe K." <JoeK@.discussions.microsoft.com> wrote in message
news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
> Is there away to execute the DBCC SHOWCONTIG without this program creating a
> table lock?
> Thank You,|||The FAST option will only take a table IS lock rather than a table S lock.
That's as non-blocking as it can do.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:unLlLucvEHA.3640@.TK2MSFTNGP10.phx.gbl...
> I think that the FAST option will take a light-weight lock (if any). And
it is a lot faster.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Joe K." <JoeK@.discussions.microsoft.com> wrote in message
> news:C763E461-B833-4DBF-B8E9-E7222F73DB4F@.microsoft.com...
> >
> > Is there away to execute the DBCC SHOWCONTIG without this program
creating a
> > table lock?
> >
> > Thank You,
>

Monday, March 19, 2012

DBCC MEMORYSTATUS

Dear all,
How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
Computer.
I dont want to connect my Query Analyser to the server i want to get
information.
thanx
Doller
EXEC TIBWORK.master.dbo.sp_executesql N'DBCC MEMORYSTATUS'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"doller" <sufianarif@.gmail.com> wrote in message
news:1142663795.418452.123220@.e56g2000cwe.googlegr oups.com...
> Dear all,
> How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
> Computer.
> I dont want to connect my Query Analyser to the server i want to get
> information.
> thanx
> Doller
>
|||HI Thanx

DBCC MEMORYSTATUS

Dear all,
How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
Computer.
I dont want to connect my Query Analyser to the server i want to get
information.
thanx
DollerEXEC TIBWORK.master.dbo.sp_executesql N'DBCC MEMORYSTATUS'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"doller" <sufianarif@.gmail.com> wrote in message
news:1142663795.418452.123220@.e56g2000cwe.googlegroups.com...
> Dear all,
> How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
> Computer.
> I dont want to connect my Query Analyser to the server i want to get
> information.
> thanx
> Doller
>|||HI Thanx

DBCC MEMORYSTATUS

Dear all,
How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
Computer.
I dont want to connect my Query Analyser to the server i want to get
information.
thanx
DollerEXEC TIBWORK.master.dbo.sp_executesql N'DBCC MEMORYSTATUS'
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
Blog: http://solidqualitylearning.com/blogs/tibor/
"doller" <sufianarif@.gmail.com> wrote in message
news:1142663795.418452.123220@.e56g2000cwe.googlegroups.com...
> Dear all,
> How can i execute DBCC MEMORYSTATUS command on Linked server or Remote
> Computer.
> I dont want to connect my Query Analyser to the server i want to get
> information.
> thanx
> Doller
>|||HI Thanx

Sunday, March 11, 2012

DBCC INDEXDEFRAG

I have SQL Server 2000 Enterprise Edition on my server.
I first execute DBCC SHOWCONTIG on my database.
Which outputs logicaldefrag, scan density, and etc.
I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
every table in my database.
Next I apply the sp_updatestats.
Lastly, I execute DBCC SHOWCONTIG to the database.
When I compare the DBCC SHOWCONTIG before and after
results from applying DBCC INDEXDEFRAG. I noticed the
logicalfrag has the same values?
Please help me fix this issue.
Thanks,
Mike
Well a couple things comes to mind. First off do these tables all have a
clustered index on them? How many pages in these tables? Can you show an
example of before and after?
Andrew J. Kelly SQL MVP
"Mike" <anonymous@.discussions.microsoft.com> wrote in message
news:27d5a01c46449$23fbc7f0$a601280a@.phx.gbl...
> I have SQL Server 2000 Enterprise Edition on my server.
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
> Please help me fix this issue.
> Thanks,
> Mike
|||"Mike" wrote:
> [...]
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
>
Mike,
I have noticed the same thing with indexes on large tables. I'm using the sample script from Books Online to run a nightly DBCC INDEXDEFRAG on indexes with higher than a certain level of fragmentation, but I notice that certain indexes are above the t
hreshold every night. If I run a DBCC DBREINDEX, I have much better results (the fragmentation usually goes down below 1%).
Normally, I would think it was my own mistake... but the strange thing is that many indexes seem to have their fragmentation reduced when running DBCC INDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for my data warehouse DBs...
Regards,
Jonathan
|||What's the reported number of pages moved when running DBCC INDEXDEFRAG? Can
you post sample DBCC SHOWCONTIG output please?
Thanks
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> "Mike" wrote:
> Mike,
> I have noticed the same thing with indexes on large tables. I'm using
the sample script from Books Online to run a nightly DBCC INDEXDEFRAG on
indexes with higher than a certain level of fragmentation, but I notice that
certain indexes are above the threshold every night. If I run a DBCC
DBREINDEX, I have much better results (the fragmentation usually goes down
below 1%).
> Normally, I would think it was my own mistake... but the strange thing
is that many indexes seem to have their fragmentation reduced when running
DBCC INDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for
my data warehouse DBs...
> Regards,
> Jonathan
|||Paul,
"Paul S Randal [MS]" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> What's the reported number of pages moved when running DBCC INDEXDEFRAG? Can
> you post sample DBCC SHOWCONTIG output please?
Thanks for your reply.
I'm still looking into this myself, and it's a bit more complicated than I originally reported.
I have a data warehouse that's updated early in the morning. The larger tables are in the order of 5 to 25 million rows. The updates vary in size from 100,000 to 2 million rows.
Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the update, and it's after the update that the index appears to be refragmented. So, for example, on a 26 million row table:
Before Defrag:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 121895
- Extents Scanned.......................: 15316
- Extent Switches.......................: 88061
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.30% [15237:88062]
- Logical Scan Fragmentation ..............: 25.04%
- Extent Scan Fragmentation ...............: 44.72%
- Avg. Bytes Free per Page................: 3012.7
- Avg. Page Density (full)................: 62.78%
INDEXDEFRAG scanned 121891, moved 76889, removed 44996
After defrag:
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 76899
- Extents Scanned.......................: 9670
- Extent Switches.......................: 37754
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
- Logical Scan Fragmentation ..............: 0.01%
- Extent Scan Fragmentation ...............: 61.40%
- Avg. Bytes Free per Page................: 38.3
- Avg. Page Density (full)................: 99.53%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
After inserting 270,000 rows:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 123077
- Extents Scanned.......................: 15464
- Extent Switches.......................: 88745
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
- Logical Scan Fragmentation ..............: 26.34%
- Extent Scan Fragmentation ...............: 65.66%
- Avg. Bytes Free per Page................: 3009.3
- Avg. Page Density (full)................: 62.82%
So... it's very strange to me that, after inserting about 1% new rows, and not deleting or updating any rows, the fragmentation could go from .01% to 26.34%.
I haven't had a chance to fully document this yet, but it seems to me that DBREINDEX results in a substantially better Scan Density, and that subsequent inserts do not result in such extreme changes in Logical Scan Fragmentation. If you think it's helpfu
l, I'll pursue that.
Regards,
Jonathan
|||> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation >could go from .01% to
26.34%.
This isn't strange at all since your pages are basically 100% full before
the inserts. That means that almost any insert will cause a page split and
the results of the showcontig shows that there was a lot of it. If your
going to do a lot of inserts you should consider setting an appropriate fill
factor and possibly Padindex as well. Leaving more free space on the page
will mean more pages in the database but will result in less pagesplits and
lots less work during the inserts.
Andrew J. Kelly SQL MVP
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...[vbcol=seagreen]
> Paul,
> "Paul S Randal [MS]" wrote:
Can
> Thanks for your reply.
> I'm still looking into this myself, and it's a bit more complicated than I
originally reported.
> I have a data warehouse that's updated early in the morning. The larger
tables are in the order of 5 to 25 million rows. The updates vary in size
from 100,000 to 2 million rows.
> Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the
update, and it's after the update that the index appears to be refragmented.
So, for example, on a 26 million row table:
> Before Defrag:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 121895
> - Extents Scanned.......................: 15316
> - Extent Switches.......................: 88061
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.30% [15237:88062]
> - Logical Scan Fragmentation ..............: 25.04%
> - Extent Scan Fragmentation ...............: 44.72%
> - Avg. Bytes Free per Page................: 3012.7
> - Avg. Page Density (full)................: 62.78%
> INDEXDEFRAG scanned 121891, moved 76889, removed 44996
> After defrag:
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 76899
> - Extents Scanned.......................: 9670
> - Extent Switches.......................: 37754
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
> - Logical Scan Fragmentation ..............: 0.01%
> - Extent Scan Fragmentation ...............: 61.40%
> - Avg. Bytes Free per Page................: 38.3
> - Avg. Page Density (full)................: 99.53%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> After inserting 270,000 rows:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 123077
> - Extents Scanned.......................: 15464
> - Extent Switches.......................: 88745
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
> - Logical Scan Fragmentation ..............: 26.34%
> - Extent Scan Fragmentation ...............: 65.66%
> - Avg. Bytes Free per Page................: 3009.3
> - Avg. Page Density (full)................: 62.82%
> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation could go from .01% to
26.34%.
> I haven't had a chance to fully document this yet, but it seems to me that
DBREINDEX results in a substantially better Scan Density, and that
subsequent inserts do not result in such extreme changes in Logical Scan
Fragmentation. If you think it's helpful, I'll pursue that.
> Regards,
> Jonathan
|||"Andrew J. Kelly" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> system administrator.
> This isn't strange at all since your pages are basically 100% full before
> the inserts. That means that almost any insert will cause a page split and
> the results of the showcontig shows that there was a lot of it. If your
> going to do a lot of inserts you should consider setting an appropriate fill
> factor and possibly Padindex as well. Leaving more free space on the page
> will mean more pages in the database but will result in less pagesplits and
> lots less work during the inserts.
Hi Andrew.
I guess that 270K inserts seems like a lot in absolute terms, but relative to the size of the table, it's pretty small. So I guess I'm surprised that one in 6 inserts would cause a page split when I'm changing the table by only 1%. I'm also suprised tha
t simply splitting pages would cause the fragmentation to increase so dramatically.
I had originally created the index with no FILLFACTOR specified. (I thought this was supposed to default to a FILLFACTOR of 80). On your suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to 80. Now DBCC SHOWCONTIG returns:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 96535
- Extents Scanned.......................: 12114
- Extent Switches.......................: 12113
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
- Logical Scan Fragmentation ..............: 0.02%
- Extent Scan Fragmentation ...............: 49.70%
- Avg. Bytes Free per Page................: 1610.7
- Avg. Page Density (full)................: 80.10%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Note the great improvement in the index's Scan Density. And I also see this kind of improvement in Scan Density when I run DBCC DBREINDEX.
So... I'll keep an eye on it for the next few days. I'll also check into whether my other big indexes have similar FILLFACTOR issues. In the meantime, is Scan Density something that I should be worrying about?
|||> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm >surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also surprised that simply
> splitting pages would cause the fragmentation to increase so dramatically.
>
When a page is that full (or usually even close) just one new row will cause
a page split since there simply isn't enough room for the new data. A
non-clustered index is essentially a table with a clustered index on the
index expression. That means the data at the leaf level have to basically
be in physical order. So when the data coming in is random (meaning the
value of the column(s) the index is based on) it usually gets placed in
between existing rows. If there is not enough room on the page it splits it
and moves half to another page. When you add new rows in index expression
order (such as a datetime that is in chronological order) they can simply be
appended to the end of the current page. When that page is full it creates
a new page and continues appending from there. This is not a page split and
essentially does not change the logical fragmentation since all the new
pages come directly after the previous ones. This KB is great for this type
stuff:
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx

> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
Logical fragmentation is the most important factor that you should be
worried about. Especially if you have more than 1 file in the filegroup. In
that case Logical is the only one that you can really trust anyway. See the
KB I mentioned.
Andrew J. Kelly SQL MVP
|||Andrew's explanations are spot on.
Why do you consider Scan Density so important? What's the access pattern
over this index?
Do you notice query performance dropping after the insert activity? It's
entirely possible that everything you're doing is a waste of time - akin to
continually shrinking a database after it grows every day. Please read the
whitepaper below which explains a bunch about when to take action on
fragmentation.
http://www.microsoft.com/technet/pro.../ss2kidbp.mspx
Thanks and regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:05DA17D7-942D-452A-8973-ACCB2DB7A98C@.microsoft.com...[vbcol=seagreen]
> "Andrew J. Kelly" wrote:
8[vbcol=seagreen]
8[vbcol=seagreen]
and[vbcol=seagreen]
..01% to[vbcol=seagreen]
before[vbcol=seagreen]
and[vbcol=seagreen]
fill[vbcol=seagreen]
page[vbcol=seagreen]
and
> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also suprised that simply splitting pages would cause the
fragmentation to increase so dramatically.
> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
>
>
|||Thanks, Andrew. Very helpful stuff.
-- J

DBCC INDEXDEFRAG

I have SQL Server 2000 Enterprise Edition on my server.
I first execute DBCC SHOWCONTIG on my database.
Which outputs logicaldefrag, scan density, and etc.
I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
every table in my database.
Next I apply the sp_updatestats.
Lastly, I execute DBCC SHOWCONTIG to the database.
When I compare the DBCC SHOWCONTIG before and after
results from applying DBCC INDEXDEFRAG. I noticed the
logicalfrag has the same values?
Please help me fix this issue.
Thanks,
MikeWell a couple things comes to mind. First off do these tables all have a
clustered index on them? How many pages in these tables? Can you show an
example of before and after?
--
Andrew J. Kelly SQL MVP
"Mike" <anonymous@.discussions.microsoft.com> wrote in message
news:27d5a01c46449$23fbc7f0$a601280a@.phx.gbl...
> I have SQL Server 2000 Enterprise Edition on my server.
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
> Please help me fix this issue.
> Thanks,
> Mike|||"Mike" wrote:
> [...]
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
>
Mike,
I have noticed the same thing with indexes on large tables. I'm using the sample script from Books Online to run a nightly DBCC INDEXDEFRAG on indexes with higher than a certain level of fragmentation, but I notice that certain indexes are above the threshold every night. If I run a DBCC DBREINDEX, I have much better results (the fragmentation usually goes down below 1%).
Normally, I would think it was my own mistake... but the strange thing is that many indexes seem to have their fragmentation reduced when running DBCC INDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for my data warehouse DBs...
Regards,
Jonathan|||What's the reported number of pages moved when running DBCC INDEXDEFRAG? Can
you post sample DBCC SHOWCONTIG output please?
Thanks
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> "Mike" wrote:
> > [...]
> > I first execute DBCC SHOWCONTIG on my database.
> >
> > Which outputs logicaldefrag, scan density, and etc.
> >
> > I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> > every table in my database.
> >
> > Next I apply the sp_updatestats.
> >
> > Lastly, I execute DBCC SHOWCONTIG to the database.
> >
> > When I compare the DBCC SHOWCONTIG before and after
> > results from applying DBCC INDEXDEFRAG. I noticed the
> > logicalfrag has the same values?
> >
> Mike,
> I have noticed the same thing with indexes on large tables. I'm using
the sample script from Books Online to run a nightly DBCC INDEXDEFRAG on
indexes with higher than a certain level of fragmentation, but I notice that
certain indexes are above the threshold every night. If I run a DBCC
DBREINDEX, I have much better results (the fragmentation usually goes down
below 1%).
> Normally, I would think it was my own mistake... but the strange thing
is that many indexes seem to have their fragmentation reduced when running
DBCC INDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for
my data warehouse DBs...
> Regards,
> Jonathan|||Paul,
"Paul S Randal [MS]" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> What's the reported number of pages moved when running DBCC INDEXDEFRAG? Can
> you post sample DBCC SHOWCONTIG output please?
Thanks for your reply.
I'm still looking into this myself, and it's a bit more complicated than I originally reported.
I have a data warehouse that's updated early in the morning. The larger tables are in the order of 5 to 25 million rows. The updates vary in size from 100,000 to 2 million rows.
Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the update, and it's after the update that the index appears to be refragmented. So, for example, on a 26 million row table:
Before Defrag:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 121895
- Extents Scanned.......................: 15316
- Extent Switches.......................: 88061
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.30% [15237:88062]
- Logical Scan Fragmentation ..............: 25.04%
- Extent Scan Fragmentation ...............: 44.72%
- Avg. Bytes Free per Page................: 3012.7
- Avg. Page Density (full)................: 62.78%
INDEXDEFRAG scanned 121891, moved 76889, removed 44996
After defrag:
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 76899
- Extents Scanned.......................: 9670
- Extent Switches.......................: 37754
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
- Logical Scan Fragmentation ..............: 0.01%
- Extent Scan Fragmentation ...............: 61.40%
- Avg. Bytes Free per Page................: 38.3
- Avg. Page Density (full)................: 99.53%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
After inserting 270,000 rows:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 123077
- Extents Scanned.......................: 15464
- Extent Switches.......................: 88745
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
- Logical Scan Fragmentation ..............: 26.34%
- Extent Scan Fragmentation ...............: 65.66%
- Avg. Bytes Free per Page................: 3009.3
- Avg. Page Density (full)................: 62.82%
So... it's very strange to me that, after inserting about 1% new rows, and not deleting or updating any rows, the fragmentation could go from .01% to 26.34%.
I haven't had a chance to fully document this yet, but it seems to me that DBREINDEX results in a substantially better Scan Density, and that subsequent inserts do not result in such extreme changes in Logical Scan Fragmentation. If you think it's helpful, I'll pursue that.
Regards,
Jonathan|||> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation >could go from .01% to
26.34%.
This isn't strange at all since your pages are basically 100% full before
the inserts. That means that almost any insert will cause a page split and
the results of the showcontig shows that there was a lot of it. If your
going to do a lot of inserts you should consider setting an appropriate fill
factor and possibly Padindex as well. Leaving more free space on the page
will mean more pages in the database but will result in less pagesplits and
lots less work during the inserts.
--
Andrew J. Kelly SQL MVP
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> Paul,
> "Paul S Randal [MS]" wrote:
> > "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> > news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> > What's the reported number of pages moved when running DBCC INDEXDEFRAG?
Can
> > you post sample DBCC SHOWCONTIG output please?
> Thanks for your reply.
> I'm still looking into this myself, and it's a bit more complicated than I
originally reported.
> I have a data warehouse that's updated early in the morning. The larger
tables are in the order of 5 to 25 million rows. The updates vary in size
from 100,000 to 2 million rows.
> Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the
update, and it's after the update that the index appears to be refragmented.
So, for example, on a 26 million row table:
> Before Defrag:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 121895
> - Extents Scanned.......................: 15316
> - Extent Switches.......................: 88061
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.30% [15237:88062]
> - Logical Scan Fragmentation ..............: 25.04%
> - Extent Scan Fragmentation ...............: 44.72%
> - Avg. Bytes Free per Page................: 3012.7
> - Avg. Page Density (full)................: 62.78%
> INDEXDEFRAG scanned 121891, moved 76889, removed 44996
> After defrag:
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 76899
> - Extents Scanned.......................: 9670
> - Extent Switches.......................: 37754
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
> - Logical Scan Fragmentation ..............: 0.01%
> - Extent Scan Fragmentation ...............: 61.40%
> - Avg. Bytes Free per Page................: 38.3
> - Avg. Page Density (full)................: 99.53%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> After inserting 270,000 rows:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 123077
> - Extents Scanned.......................: 15464
> - Extent Switches.......................: 88745
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
> - Logical Scan Fragmentation ..............: 26.34%
> - Extent Scan Fragmentation ...............: 65.66%
> - Avg. Bytes Free per Page................: 3009.3
> - Avg. Page Density (full)................: 62.82%
> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation could go from .01% to
26.34%.
> I haven't had a chance to fully document this yet, but it seems to me that
DBREINDEX results in a substantially better Scan Density, and that
subsequent inserts do not result in such extreme changes in Logical Scan
Fragmentation. If you think it's helpful, I'll pursue that.
> Regards,
> Jonathan|||"Andrew J. Kelly" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> > After defrag:
> >
> > Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> > LEAF level scan performed.
> > - Pages Scanned........................: 76899
> > - Extents Scanned.......................: 9670
> > - Extent Switches.......................: 37754
> > - Avg. Pages per Extent..................: 8.0
> > - Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
> > - Logical Scan Fragmentation ..............: 0.01%
> > - Extent Scan Fragmentation ...............: 61.40%
> > - Avg. Bytes Free per Page................: 38.3
> > - Avg. Page Density (full)................: 99.53%
> > DBCC execution completed. If DBCC printed error messages, contact your
> system administrator.
> >
> > After inserting 270,000 rows:
> > DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> > Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> > LEAF level scan performed.
> > - Pages Scanned........................: 123077
> > - Extents Scanned.......................: 15464
> > - Extent Switches.......................: 88745
> > - Avg. Pages per Extent..................: 8.0
> > - Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
> > - Logical Scan Fragmentation ..............: 26.34%
> > - Extent Scan Fragmentation ...............: 65.66%
> > - Avg. Bytes Free per Page................: 3009.3
> > - Avg. Page Density (full)................: 62.82%
> >
> > So... it's very strange to me that, after inserting about 1% new rows, and
> > not deleting or updating any rows, the fragmentation could go from .01% to
> > 26.34%.
> >
> This isn't strange at all since your pages are basically 100% full before
> the inserts. That means that almost any insert will cause a page split and
> the results of the showcontig shows that there was a lot of it. If your
> going to do a lot of inserts you should consider setting an appropriate fill
> factor and possibly Padindex as well. Leaving more free space on the page
> will mean more pages in the database but will result in less pagesplits and
> lots less work during the inserts.
Hi Andrew.
I guess that 270K inserts seems like a lot in absolute terms, but relative to the size of the table, it's pretty small. So I guess I'm surprised that one in 6 inserts would cause a page split when I'm changing the table by only 1%. I'm also suprised that simply splitting pages would cause the fragmentation to increase so dramatically.
I had originally created the index with no FILLFACTOR specified. (I thought this was supposed to default to a FILLFACTOR of 80). On your suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to 80. Now DBCC SHOWCONTIG returns:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 96535
- Extents Scanned.......................: 12114
- Extent Switches.......................: 12113
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
- Logical Scan Fragmentation ..............: 0.02%
- Extent Scan Fragmentation ...............: 49.70%
- Avg. Bytes Free per Page................: 1610.7
- Avg. Page Density (full)................: 80.10%
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
Note the great improvement in the index's Scan Density. And I also see this kind of improvement in Scan Density when I run DBCC DBREINDEX.
So... I'll keep an eye on it for the next few days. I'll also check into whether my other big indexes have similar FILLFACTOR issues. In the meantime, is Scan Density something that I should be worrying about?|||> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm >surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also surprised that simply
> splitting pages would cause the fragmentation to increase so dramatically.
>
When a page is that full (or usually even close) just one new row will cause
a page split since there simply isn't enough room for the new data. A
non-clustered index is essentially a table with a clustered index on the
index expression. That means the data at the leaf level have to basically
be in physical order. So when the data coming in is random (meaning the
value of the column(s) the index is based on) it usually gets placed in
between existing rows. If there is not enough room on the page it splits it
and moves half to another page. When you add new rows in index expression
order (such as a datetime that is in chronological order) they can simply be
appended to the end of the current page. When that page is full it creates
a new page and continues appending from there. This is not a page split and
essentially does not change the logical fragmentation since all the new
pages come directly after the previous ones. This KB is great for this type
stuff:
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
Logical fragmentation is the most important factor that you should be
worried about. Especially if you have more than 1 file in the filegroup. In
that case Logical is the only one that you can really trust anyway. See the
KB I mentioned.
Andrew J. Kelly SQL MVP|||Andrew's explanations are spot on.
Why do you consider Scan Density so important? What's the access pattern
over this index?
Do you notice query performance dropping after the insert activity? It's
entirely possible that everything you're doing is a waste of time - akin to
continually shrinking a database after it grows every day. Please read the
whitepaper below which explains a bunch about when to take action on
fragmentation.
http://www.microsoft.com/technet/prodtechnol/sql/2000/maintain/ss2kidbp.mspx
Thanks and regards.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:05DA17D7-942D-452A-8973-ACCB2DB7A98C@.microsoft.com...
> "Andrew J. Kelly" wrote:
> > "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> > news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> > > After defrag:
> > >
> > > Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID:
8
> > > LEAF level scan performed.
> > > - Pages Scanned........................: 76899
> > > - Extents Scanned.......................: 9670
> > > - Extent Switches.......................: 37754
> > > - Avg. Pages per Extent..................: 8.0
> > > - Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
> > > - Logical Scan Fragmentation ..............: 0.01%
> > > - Extent Scan Fragmentation ...............: 61.40%
> > > - Avg. Bytes Free per Page................: 38.3
> > > - Avg. Page Density (full)................: 99.53%
> > > DBCC execution completed. If DBCC printed error messages, contact your
> > system administrator.
> > >
> > > After inserting 270,000 rows:
> > > DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> > > Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID:
8
> > > LEAF level scan performed.
> > > - Pages Scanned........................: 123077
> > > - Extents Scanned.......................: 15464
> > > - Extent Switches.......................: 88745
> > > - Avg. Pages per Extent..................: 8.0
> > > - Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746]
> > > - Logical Scan Fragmentation ..............: 26.34%
> > > - Extent Scan Fragmentation ...............: 65.66%
> > > - Avg. Bytes Free per Page................: 3009.3
> > > - Avg. Page Density (full)................: 62.82%
> > >
> > > So... it's very strange to me that, after inserting about 1% new rows,
and
> > > not deleting or updating any rows, the fragmentation could go from
.01% to
> > > 26.34%.
> > >
> > This isn't strange at all since your pages are basically 100% full
before
> > the inserts. That means that almost any insert will cause a page split
and
> > the results of the showcontig shows that there was a lot of it. If your
> > going to do a lot of inserts you should consider setting an appropriate
fill
> > factor and possibly Padindex as well. Leaving more free space on the
page
> > will mean more pages in the database but will result in less pagesplits
and
> > lots less work during the inserts.
> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also suprised that simply splitting pages would cause the
fragmentation to increase so dramatically.
> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
>
>|||Thanks, Andrew. Very helpful stuff.
-- J|||Paul,
Thanks for your quick reply.
"Paul S Randal [MS]" wrote:
> Why do you consider Scan Density so important? What's the access pattern
> over this index?
Sorry if I wasn't clear. I don't know whether Scan Density is important or not. The KB articles are great about Logical Fragmentation, but they don't really seem to address Scan Density. I just observed that (a) it was low and (b) INDEXDEFRAG didn't seem to reduce the total number of extents as effectively as DBREINDEX. I don't know if the total number of pages is important, but I wonder how the fragmentation can be low and the average page density high when there seem to be a significant difference in the total number of extents... is the reason that DBREINDEX tends to group pages together better physically? And is that important?
> Do you notice query performance dropping after the insert activity? It's
> entirely possible that everything you're doing is a waste of time - akin to
> continually shrinking a database after it grows every day. Please read the
> whitepaper below which explains a bunch about when to take action on
> fragmentation.
Yes, the query performance seems to be inversely proportional to the fragmentation of the indexes. I don't have stats on individual queries, but the process which does the queries has become considerably faster after instituting nightly defragmentations. The insert process has not; however, I'm hoping that tuning the FILLFACTOR will help that.
-- J|||You shouldn't worry about Scan Density or Extent Scan Fragmentation. The
main cause of query slowdown is ineffective readahead during range scans
caused by Logical Scan Fragmentation. Extent Scan Fragmentation has only
minimal effect on readahead and so we're de-emphasizing its importance.
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:3D9896FF-FD3A-4DF3-8F14-610E7C856F7F@.microsoft.com...
> Paul,
> Thanks for your quick reply.
> "Paul S Randal [MS]" wrote:
> > Why do you consider Scan Density so important? What's the access pattern
> > over this index?
> Sorry if I wasn't clear. I don't know whether Scan Density is important
or not. The KB articles are great about Logical Fragmentation, but they
don't really seem to address Scan Density. I just observed that (a) it was
low and (b) INDEXDEFRAG didn't seem to reduce the total number of extents as
effectively as DBREINDEX. I don't know if the total number of pages is
important, but I wonder how the fragmentation can be low and the average
page density high when there seem to be a significant difference in the
total number of extents... is the reason that DBREINDEX tends to group
pages together better physically? And is that important?
> > Do you notice query performance dropping after the insert activity? It's
> > entirely possible that everything you're doing is a waste of time - akin
to
> > continually shrinking a database after it grows every day. Please read
the
> > whitepaper below which explains a bunch about when to take action on
> > fragmentation.
> Yes, the query performance seems to be inversely proportional to the
fragmentation of the indexes. I don't have stats on individual queries, but
the process which does the queries has become considerably faster after
instituting nightly defragmentations. The insert process has not; however,
I'm hoping that tuning the FILLFACTOR will help that.
> -- J

Thursday, March 8, 2012

DBCC INDEXDEFRAG

I have SQL Server 2000 Enterprise Edition on my server.
I first execute DBCC SHOWCONTIG on my database.
Which outputs logicaldefrag, scan density, and etc.
I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
every table in my database.
Next I apply the sp_updatestats.
Lastly, I execute DBCC SHOWCONTIG to the database.
When I compare the DBCC SHOWCONTIG before and after
results from applying DBCC INDEXDEFRAG. I noticed the
logicalfrag has the same values?
Please help me fix this issue.
Thanks,
MikeWell a couple things comes to mind. First off do these tables all have a
clustered index on them? How many pages in these tables? Can you show an
example of before and after?
Andrew J. Kelly SQL MVP
"Mike" <anonymous@.discussions.microsoft.com> wrote in message
news:27d5a01c46449$23fbc7f0$a601280a@.phx
.gbl...
> I have SQL Server 2000 Enterprise Edition on my server.
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
> Please help me fix this issue.
> Thanks,
> Mike|||"Mike" wrote:
> [...]
> I first execute DBCC SHOWCONTIG on my database.
> Which outputs logicaldefrag, scan density, and etc.
> I apply the DBCC INDEXDEFRAG (0, table_id, index_id) to
> every table in my database.
> Next I apply the sp_updatestats.
> Lastly, I execute DBCC SHOWCONTIG to the database.
> When I compare the DBCC SHOWCONTIG before and after
> results from applying DBCC INDEXDEFRAG. I noticed the
> logicalfrag has the same values?
>
Mike,
I have noticed the same thing with indexes on large tables. I'm using the s
ample script from Books Online to run a nightly DBCC INDEXDEFRAG on indexes
with higher than a certain level of fragmentation, but I notice that certain
indexes are above the t
hreshold every night. If I run a DBCC DBREINDEX, I have much better results
(the fragmentation usually goes down below 1%).
Normally, I would think it was my own mistake... but the strange thing is th
at many indexes seem to have their fragmentation reduced when running DBCC I
NDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for my dat
a warehouse DBs...
Regards,
Jonathan|||What's the reported number of pages moved when running DBCC INDEXDEFRAG? Can
you post sample DBCC SHOWCONTIG output please?
Thanks
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> "Mike" wrote:
> Mike,
> I have noticed the same thing with indexes on large tables. I'm using
the sample script from Books Online to run a nightly DBCC INDEXDEFRAG on
indexes with higher than a certain level of fragmentation, but I notice that
certain indexes are above the threshold every night. If I run a DBCC
DBREINDEX, I have much better results (the fragmentation usually goes down
below 1%).
> Normally, I would think it was my own mistake... but the strange thing
is that many indexes seem to have their fragmentation reduced when running
DBCC INDEXDEFRAG on them. I'm now considering giving up on INDEXDEFRAG for
my data warehouse DBs...
> Regards,
> Jonathan|||Paul,
"Paul S Randal [MS]" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:9E111CD5-2CD0-4071-B3A9-39E3D5CA4978@.microsoft.com...
> What's the reported number of pages moved when running DBCC INDEXDEFRAG? C
an
> you post sample DBCC SHOWCONTIG output please?
Thanks for your reply.
I'm still looking into this myself, and it's a bit more complicated than I o
riginally reported.
I have a data warehouse that's updated early in the morning. The larger tab
les are in the order of 5 to 25 million rows. The updates vary in size from
100,000 to 2 million rows.
Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the u
pdate, and it's after the update that the index appears to be refragmented.
So, for example, on a 26 million row table:
Before Defrag:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 121895
- Extents Scanned.......................: 15316
- Extent Switches.......................: 88061
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.30% [15237:88062
]
- Logical Scan Fragmentation ..............: 25.04%
- Extent Scan Fragmentation ...............: 44.72%
- Avg. Bytes Free per Page................: 3012.7
- Avg. Page Density (full)................: 62.78%
INDEXDEFRAG scanned 121891, moved 76889, removed 44996
After defrag:
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 76899
- Extents Scanned.......................: 9670
- Extent Switches.......................: 37754
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 25.46% [9613:37755]
- Logical Scan Fragmentation ..............: 0.01%
- Extent Scan Fragmentation ...............: 61.40%
- Avg. Bytes Free per Page................: 38.3
- Avg. Page Density (full)................: 99.53%
DBCC execution completed. If DBCC printed error messages, contact your syste
m administrator.
After inserting 270,000 rows:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 123077
- Extents Scanned.......................: 15464
- Extent Switches.......................: 88745
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 17.34% [15385:88746
]
- Logical Scan Fragmentation ..............: 26.34%
- Extent Scan Fragmentation ...............: 65.66%
- Avg. Bytes Free per Page................: 3009.3
- Avg. Page Density (full)................: 62.82%
So... it's very strange to me that, after inserting about 1% new rows, and n
ot deleting or updating any rows, the fragmentation could go from .01% to 26
.34%.
I haven't had a chance to fully document this yet, but it seems to me that D
BREINDEX results in a substantially better Scan Density, and that subsequent
inserts do not result in such extreme changes in Logical Scan Fragmentation
. If you think it's helpfu
l, I'll pursue that.
Regards,
Jonathan|||> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation >could go from .01% to
26.34%.
This isn't strange at all since your pages are basically 100% full before
the inserts. That means that almost any insert will cause a page split and
the results of the showcontig shows that there was a lot of it. If your
going to do a lot of inserts you should consider setting an appropriate fill
factor and possibly Padindex as well. Leaving more free space on the page
will mean more pages in the database but will result in less pagesplits and
lots less work during the inserts.
Andrew J. Kelly SQL MVP
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> Paul,
> "Paul S Randal [MS]" wrote:
Can[vbcol=seagreen]
> Thanks for your reply.
> I'm still looking into this myself, and it's a bit more complicated than I
originally reported.
> I have a data warehouse that's updated early in the morning. The larger
tables are in the order of 5 to 25 million rows. The updates vary in size
from 100,000 to 2 million rows.
> Before the update, I run INDEXDEFRAG on fragmented indexes. Then I do the
update, and it's after the update that the index appears to be refragmented.
So, for example, on a 26 million row table:
> Before Defrag:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 121895
> - Extents Scanned.......................: 15316
> - Extent Switches.......................: 88061
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.30% [15237:880
62]
> - Logical Scan Fragmentation ..............: 25.04%
> - Extent Scan Fragmentation ...............: 44.72%
> - Avg. Bytes Free per Page................: 3012.7
> - Avg. Page Density (full)................: 62.78%
> INDEXDEFRAG scanned 121891, moved 76889, removed 44996
> After defrag:
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 76899
> - Extents Scanned.......................: 9670
> - Extent Switches.......................: 37754
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 25.46% [9613:3775
5]
> - Logical Scan Fragmentation ..............: 0.01%
> - Extent Scan Fragmentation ...............: 61.40%
> - Avg. Bytes Free per Page................: 38.3
> - Avg. Page Density (full)................: 99.53%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> After inserting 270,000 rows:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 123077
> - Extents Scanned.......................: 15464
> - Extent Switches.......................: 88745
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 17.34% [15385:887
46]
> - Logical Scan Fragmentation ..............: 26.34%
> - Extent Scan Fragmentation ...............: 65.66%
> - Avg. Bytes Free per Page................: 3009.3
> - Avg. Page Density (full)................: 62.82%
> So... it's very strange to me that, after inserting about 1% new rows, and
not deleting or updating any rows, the fragmentation could go from .01% to
26.34%.
> I haven't had a chance to fully document this yet, but it seems to me that
DBREINDEX results in a substantially better Scan Density, and that
subsequent inserts do not result in such extreme changes in Logical Scan
Fragmentation. If you think it's helpful, I'll pursue that.
> Regards,
> Jonathan|||"Andrew J. Kelly" wrote:
> "Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
> news:70809313-9024-428C-BD37-3D035CB44453@.microsoft.com...
> system administrator.
> This isn't strange at all since your pages are basically 100% full before
> the inserts. That means that almost any insert will cause a page split an
d
> the results of the showcontig shows that there was a lot of it. If your
> going to do a lot of inserts you should consider setting an appropriate fi
ll
> factor and possibly Padindex as well. Leaving more free space on the page
> will mean more pages in the database but will result in less pagesplits an
d
> lots less work during the inserts.
Hi Andrew.
I guess that 270K inserts seems like a lot in absolute terms, but relative t
o the size of the table, it's pretty small. So I guess I'm surprised that o
ne in 6 inserts would cause a page split when I'm changing the table by only
1%. I'm also suprised tha
t simply splitting pages would cause the fragmentation to increase so dramat
ically.
I had originally created the index with no FILLFACTOR specified. (I thought
this was supposed to default to a FILLFACTOR of 80). On your suggestion, I
tried rebuilding the index with FILLFACTOR explicitly set to 80. Now DBCC
SHOWCONTIG returns:
DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
LEAF level scan performed.
- Pages Scanned........................: 96535
- Extents Scanned.......................: 12114
- Extent Switches.......................: 12113
- Avg. Pages per Extent..................: 8.0
- Scan Density [Best Count:Actual Count]......: 99.61% [12067:12114
]
- Logical Scan Fragmentation ..............: 0.02%
- Extent Scan Fragmentation ...............: 49.70%
- Avg. Bytes Free per Page................: 1610.7
- Avg. Page Density (full)................: 80.10%
DBCC execution completed. If DBCC printed error messages, contact your syste
m administrator.
Note the great improvement in the index's Scan Density. And I also see this
kind of improvement in Scan Density when I run DBCC DBREINDEX.
So... I'll keep an eye on it for the next few days. I'll also check into wh
ether my other big indexes have similar FILLFACTOR issues. In the meantime,
is Scan Density something that I should be worrying about?|||> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm >surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also surprised that simply
> splitting pages would cause the fragmentation to increase so dramatically.
>
When a page is that full (or usually even close) just one new row will cause
a page split since there simply isn't enough room for the new data. A
non-clustered index is essentially a table with a clustered index on the
index expression. That means the data at the leaf level have to basically
be in physical order. So when the data coming in is random (meaning the
value of the column(s) the index is based on) it usually gets placed in
between existing rows. If there is not enough room on the page it splits it
and moves half to another page. When you add new rows in index expression
order (such as a datetime that is in chronological order) they can simply be
appended to the end of the current page. When that page is full it creates
a new page and continues appending from there. This is not a page split and
essentially does not change the logical fragmentation since all the new
pages come directly after the previous ones. This KB is great for this type
stuff:
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx

> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:121
14]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
Logical fragmentation is the most important factor that you should be
worried about. Especially if you have more than 1 file in the filegroup. In
that case Logical is the only one that you can really trust anyway. See the
KB I mentioned.
Andrew J. Kelly SQL MVP|||Andrew's explanations are spot on.
Why do you consider Scan Density so important? What's the access pattern
over this index?
Do you notice query performance dropping after the insert activity? It's
entirely possible that everything you're doing is a waste of time - akin to
continually shrinking a database after it grows every day. Please read the
whitepaper below which explains a bunch about when to take action on
fragmentation.
http://www.microsoft.com/technet/pr...n/ss2kidbp.mspx
Thanks and regards.
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"Jonathan Levine" <myfoo@.nospam.nospam> wrote in message
news:05DA17D7-942D-452A-8973-ACCB2DB7A98C@.microsoft.com...
> "Andrew J. Kelly" wrote:
8[vbcol=seagreen]
8[vbcol=seagreen]
and[vbcol=seagreen]
.01% to[vbcol=seagreen]
before[vbcol=seagreen]
and[vbcol=seagreen]
fill[vbcol=seagreen]
page[vbcol=seagreen]
and[vbcol=seagreen]
> Hi Andrew.
> I guess that 270K inserts seems like a lot in absolute terms, but relative
to the size of the table, it's pretty small. So I guess I'm surprised that
one in 6 inserts would cause a page split when I'm changing the table by
only 1%. I'm also suprised that simply splitting pages would cause the
fragmentation to increase so dramatically.
> I had originally created the index with no FILLFACTOR specified. (I
thought this was supposed to default to a FILLFACTOR of 80). On your
suggestion, I tried rebuilding the index with FILLFACTOR explicitly set to
80. Now DBCC SHOWCONTIG returns:
> DBCC SHOWCONTIG scanning 'Historical_Rankings' table...
> Table: 'Historical_Rankings' (2018106230); index ID: 14, database ID: 8
> LEAF level scan performed.
> - Pages Scanned........................: 96535
> - Extents Scanned.......................: 12114
> - Extent Switches.......................: 12113
> - Avg. Pages per Extent..................: 8.0
> - Scan Density [Best Count:Actual Count]......: 99.61% [12067:121
14]
> - Logical Scan Fragmentation ..............: 0.02%
> - Extent Scan Fragmentation ...............: 49.70%
> - Avg. Bytes Free per Page................: 1610.7
> - Avg. Page Density (full)................: 80.10%
> DBCC execution completed. If DBCC printed error messages, contact your
system administrator.
> Note the great improvement in the index's Scan Density. And I also see
this kind of improvement in Scan Density when I run DBCC DBREINDEX.
> So... I'll keep an eye on it for the next few days. I'll also check into
whether my other big indexes have similar FILLFACTOR issues. In the
meantime, is Scan Density something that I should be worrying about?
>
>|||Thanks, Andrew. Very helpful stuff.
-- J

Wednesday, March 7, 2012

DBCC DBReindex on NonClustered

If I execute the following statement on a nonclustered index there is no
reduction in fragmentation on the index:
DBCC DBREINDEX ('DBName.dbo.MyTable','IDX_MyTable_NonClustered',0) WITH
NO_INFOMSGS
The table on which I am performing the above statement has a clustered index
.
Is that the reason the above DBCC DBReindex would not reduce fragmentation
using the above statement? In other words, if a table has a clustered index,
then in order to reduce fragmentation on a nonclustered index in the same
table that has the clustered index, I would need to perform a DROP and CREAT
E
INDEX on the nonclustered index?
Message posted via http://www.droptable.comcbrichards via droptable.com wrote:
> If I execute the following statement on a nonclustered index there is no
> reduction in fragmentation on the index:
> DBCC DBREINDEX ('DBName.dbo.MyTable','IDX_MyTable_NonClustered',0) WITH
> NO_INFOMSGS
> The table on which I am performing the above statement has a clustered ind
ex.
> Is that the reason the above DBCC DBReindex would not reduce fragmentation
> using the above statement? In other words, if a table has a clustered inde
x,
> then in order to reduce fragmentation on a nonclustered index in the same
> table that has the clustered index, I would need to perform a DROP and CRE
ATE
> INDEX on the nonclustered index?
>
Please post the output of DBCC SHOWCONTIG for this index...
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||DBCC SHOWCONTIG scanning 'MyTable' table...
Table: 'MyTable' (862501003); index ID: 43, database ID: 61
LEAF level scan performed.
- Pages Scanned........................: 7
- Extents Scanned.......................: 7
- Extent Switches.......................: 6
- Avg. Pages per Extent..................: 1.0
- Scan Density [Best Count:Actual Count]......: 14.29% [1:7]
- Logical Scan Fragmentation ..............: 85.71%
- Extent Scan Fragmentation ...............: 42.86%
- Avg. Bytes Free per Page................: 488.7
- Avg. Page Density (full)................: 93.96%
DBCC execution completed. If DBCC printed error messages, contact your syste
m
administrator.
Tracy McKibben wrote:
>[quoted text clipped - 8 lines]
>Please post the output of DBCC SHOWCONTIG for this index...
>
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200608/1|||Since your last reply I have performed the following operations:
I have dropped and recreated this nonclustered index, and there is no
difference in fragmentation.
I have dropped and recreated the clustered index, and there is no difference
in fragmentation on the clustered or nonclustered index.
Any ideas?
Tracy McKibben wrote:
>[quoted text clipped - 8 lines]
>Please post the output of DBCC SHOWCONTIG for this index...
>
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200608/1|||Your index only has 7 pages in it. Anything less than 8 pages will use a
mixed extent. That means it will share as much as 8 extents and will always
show as fragmented. Only after you get more than 8 pages can you make them
all contiguous. But this is pretty moot anyway. I wouldn't worry about
anything with such few pages as I am sure there are more pressing issues
that you can address. I usually don't pay much attention to indexes with
less than several hundred pages at least.
Andrew J. Kelly SQL MVP
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:64eb85d653ff4@.uwe...
> DBCC SHOWCONTIG scanning 'MyTable' table...
> Table: 'MyTable' (862501003); index ID: 43, database ID: 61
> LEAF level scan performed.
> - Pages Scanned........................: 7
> - Extents Scanned.......................: 7
> - Extent Switches.......................: 6
> - Avg. Pages per Extent..................: 1.0
> - Scan Density [Best Count:Actual Count]......: 14.29% [1:7]
> - Logical Scan Fragmentation ..............: 85.71%
> - Extent Scan Fragmentation ...............: 42.86%
> - Avg. Bytes Free per Page................: 488.7
> - Avg. Page Density (full)................: 93.96%
> DBCC execution completed. If DBCC printed error messages, contact your
> system
> administrator.
> Tracy McKibben wrote:
> --
> Message posted via droptable.com
> http://www.droptable.com/Uwe/Forum...server/200608/1
>

DBCC DBReindex on NonClustered

If I execute the following statement on a nonclustered index there is no
reduction in fragmentation on the index:
DBCC DBREINDEX ('DBName.dbo.MyTable','IDX_MyTable_NonClustered',0) WITH
NO_INFOMSGS
The table on which I am performing the above statement has a clustered index.
Is that the reason the above DBCC DBReindex would not reduce fragmentation
using the above statement? In other words, if a table has a clustered index,
then in order to reduce fragmentation on a nonclustered index in the same
table that has the clustered index, I would need to perform a DROP and CREATE
INDEX on the nonclustered index?
--
Message posted via http://www.sqlmonster.comcbrichards via SQLMonster.com wrote:
> If I execute the following statement on a nonclustered index there is no
> reduction in fragmentation on the index:
> DBCC DBREINDEX ('DBName.dbo.MyTable','IDX_MyTable_NonClustered',0) WITH
> NO_INFOMSGS
> The table on which I am performing the above statement has a clustered index.
> Is that the reason the above DBCC DBReindex would not reduce fragmentation
> using the above statement? In other words, if a table has a clustered index,
> then in order to reduce fragmentation on a nonclustered index in the same
> table that has the clustered index, I would need to perform a DROP and CREATE
> INDEX on the nonclustered index?
>
Please post the output of DBCC SHOWCONTIG for this index...
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||DBCC SHOWCONTIG scanning 'MyTable' table...
Table: 'MyTable' (862501003); index ID: 43, database ID: 61
LEAF level scan performed.
- Pages Scanned........................: 7
- Extents Scanned.......................: 7
- Extent Switches.......................: 6
- Avg. Pages per Extent..................: 1.0
- Scan Density [Best Count:Actual Count]......: 14.29% [1:7]
- Logical Scan Fragmentation ..............: 85.71%
- Extent Scan Fragmentation ...............: 42.86%
- Avg. Bytes Free per Page................: 488.7
- Avg. Page Density (full)................: 93.96%
DBCC execution completed. If DBCC printed error messages, contact your system
administrator.
Tracy McKibben wrote:
>> If I execute the following statement on a nonclustered index there is no
>> reduction in fragmentation on the index:
>[quoted text clipped - 8 lines]
>> table that has the clustered index, I would need to perform a DROP and CREATE
>> INDEX on the nonclustered index?
>Please post the output of DBCC SHOWCONTIG for this index...
>
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200608/1|||Since your last reply I have performed the following operations:
I have dropped and recreated this nonclustered index, and there is no
difference in fragmentation.
I have dropped and recreated the clustered index, and there is no difference
in fragmentation on the clustered or nonclustered index.
Any ideas?
Tracy McKibben wrote:
>> If I execute the following statement on a nonclustered index there is no
>> reduction in fragmentation on the index:
>[quoted text clipped - 8 lines]
>> table that has the clustered index, I would need to perform a DROP and CREATE
>> INDEX on the nonclustered index?
>Please post the output of DBCC SHOWCONTIG for this index...
>
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200608/1|||Your index only has 7 pages in it. Anything less than 8 pages will use a
mixed extent. That means it will share as much as 8 extents and will always
show as fragmented. Only after you get more than 8 pages can you make them
all contiguous. But this is pretty moot anyway. I wouldn't worry about
anything with such few pages as I am sure there are more pressing issues
that you can address. I usually don't pay much attention to indexes with
less than several hundred pages at least.
--
Andrew J. Kelly SQL MVP
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:64eb85d653ff4@.uwe...
> DBCC SHOWCONTIG scanning 'MyTable' table...
> Table: 'MyTable' (862501003); index ID: 43, database ID: 61
> LEAF level scan performed.
> - Pages Scanned........................: 7
> - Extents Scanned.......................: 7
> - Extent Switches.......................: 6
> - Avg. Pages per Extent..................: 1.0
> - Scan Density [Best Count:Actual Count]......: 14.29% [1:7]
> - Logical Scan Fragmentation ..............: 85.71%
> - Extent Scan Fragmentation ...............: 42.86%
> - Avg. Bytes Free per Page................: 488.7
> - Avg. Page Density (full)................: 93.96%
> DBCC execution completed. If DBCC printed error messages, contact your
> system
> administrator.
> Tracy McKibben wrote:
>> If I execute the following statement on a nonclustered index there is no
>> reduction in fragmentation on the index:
>>[quoted text clipped - 8 lines]
>> table that has the clustered index, I would need to perform a DROP and
>> CREATE
>> INDEX on the nonclustered index?
>>Please post the output of DBCC SHOWCONTIG for this index...
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200608/1
>

Friday, February 24, 2012

dbcc checkprimaryfile

Hello All,

I am going crazy tring to find out why I keep getting this error when I execute a simple

dbcc checkprimaryfile (N'C:\backup\databasename.mdf', 0) from ADO.Net. This works just fine from Query analyzer.

By the way, I am running SQL Server 2005 and .Net 2.0.

Here the complete error:

CREATE FILE encountered operating system error5 (Access is denied) while attempting to open or create the physical file 'C:\backup\databasename.mdf.

Note that the database file is not in use as I have detached it.

Any help would be greatly appreciated!

Thanks!

Amine

Are you using the same connection string ? So arr you connecting to the same server with the same credentials ? Seems that the user in ADO.NET does not have the appropiate permissions.

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||

yes, I am using the same connection and I am logging in with sa account in the ADO.Net connection string.

|||

All,

I figured out what the problem was: the Initial catalog was not set in the connection string!

Thanks.

Dbcc Checkident Reseed

On some tables when I execute the following statement the identity value will start at 1 other times 0. Has anyone experienced this inconsistency before?
DBCC CHECKIDENT ('TABLE_NAME', RESEED, 0)Is the miracle effect?

Can you post some code where this happens?

Please make sure to post the DDL, any DML and sample data.

Thanks|||Here ya go. Most of the tables are very simplistic. I start by deleting all of the records then executing the DBCC CHECKIDENT ('table_name', RESEED, 0) in query analyzer against the table. Here's the ddl for one of the tables. 90% of the time the identity value starts at 1 the other 10% start at 0.

t_unique_id = int
t_varchar = varchar(50)
t_flag = int with rule limiting values to 1 or 0
t_guid = char(36)

/*================================================= =============*/
/* Table: producer_type */
/*================================================= =============*/
create table dbo.producer_type (
producer_type_id t_unique_id identity,
producer_type_name t_varchar not null,
org_flag t_flag not null,
description t_long_varchar not null,
comments t_long_varchar not null,
created_by t_unique_id not null,
created_dt datetime not null,
changed_by t_unique_id not null,
changed_dt datetime not null,
logical_unit_of_work_id t_guid not null
)
go

alter table dbo.producer_type
add constraint pk_producer_type primary key (producer_type_id)
with
fillfactor= 90
go

/*================================================= =============*/
/* Index: ux_producer_type_01 */
/*================================================= =============*/
create unique index ux_producer_type_01 on dbo.producer_type (
producer_type_name
)
with
fillfactor= 90
go|||I'll take a look, but why don't you specify the seed an increment in the DDL?

I'm sure there's a default...but...

I've always set IDENTITY(1,1) (that is when I have to use it...I try to avoid it)|||Just out of curiosity...how are you building this table?

You can't do what you're doing unless you use dynamic sql...unless you're building from the application layer, and if you are, what's with the GO?

Also out of curiosity, it sounds like whatever process your doing is placing an undue amount of meaning to the identity column.

Why does it need to be reset to 1 (or 0)|||Sorry, these are in no particular order:

First, I'm building the tables with ddl and executing with query builder. I didn't want to post all of the ddl for the user defined data types, fks, etc... The 'GO' is used as a terminator for the SQL. I'm building over 150 tables, pk's, fk's, indexes, etc.. in one script. It helps me if I encounter an error. The script will stop at that point and allow me to correct the problem and continue running.

Second, the default on the identity is (1,1)

Third, we are placing extra burden on the identity value because we are trying to migrate data into the new system from an existing system and are heavily coding at the same time. The developers need to know the primary key values for reference or metadata for codiing purposes. I know the order of the values going into the tables and as a standard told all of the developers the pk would start at 1. This hurts if it periodically starts at 0 because we are constantly rebuilding the database from the ddl.

Finally, I'm regretting the decision not to turn the identity insert on and specify the values on insert. I could change my scripts but it would take some time to do. I didn't know if there was something simple I was missing with the DBCC CHECKIDENT and RESEED.

Hope this helps, sorry for the long reply.|||Are you not using Query Analyzer?

And if you are, then how does this work?

t_unique_id = int
t_varchar = varchar(50)
t_flag = int with rule limiting values to 1 or 0
t_guid = char(36)

/ *=================================================
=============*/
/* Table: producer_type */
/ *=================================================
=============*/
create table dbo.producer_type (
producer_type_id t_unique_id identity,
producer_type_name t_varchar not null,
org_flag t_flag not null,
description t_long_varchar not null,
comments t_long_varchar not null,
created_by t_unique_id not null,
created_dt datetime not null,
changed_by t_unique_id not null,
changed_dt datetime not null,
logical_unit_of_work_id t_guid not null
)
go

You can't assign the datatype to a variable like that...unless it's a different interface/language...

I'm amazed at a 10% occurance...it's not often that the same process behave differently.

Since you're blowing the data away anyway, can you just do a drop, then recreate the table?

It will save on logging.

Why not create a shell db and recreate it when you need. Then have load scripts...or better just dump a "clean slate" db, and restore over...

and I'm sure NONE of these suggestion will work for you because of either RI, developer data, yada yada yada...

And in lieu of the fact that you're having these problems...why not give it a try and build the table with IDENTITY(1,1).

My Own Opinion (MOO)

Good Luck

Sunday, February 19, 2012

DBCC CHECKDB Single User Mode

Does the database have to be in Single User Mode to execute the
statement listed below?
DBCC CHECKDB ('Database',Repair_Rebuild) WITH ALL_ERRORMSGS
Thanks,> Does the database have to be in Single User Mode to execute the
> statement listed below?
Based on the error message, I'd say yes'?
Server: Msg 7919, Level 16, State 2, Line 1
Repair statement not processed. Database needs to be in single user mode.|||Yes it does. Before fixing any errors that checkdb has reported, you should
work out whay the errors occured (check the errorlog and event logs for
hardware messages for instance)
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"AB - MVP" <ten.xoc@.dnartreb.noraa> wrote in message
news:OhQXkCNUFHA.3436@.TK2MSFTNGP09.phx.gbl...
> Based on the error message, I'd say yes'?
> Server: Msg 7919, Level 16, State 2, Line 1
> Repair statement not processed. Database needs to be in single user mode.
>

DBCC CHECKDB Single User Mode

Does the database have to be in Single User Mode to execute the
statement listed below?
DBCC CHECKDB ('Database',Repair_Rebuild) WITH ALL_ERRORMSGS
Thanks,
> Does the database have to be in Single User Mode to execute the
> statement listed below?
Based on the error message, I'd say yes??
Server: Msg 7919, Level 16, State 2, Line 1
Repair statement not processed. Database needs to be in single user mode.
|||Yes it does. Before fixing any errors that checkdb has reported, you should
work out whay the errors occured (check the errorlog and event logs for
hardware messages for instance)
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"AB - MVP" <ten.xoc@.dnartreb.noraa> wrote in message
news:OhQXkCNUFHA.3436@.TK2MSFTNGP09.phx.gbl...
> Based on the error message, I'd say yes??
> Server: Msg 7919, Level 16, State 2, Line 1
> Repair statement not processed. Database needs to be in single user mode.
>

DBCC CHECKDB Single User Mode

Does the database have to be in Single User Mode to execute the
statement listed below?
DBCC CHECKDB ('Database',Repair_Rebuild) WITH ALL_ERRORMSGS
Thanks,> Does the database have to be in Single User Mode to execute the
> statement listed below?
Based on the error message, I'd say yes'?
Server: Msg 7919, Level 16, State 2, Line 1
Repair statement not processed. Database needs to be in single user mode.|||Yes it does. Before fixing any errors that checkdb has reported, you should
work out whay the errors occured (check the errorlog and event logs for
hardware messages for instance)
--
Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
This posting is provided "AS IS" with no warranties, and confers no rights.
"AB - MVP" <ten.xoc@.dnartreb.noraa> wrote in message
news:OhQXkCNUFHA.3436@.TK2MSFTNGP09.phx.gbl...
> > Does the database have to be in Single User Mode to execute the
> > statement listed below?
> Based on the error message, I'd say yes'?
> Server: Msg 7919, Level 16, State 2, Line 1
> Repair statement not processed. Database needs to be in single user mode.
>