以下查询在较高的缩放级别(边界框小于2度经度,纬度为0.5度)时表现非常好,但随着边界框变大而显着降低。该表包含7~800万行文本和位置数据存储作为几何列中的点。
我尝试过不同的网格配置,但是当边界框比@ north = 41.123029000000002,@ east = -72.935406,@ south = 40.296503999999999,@ west = -75.077740000000006
更大时,性能总是会下降有什么想法吗?谢谢〜马特
我在不同的缩放级别中包含了一个表格。
declare @filter geometry
select @filter = GEOMETRY::STGeomFromText(
'LINESTRING(' + CONVERT(varchar,@west) + ' ' + CONVERT(varchar,@south) + ',' + CONVERT(varchar,@east) + ' ' + CONVERT(varchar,@north) + ')'
,4326
).STEnvelope();
select
x.Id
,x.[Timestamp]
,x.Location
,x.[Text]
from (
select top(1000)
t.Id
,t.[Timestamp]
,t.Location
,t.[Text]
from dbo.Table1 AS t with (nolock, index([SPIX_Table1_Location_HIGH]))
inner join containstable(
dbo.Table1
,[text]
, N'FORMSOF(INFLECTIONAL, "word1") | FORMSOF(INFLECTIONAL, "word2") | FORMSOF(INFLECTIONAL, "wordN")'
) as r on t.Id = r.[KEY]
where t.Location.Filter(@filter) = 1
AND t.[Hour] >= @HourId
order by r.[RANK] desc
) as x
order by x.[Timestamp] desc
option (maxdop 1)
缩放等级2 = @ north = 74.542308000000006,@ east = 94.21875,@ south = -24.370607,@ west = -180 缩放等级20 = @ north = 40.711250999999997,@ east = -74.006050000000002,@ south = 40.710847000000001,@ west = -74.007096000000004
这是空间索引:
CREATE SPATIAL INDEX [SPIX_Table1_location_HIGH] ON [dbo].[Table1]
(
[location]
)USING GEOMETRY_GRID
WITH (
BOUNDING_BOX =(-180, -90, 180, 90), GRIDS =(LEVEL_1 = HIGH,LEVEL_2 = HIGH,LEVEL_3 = HIGH,LEVEL_4 = HIGH),
CELLS_PER_OBJECT = 16, FILLFACTOR = 70) ON [PRIMARY]
GO
按缩放级别请求持续时间(1000次随机测试):
Level Duration0to5 Duration5to10 Duration10to15 Duration15to20 DurationGreaterThan20
2 0 0 0 0 26
3 0 0 0 0 42
4 0 0 0 0 57
5 0 0 0 0 60
6 0 0 0 0 54
7 0 0 0 1 65
8 0 2 5 6 34
9 0 3 7 10 6
10 5 23 25 14 1
11 13 26 18 3 0
12 17 31 7 0 0
13 48 11 0 0 0
14 48 6 0 0 0
15 47 1 0 0 0
16 57 0 0 0 0
17 48 8 0 0 0
18 44 3 0 0 0
19 63 5 0 0 0
20 47 3 0 0 0
ALL 437 122 62 34 345
典型查询的行计数和执行时间,w / out top(1000),强制空间索引:
if (@level=2)
select @north=74.542308000000006,@east=94.21875,@south=-24.370607,@west=-180 --70,404 rows, 2 minutes w/ spatial
if (@level=3)
select @north=61.978465999999997,@east=-5.451886,@south=9.7052770000000006,@west=-142.56126 -- 57,911 rows, 1m22s w/ spatial
if (@level=4)
select @north=52.614061999999997,@east=-39.729228999999997,@south=26.230861999999998,@west=-108.283917 -- 45,636 rows, 1m23s w/ spatial
if (@level=5)
select @north=46.992624999999997,@east=-56.867901000000003,@south=33.775959999999998,@west=-91.145245000000003 -- 32,386 rows, 26s w/ spatial
if (@level=6)
select @north=43.934699999999999,@east=-65.437236999999996,@south=37.323439,@west=-82.575908999999996 -- 19,998 rows, 13s w/ spatial
if (@level=7)
select @north=42.343530999999999,@east=-69.721905000000007,@south=39.037540999999997,@west=-78.291240999999999 -- 11,256 rows, 13s w/ spatial
if (@level=8)
select @north=41.532438999999997,@east=-71.864238999999998,@south=39.879399999999997,@west=-76.148906999999994 -- 6,147 rows, 4s w/ spatial
if (@level=9)
select @north=41.123029000000002,@east=-72.935406,@south=40.296503999999999,@west=-75.077740000000006 -- 3,667 rows, 3s w/ spatial