【问题标题】:How to do geography performance test with procedures如何使用程序进行地理性能测试
【发布时间】:2021-07-06 02:27:41
【问题描述】:

我想测试我的程序在使用和不使用索引的情况下的性能,并比较经过的时间和 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

是否有可能以其他方式测试过程以显示受影响的执行时间和行,而不对过程进行任何更改?

【问题讨论】:

  • STATISTICS IO 通常是衡量性能的最佳指标,尤其是logical reads。可以从execution plan 的属性中收集更多信息 - 您是否查看过每个计划?
  • 我希望从这个过程中看到很多表扫描,因为STDistance() 使用sqrt() 操作可能会变得非常昂贵。查询规划器可能不够聪明,无法在预期看到 geography1.STDistance(geography2) &lt;= number 时使用空间索引,因为 /1000 可能会将其丢弃。
  • 这是 搜索 - 不是“搜索” ....
  • 是的,我审查了计划,但是这个程序的计划与索引相同,没有索引可能我没有足够的数据?

标签: sql-server performance stored-procedures indexing geospatial


【解决方案1】:

您不必将您的程序转换为测试脚本。取而代之的是 invoke 它。并且不要使用冷程序或页面缓存进行测试。这是一个非常不寻常的状态。

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

【讨论】:

    猜你喜欢
    • 2019-04-23
    • 2015-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多