我有一个位于 SQL Server 2008 上的数据库,其中包含约 120 亿行,所有行都包含纬度、经度和相应的地理字段。我最近需要添加对地理字段的查询功能。我添加了空间索引,处理超过 4TB 的数据需要 6 天。
CREATE SPATIAL INDEX IX_Location_Geo ON Location
(
Geo
) USING GEOGRAPHY_GRID
WITH (
GRIDS =(LEVEL_1 = MEDIUM,LEVEL_2 = MEDIUM,LEVEL_3 = MEDIUM,LEVEL_4 = MEDIUM),
CELLS_PER_OBJECT = 16, PAD_INDEX = OFF, SORT_IN_TEMPDB = OFF,
DROP_EXISTING = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON PRIMARY
GO
使用这样的查询添加预期......
SELECT TOP 100
ci.LocationID, ci.Geo.STDistance(@g)
FROM Location ci WITH(INDEX(IX_Location_Geo))
WHERE ci.Geo.Filter(@region) = 1
ORDER BY ci.Geo.STDistance(@g)
这是估计的执行计划......
我在 100 个轧机行的样本集上测试了这个查询,它工作得非常好。但是在 12 个账单行上,查询在约 4 小时后没有响应,最后由于磁盘写入错误而失败,这很奇怪,因为磁盘有 5TB 未使用。
Msg 1101, Level 17, State 10, Line 4 Could not allocate a new page
for database 'TEMPDB' because of insufficient disk space in filegroup
'DEFAULT'. Create the necessary space by dropping objects in the filegroup,
adding additional files to the filegroup, or setting autogrowth on for
existing files in the filegroup.
希望有人可能会看到我的明显疏忽。非常感谢!