如何解决为什么我的执行计划与索引相同,但有时没有索引?
我在使用和不使用索引的情况下测试了我的程序以比较结果。我的问题是我不知道为什么我测试时我的空间索引在执行计划中没有显示,但有时在执行计划中缺少索引;我不知道为什么我有这个,有人可以帮忙吗?我的程序看起来像:
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 举报,一经查实,本站将立刻删除。