Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 如何用程序进行地理性能测试_Sql Server_Performance_Stored Procedures_Indexing_Geospatial - Fatal编程技术网

Sql server 如何用程序进行地理性能测试

Sql server 如何用程序进行地理性能测试,sql-server,performance,stored-procedures,indexing,geospatial,Sql Server,Performance,Stored Procedures,Indexing,Geospatial,我想测试我的过程在有索引和没有索引的情况下的性能,并比较运行时间和cpu时间。我的程序如下所示: create procedure p_search_vehicle @IdCustomer int, @idGroupVehicle int = null, @ResultCount int= null, @Radiant int= null as begin if @IdCustomer is null begin print 'T

我想测试我的过程在有索引和没有索引的情况下的性能,并比较运行时间和cpu时间。我的程序如下所示:

create procedure p_search_vehicle
    @IdCustomer int,
    @idGroupVehicle int = null,
    @ResultCount int= null,
    @Radiant int= null 
as
begin
    if @IdCustomer is null
    begin
        print 'The argument cannot be null'
        return 
    end

    declare @start geography

    set @start = (select location from Customer where idCustomer = @idCustomer)

    --- @Result null group null radiant null
    if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
        select top 10 
            idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
        from 
            Vehicle 
        where 
            (@start.STDistance(locationVehicle)/1000 is not null)
        order by 
            @start.STDistance(locationVehicle)/1000 asc
    ---@Result null  radiant null
    else if @ResultCount is null and @Radiant is null
        select top 10 
            idVehicle, idGroupVehicle, brand, model, maxRange, weight, maxSpeed, nameLocation, @start.STDistance(locationVehicle)/1000 as distanceInKm
        from 
            Vehicle 
        where  
            idGroupVehicle = @idGroupVehicle 
            and (@start.STDistance(locationVehicle)/1000  is not null)
        order by 
            @start.STDistance(locationVehicle)/1000 asc
    ---@Result null  
    else if @Radiant is null
        select top(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where idGroupVehicle= @idGroupVehicle  and  (@start.STDistance(locationVehicle)/1000  is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
             ---@@idGroupVehicle  null @Radiant is null
            else if  @idGroupVehicle is null and @Radiant is null
    select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000  is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
            ---@idGroupVehicle is null and @ResultCount is null
            else if  @idGroupVehicle is null and @ResultCount is null
    select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000   <= @Radiant)
            order by @start.STDistance(locationVehicle)/1000 asc
        --- @idGroupVehicle is null 
            else if  @idGroupVehicle is null 
    select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000   <= @Radiant)
            order by @start.STDistance(locationVehicle)/1000 asc
            --- all options
    else
    select TOP(@ResultCount) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where idGroupVehicle= @idGroupVehicle  and  (@start.STDistance(locationVehicle)/1000  <= @Radiant)
            order by @start.STDistance(locationVehicle)/1000 asc
 end
 go
我已经使用SET STATISTICS IO,TIME ON测试了这个过程 DBCC-FREEPROCCACHE; DBCC缓冲区; 检查站 去吧,但我必须改变一些测试工作的东西,永久设置所有参数,扔掉创建过程和声明每个参数

SET STATISTICS IO, TIME ON 
DBCC FREEPROCCACHE; 
DBCC DROPCLEANBUFFERS; 
CHECKPOINT
GO
declare @IdCustomer int = 1,
 @idGroupVehicle int = null,
 @ResultCount int= null,
 @Radiant int= null 
 begin
 if @IdCustomer is null
    begin
        print 'The argument cannot be null'
        return 
    end
 declare @start geography
 SET @start = (select location from Customer where idCustomer=@idCustomer )
 ---@Result null group null radiant null
    if @ResultCount is null and @idGroupVehicle is null and @Radiant is null
    begin
    select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where (@start.STDistance(locationVehicle)/1000 is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
             ---@Result null  radiant null
             if @ResultCount is null and @Radiant is null
            begin
    select  top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  idGroupVehicle= 1 and (@start.STDistance(locationVehicle)/1000  is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
             ---@Result null  
             if @Radiant is null
            begin
    select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where idGroupVehicle= 1  and  (@start.STDistance(locationVehicle)/1000  is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
             ---@@idGroupVehicle  null @Radiant is null
             if  @idGroupVehicle is null and @Radiant is null
            begin
    select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000  is not null)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
            ---@idGroupVehicle is null and @ResultCount is null
             if  @idGroupVehicle is null and @ResultCount is null
            begin
    select top 10 idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000   <= 1)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
        --- @idGroupVehicle is null 
             if  @idGroupVehicle is null 
            begin
    select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where  (@start.STDistance(locationVehicle)/1000   <= 1)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
            --- all options
    else
    begin
    select TOP(5) idVehicle,idGroupVehicle,brand,model,maxRange,weight,maxSpeed, nameLocation , @start.STDistance(locationVehicle)/1000 as distanceInKm
        from Vehicle 
            where idGroupVehicle= 1  and  (@start.STDistance(locationVehicle)/1000  <= 1)
            order by @start.STDistance(locationVehicle)/1000 asc
            end
end
是否可以以其他方式测试过程,以显示受影响的执行时间和行,而不对过程进行任何更改?

您不必将过程转换为测试脚本。而只是调用它。不要使用冷过程或页面缓存进行测试。这是一种非常不寻常的状态

SET STATISTICS IO, TIME ON 
GO

declare @IdCustomer int = 1,
 @idGroupVehicle int = null,
 @ResultCount int= null,
 @Radiant int= null 

exec p_search_vehicle @IdCustomer, @idGroupVehicle, @ResultCount, @Radiant
GO
SET STATISTICS IO, TIME OFF

统计IO通常是性能的最佳指标,特别是逻辑读取。从执行计划的属性中可以收集到更多的信息-您查看了每个计划了吗?我希望从这个过程中可以看到很多表扫描,因为STDistance使用的sqrt操作可能非常昂贵。Query planner可能不够聪明,无法在希望看到geography1.STDistancegeography2时使用空间索引。它是搜索-不是shearch…是的,我查看了计划,但此过程的计划与索引相同,没有索引可能我没有足够的数据?