BCC SHOWCONTIG 正在扫描 'sysobjects' 表...
表: 'sysobjects'(1);索引 ID: 1,数据库 ID: 10
已执行 TABLE 级别的扫描。
- 扫描页数.....................................: 60
- 扫描扩展盘区数...............................: 17
- 扩展盘区开关数...............................: 59
- 每个扩展盘区上的平均页数.....................: 3.5
- 扫描密度[最佳值:实际值]....................: 13.33%[8:60]
- 逻辑扫描碎片.................................: 45.00%
- 扩展盘区扫描碎片.............................: 88.24%
- 每页上的平均可用字节数.......................: 2694.1
- 平均页密度(完整)...........................: 66.71%
DBCC SHOWCONTIG 正在扫描 'sysindexes' 表...
表: 'sysindexes'(2);索引 ID: 1,数据库 ID: 10
已执行 TABLE 级别的扫描。
- 扫描页数.....................................: 115
- 扫描扩展盘区数...............................: 60
- 扩展盘区开关数...............................: 109
- 每个扩展盘区上的平均页数.....................: 1.9
- 扫描密度[最佳值:实际值]....................: 13.64%[15:110]
- 逻辑扫描碎片.................................: 45.22%
- 扩展盘区扫描碎片.............................: 98.33%
- 每页上的平均可用字节数.......................: 4656.5
- 平均页密度(完整)...........................: 42.47%
DBCC SHOWCONTIG 正在扫描 'syscolumns' 表...
表: 'syscolumns'(3);索引 ID: 1,数据库 ID: 10
已执行 TABLE 级别的扫描。
- 扫描页数.....................................: 525
- 扫描扩展盘区数...............................: 195
- 扩展盘区开关数...............................: 522
- 每个扩展盘区上的平均页数.....................: 2.7
- 扫描密度[最佳值:实际值]....................: 12.62%[66:523]
- 逻辑扫描碎片.................................: 48.38%
- 扩展盘区扫描碎片.............................: 95.90%
- 每页上的平均可用字节数.......................: 5679.0
- 平均页密度(完整)...........................: 29.84%
使用的一个sqlserver2000数据库,用了两个月后变得很慢,重建所有表索引后改善不大,
通过Show contig再查看系统表,发现系统表扫描密度很低
sysobjects又不能通过dbcc来重建索引的,请高手指点如果提升系统表的扫描密度
------解决方案--------------------
/*Perform a 'USE <database name>' to select the database in which to run the script.*/
-- Declare variables
SET NOCOUNT ON;
DECLARE @tablename varchar(255);
DECLARE @execstr varchar(400);
DECLARE @objectid int;
DECLARE @indexid int;
DECLARE @frag decimal;
DECLARE @maxfrag decimal;
-- Decide on the maximum fragmentation to allow for.
SELECT @maxfrag = 30.0;
-- Declare a cursor.
DECLARE tables CURSOR FOR
SELECT TABLE_SCHEMA + '.' + TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE';
-- Create the table.
CREATE TABLE #fraglist (
ObjectName char(255),
ObjectId int,
IndexName char(255),
IndexId int,
Lvl int,
CountPages int,
CountRows int,
MinRecSize int,
MaxRecSize int,
AvgRecSize int,
ForRecCount int,
Extents int,
ExtentSwitches int,
AvgFreeBytes int,
AvgPageDensity int,
ScanDensity decimal,
BestCount int,
ActualCount int,
LogicalFrag decimal,
ExtentFrag decimal);
-- Open the cursor.
OPEN tables;
-- Loop through all the tables in the database.
FETCH NEXT
FROM tables
INTO @tablename;
WHILE @@FETCH_STATUS = 0
BEGIN;
-- Do the showcontig of all indexes of the table
INSERT INTO #fraglist
EXEC ('DBCC SHOWCONTIG (''' + @tablename + ''')
WITH FAST, TABLERESULTS, ALL_INDEXES, NO_INFOMSGS');
FETCH NEXT
FROM tables
INTO @tablename;
END;
-- Close and deallocate the cursor.
CLOSE tables;
DEALLOCATE tables;
-- Declare the cursor for the list of indexes to be defragged.
DECLARE indexes CURSOR FOR
SELECT ObjectName, ObjectId, IndexId, LogicalFrag
FROM #fraglist
WHERE LogicalFrag >= @maxfrag
AND INDEXPROPERTY (ObjectId, IndexName, 'IndexDepth') > 0;
-- Open the cursor.
OPEN indexes;