针对调用上下文的数据库中 reorg defrag 的所有适用对象或适用于 reorg defrag 的给定对象报告碎片整理信息。
sp_helpdefrag 在每个必需表或必需数据分区上使用内置函数 defrag_status() 来获取有关碎片整理的信息。
<table_name>,则会报告 <reorg defrag> 的所有适用表(即带有数据行或数据页锁定方案的用户表)的碎片整理信息。当前正在执行 <reorg defrag> 的表的行的优先级要高于当前未执行 <reorg defrag> 的表的行的优先级。在上述两个设置中,行按升序顺序显示 pct_defrag。
<reorg defrag>,则将报告表的碎片整理信息以及各个数据分区的碎片整理信息。行按升序顺序显示已经过碎片整理的分区所占的比例。表行排在首位且在分区列中具有 NULL。
<partition_name>,则将报告特定数据分区的信息。
sp_helpdefrag [<table_name>][,<partition_name>]
<table_name>
是表的名称。
<partition_name>
是分区的名称。
如果在碎片整理前在数据库 testdb 中无参数且使用用户仅数据锁定表的情况下执行 sp_helpdefrag:
sp_helpdefrag
输出为:
table frag_index pct_defrag executing last_run
------------- ------------ ------------ ----------- ----------
t1_forw 0.01 0 0 NULL
mymsgs 0.39 0 0 NULL
mymsgs_clone 0.57 0 0 NULL
t1 0.66 0 0 NULL
myprocs 0.86 0 0 NULL
mymsgs_ptnd 1.07 0 0 NULL
t1_clone 1.98 0 0 NULL
myprocs_clone 2.16 0 0 NULL
t1_ptnd 2.99 0 0 NULL
myprocs_ptnd 3.03 0 0 NULL
(1 row affected)
(return status = 0)
如果在碎片整理后执行 sp_helpdefrag,则输出为:
table frag_index pct_defrag executing last_run
------------- ------------ ------------ ----------- --------------
t1_forw 0.01 100 0 Oct 10 2012 4:15PM
mymsgs 0.05 100 0 Oct 10 2012 4:15PM
mymsgs_clone 0.06 100 0 Oct 10 2012 4:15PM
t1 0.08 100 0 Oct 10 2012 4:15PM
myprocs 0.09 100 0 Oct 10 2012 4:15PM
mymsgs_ptnd 0.09 100 0 Oct 10 2012 4:15PM
t1_clone 0.10 100 0 Oct 10 2012 4:15PM
myprocs_clone 0.11 100 0 Oct 10 2012 4:15PM
t1_ptnd 0.12 100 0 Oct 10 2012 4:15PM
myprocs_ptnd 0.14 100 0 Oct 10 2012 4:15PM
(1 row affected)
(return status = 0)
如果在数据库 testdb 的表 t1 上执行 sp_helpdefrag:
sp_helpdefrag t1
输出为:
table partition frag_index pct_defrag executing last_run
------ ---------- ----------- ------------ ---------- -----------------
t1 NULL 0.35 35 0 Oct 10 2012 4:33PM
t1 p2 0.50 0 0 NULL
t1 p1 0.42 20 0 Oct 10 2012 4:33PM
t1 p3 0.42 20 0 Oct 10 2012 4:33PM
t1 p4 0.05 100 0 Oct 10 2012 4:33PM
(1 row affected)
(return status = 0)
如果当前正在处理 reorg defrag,则输出为:
table partition frag_index pct_defrag executing last_run
------- ---------- ----------- ------------ ---------- -----------------
t1 NULL 0.48 13 1 Oct 10 2012 4:33PM
t1 p2 0.50 0 1 NULL
t1 p4 0.60 0 1 Oct 10 2012 4:33PM
t1 p1 0.42 20 1 Oct 10 2012 4:33PM
t1 p3 0.42 20 1 Oct 10 2012 4:33PM
(1 row affected)
(return status = 0)
如果在表 t1 的分区 p1 上执行 sp_helpdefrag:
sp_helpdefrag t1, p1
输出为:
table partition frag_index pct_defrag executing last_run
------- ---------- ----------- ------------ ---------- -----------------
t1 p1 0.42 20 0 Oct 10 2012 4:33PM
(1 row affected)
(return status = 0)