2012-06-07 115 views
2

我有一個數據庫在2 000 000行內與1個地理類型字段包含點。 在另一個數據表中,我有600行,其中包含1個包含多邊形的地理類型字段。Sql Server 2008空間查詢慢

This query to retrieve all the POINT in a POLYGON is very slow 

SELECT ID_POINT, ID_POLYGON FROM 
      (SELECT ID_POINT, COORD FROM POINT_TABLE) as POINT 
      (SELECT ID_POLYGON, COORD FROM POLYGON_TABLE WHERE ID_POLYGON = 276) as POLYGON 
     WHERE 
      (POINT.Coord.STIntersects(POLYGON.COORD) = 1) 

我有一個像這樣在每個表1個空間索引:

CREATE SPATIAL INDEX [IDX_POLYGON_COORD] ON [dbo].[POLYGON] 
(
    [COORD] 
)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 

能不能幫我加快此查詢?

問候

回答

1

這將主要取決於如何攤開你的數據,是否你對點表的索引(我假設這樣一個指數存在)與中介的柵格尺寸大小適當。

理想情況下,您的執行計劃應該在Polygon上顯示尋道以獲取第276行,然後在Point上尋找與多邊形相交的空間索引。它不應該慢。但是,如果Polygon表也不是在id_polygon上編制索引的,那麼在篩選到該行之前,您可能會發現它試圖加入地​​理位置。