问题描述
我在使用和不使用索引的情况下测试了我的程序以比较结果。我的问题是我不知道为什么我测试时我的空间索引在执行计划中没有显示,但有时在执行计划中缺少索引;我不知道为什么我有这个,有人可以帮忙吗?我的程序看起来像:
create procedure [dbo].[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,@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
---@Radiant null
else if @Radiant is null
select TOP(@ResultCount) idVehicle,@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,@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,@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,@start.Stdistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where (@start.Stdistance(locationVehicle)/1000 <= @Radiant)
order by @start.Stdistance(locationVehicle)/1000 asc
--- @Result is null
else if @ResultCount is null
select TOP(10) idVehicle,@start.Stdistance(locationVehicle)/1000 as distanceInKm
from Vehicle
where idGroupVehicle= @idGroupVehicle and (@start.Stdistance(locationVehicle)/1000 <= @Radiant)
order by @start.Stdistance(locationVehicle)/1000 asc
--- all options
else
select TOP(@ResultCount) idVehicle,@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
这个程序返回离用户最近的车辆列表 我有一个桌子车辆的空间索引是
CREATE SPATIAL INDEX [SIndx_Vehicle_locationVehicle] ON [dbo].[Vehicle]
(
[locationVehicle]
)USING GEOGRAPHY_AUTO_GRID
WITH (
CELLS_PER_OBJECT = 12,PAD_INDEX = OFF,STATISTICS_norECOmpuTE = OFF,SORT_IN_TEMPDB = OFF,DROP_EXISTING = OFF,ONLINE = OFF,ALLOW_ROW_LOCKS = ON,ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
当我使用 set statistics io on
测试此过程时,我在执行计划中没有看到我的空间索引。我不知道为什么,但我有一条缺少索引的绿色消息。
谁能解释为什么我有索引和没有索引的执行计划相同?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)