Sql server空间索引存储过程性能调优

时间:2015-11-12 19:45:07

标签: sql-server

大家好我正在对我的一个存储过程进行性能调优,该过程具有更新语句:

UPDATE e
        SET
            LNG_PROP  = GEOGRAPHY::STPointFromText(A.geom.STPointN(A.geom.STNumPoints()/2).ToString(), 4326).Long
            ,LAT_PROP = GEOGRAPHY::STPointFromText(A.geom.STPointN(A.geom.STNumPoints()/2).ToString(), 4326).Lat
        FROM
            Exports.SpatialKey_MTG22 e           
            INNER JOIN dbo.Addresses A WITH (NOLOCK) ON  A.FullName = e.ADDR_STREET_PROP AND ((e.ADDR_NUMBER_PROP BETWEEN LFROMHN AND LTOHN OR e.ADDR_NUMBER_PROP BETWEEN RFROMHN AND RTOHN) OR (e.ADDR_NUMBER_PROP BETWEEN LTOHN AND LFROMHN OR e.ADDR_NUMBER_PROP BETWEEN RTOHN AND RFROMHN))
            INNER JOIN dbo.ZipCodes Z WITH (NOLOCK) ON Z.ZipCode = A.ZipL OR Z.ZipCode = A.ZipR AND (Z.ZipCode = e.IC_PROP_ZIP OR (Z.State = e.IC_PROP_STATE AND Z.City = e.IC_PROP_CITY))

我尝试修改:

Select                     e.SpatialKey_MTG22_ID,e.AC_ACCOUNT_NAME,e.IC_PROP_ADDR_1,e.ADDR_NUMBER_PROP,e.ADDR_STREET_PROP,e.IC_PROP_CITY,e.IC_PROP_STATE,e.IC_PROP_ZIP
                     ,[LNG_PROP]  = GEOGRAPHY::STPointFromText(e.geom.STPointN(e.geom.STNumPoints()/2).ToString(), 4326).Long
                     ,[LAT_PROP] = GEOGRAPHY::STPointFromText(e.geom.STPointN(e.geom.STNumPoints()/2).ToString(), 4326).Lat
          FROM
       (
              SELECT e.*,A.geom,A.ZIPL,A.ZIPR
              FROM
                     Exports.SpatialKey_MTG22 e               
                     INNER JOIN dbo.Addresses A WITH (NOLOCK) 
                           ON  A.FullName = e.ADDR_STREET_PROP 
           WHERE
                     ((e.ADDR_NUMBER_PROP BETWEEN LFROMHN AND LTOHN OR e.ADDR_NUMBER_PROP BETWEEN RFROMHN AND RTOHN) 
                                         OR (e.ADDR_NUMBER_PROP BETWEEN LTOHN AND LFROMHN OR e.ADDR_NUMBER_PROP BETWEEN RTOHN AND RFROMHN))
       ) e
INNER JOIN dbo.ZipCodes Z WITH (NOLOCK) 
                           ON     (Z.ZipCode = e.ZipL OR Z.ZipCode = e.ZipR) 
                                  AND (Z.ZipCode = e.IC_PROP_ZIP OR (Z.State = e.IC_PROP_STATE AND Z.City = e.IC_PROP_CITY))

我在地址表中有2600万条记录 它还需要1个多小时才能运行。 任何人都可以帮助我做出改变,以便我可以改善表现。

0 个答案:

没有答案