【发布时间】:2012-10-07 19:19:56
【问题描述】:
我有一个位于 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.
希望有人可能会看到我的明显疏忽。非常感谢!
【问题讨论】:
-
我将开始寻找 5TB RAID-0 的 SSD :)
-
请发布“一般错误”消息。可能会有所帮助。
-
查询计划是什么样的?具体来说,它们与您的小型数据集和大型数据集有何不同?
-
@usr - 错误是
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. -
@BenThul - 似乎因为大数据的错误,执行计划永远不会完成。
标签: sql-server tsql spatial-index