Article View: comp.databases.ms-sqlserver
Article #84Re: what is the impact of Database size on Performemce
From: Erland Sommarskog
Date: Wed, 31 Mar 2004 22:45
Date: Wed, 31 Mar 2004 22:45
101 lines
4304 bytes
4304 bytes
[posted and mailed]
louis nguyen (louisducnguyen@hotmail.com) writes:
> B) Reindexing. On any given day maybe 5% (max) of new data is added
> to my DB. But DBCC reindex has to work on all the indexes. So DBCC
> reindex takes 3 hours a night. Yuck.
>
> Maybe there is a better way. But I try to keep each database as small
> as possible.
Here is a script that I got from SQL Server MVP Andrew Kelly, which examines
which tables that are in actually in need of fragmentation. This could
reduce the reindex time a bit.
-- Gather Fragmentation Info
SET NOCOUNT ON
USE PRESENTS
DECLARE @TableName VARCHAR(100)
-- Create a table to hold the results of DBCC SHOWCONTIG
IF OBJECT_ID('Tempdb.dbo.#Contig') IS NOT NULL
DROP TABLE #Contig
CREATE TABLE #Contig ([ObjectName] VARCHAR(100), [ObjectId] INT, [IndexName]
VARCHAR(200),
[IndexId] INT, [Level] INT, [Pages] INT , [Rows] INT ,
[MinimumRecordSize] INT,
[MaximumRecordSize] INT , [AverageRecordSize] INT,
[ForwardedRecords] INT ,
[Extents] INT, [ExtentSwitches] INT, [AverageFreeBytes] NUMERIC(6,2)
,
[AveragePageDensity] NUMERIC(6,2), [ScanDensity] NUMERIC(6,2) ,
[BestCount] INT ,
[ActualCount] INT , [LogicalFragmentation] NUMERIC(6,2) ,
[ExtentFragmentation] NUMERIC(6,2) )
DECLARE curTables CURSOR STATIC LOCAL
FOR
SELECT Table_Name
FROM Information_Schema.Tables
WHERE Table_Type = 'BASE TABLE'
OPEN curTables
FETCH NEXT FROM curTables INTO @TableName
SET @TableName = RTRIM(@TableName)
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO #Contig EXEC('DBCC SHOWCONTIG(' + @TableName + ') WITH
TABLERESULTS, ALL_INDEXES, NO_INFOMSGS')
FETCH NEXT FROM curTables INTO @TableName
END
CLOSE curTables
DEALLOCATE curTables
-- Get a list of all the tables where the Logical Fragmentation of at least
-- one index is over 30% and is not a statistic, a heap or Text / Image.
DECLARE curFrag CURSOR STATIC LOCAL
FOR
SELECT [ObjectName]
FROM #Contig
WHERE LogicalFragmentation >= 30 AND IndexID BETWEEN 1 AND 254
AND INDEXPROPERTY (ObjectId, IndexName, 'IsStatistics') = 0
GROUP BY [ObjectName]
OPEN curFrag
FETCH NEXT FROM curTables INTO @TableName
SET @TableName = RTRIM(@TableName)
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName)
FETCH NEXT FROM curFrag INTO @TableName
END
CLOSE curFrag
DEALLOCATE curFrag
select * from #Contig
--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinfo/productdoc/2000/books.asp
Technical Details
Message-ID:
<Xns94BE761CE43DYazorman@127.0.0.1>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news2.telebyte.nl!surfnet.nl!newsfeed1.funet.fi!newsfeeds.funet.fi!62.127.77.83.MISMATCH!newsfeed1.telenor.se!news2.tninet.se!not-for-mailReferences:
<tSjac.16658$xb.714@newssvr27.news.prodigy.com> <b0e9d53.0403301556.69835854@posting.google.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f816f,2aea0b246c090747 X-Google-Attributes: gidf816f,public X-Google-Thread: ff490,2aea0b246c090747 X-Google-Attributes: gidff490,public X-Google-Thread: 110f0d,2aea0b246c090747 X-Google-Attributes: gid110f0d,public X-Google-Thread: 107d2f,2aea0b246c090747 X-Google-Attributes: gid107d2f,public X-Google-Thread: 104de1,2aea0b246c090747 X-Google-Attributes: gid104de1,public X-Google-ArrivalTime: 2004-03-31 14:43:31 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news2.telebyte.nl!surfnet.nl!newsfeed1.funet.fi!newsfeeds.funet.fi!62.127.77.83.MISMATCH!newsfeed1.telenor.se!news2.tninet.se!not-for-mail From: Erland Sommarskog <sommar@algonet.se> Newsgroups: comp.databases.ms-sqlserver,cz.comp.microsoft.sql,microsoft.public.il.hebrew.sqlserver,microsoft.public.sqlserver,microsoft.public.sqlserver.misc Subject: Re: what is the impact of Database size on Performemce Date: Wed, 31 Mar 2004 22:45:05 +0000 (UTC) Organization: Erland Sommarskog Lines: 101 Sender: sommar@algonet.invalid Message-ID: <Xns94BE761CE43DYazorman@127.0.0.1> References: <tSjac.16658$xb.714@newssvr27.news.prodigy.com> <b0e9d53.0403301556.69835854@posting.google.com> NNTP-Posting-Host: kairos.algonet.se Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: green.tninet.se 1080773105 9891 213.150.135.237 (31 Mar 2004 22:45:05 GMT) X-Complaints-To: abuse@telenordia.se NNTP-Posting-Date: Wed, 31 Mar 2004 22:45:05 +0000 (UTC) User-Agent: Xnews/06.07.17 Mime-proxy/1.4.c.0 (Win32)