我在db A中有一个查询,它显示了索引碎片级别和最近重建或重新组织的状态,它在db C中交叉应用函数B,A和C在同一个实例上。
功能B是:
ALTER function [dbo].[B]
(
@db_id int
,@object_id int
,@index_id int
,@partition_number int
,@mode varchar (20)
)
returns @results TABLE (
[database_id] [smallint] NULL,
[object_id] [int] NULL,
[index_id] [int] NULL,
[partition_number] [int] NULL,
[index_type_desc] [nvarchar](60) NULL,
[alloc_unit_type_desc] [nvarchar](60) NULL,
[index_depth] [tinyint] NULL,
[index_level] [tinyint] NULL,
[avg_fragmentation_in_percent] [float] NULL,
[fragment_count] [bigint] NULL,
[avg_fragment_size_in_pages] [float] NULL,
[page_count] [bigint] NULL,
[avg_page_space_used_in_percent] [float] NULL,
[record_count] [bigint] NULL,
[ghost_record_count] [bigint] NULL,
[version_ghost_record_count] [bigint] NULL,
[min_record_size_in_bytes] [int] NULL,
[max_record_size_in_bytes] [int] NULL,
[avg_record_size_in_bytes] [float] NULL,
[forwarded_record_count] [bigint] NULL,
[compressed_page_count] [bigint] NULL
)
begin
insert into @results
select *
from sys.dm_db_index_physical_stats (@db_id, @object_id, @index_id ,@partition_number
,@mode )
return
end
此查询需要很长时间才能执行。我读了查询计划,该计划包含一个“远程扫描”。我不明白为什么会这样。
有人可以帮忙吗?
谢谢,