我有一种非常可疑的感觉,这个更新触发器正在更新目标上的所有行,而不仅仅是那些满足“更新(形状)”测试的行。性能很好,直到我添加了第二个操作。单个空间连接发生得更快,这不是空间索引问题,而且该数据集中只有几条记录。
ALTER TRIGGER [dbo].[GRSM_WETLANDS_Point_GIS_tbl_locations_update]
ON [dbo].[GRSM_WETLANDS_POINT]
after update
AS
BEGIN
SET NOCOUNT ON;
if UPDATE (shape)
update GRSM_WETLANDS_Point
set X_Coord =CASE WHEN u.shape.STDimension() = 2 THEN u.shape.STCentroid().STX ELSE u.shape.STEnvelope().STCentroid().STX END,
Y_Coord =CASE WHEN u.shape.STDimension() = 2 THEN u.shape.STCentroid().STY ELSE u.shape.STEnvelope().STCentroid().STY END
from inserted i
inner join GRSM_WETLANDS_POint u on i.GIS_Location_ID = u.GIS_Location_ID;
--second spatial operation
update GRSM_WETLANDS_Point
set QuadName = grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES.name
FROM GRSM_WETLANDS_POint i
inner join grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES
on i.GIS_Location_ID = i.GIS_Location_ID
WHERE (USGS_24K_TOPOMAP_BOUNDARIES.Shape.STContains(i.SHAPE) = 1) ;
end
我的怀疑是对的吗?
更新:根据 Aaron 的建议...解决了所有行的火灾问题。
update GRSM_WETLANDS_Point
set QuadName = grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES.name
FROM inserted i inner join GRSM_WETLANDS_POint u on i.GIS_Location_ID = u.GIS_Location_ID
left outer join grsm.dbo.USGS_24K_TOPOMAP_BOUNDARIES
on i.GIS_Location_ID = i.GIS_Location_ID
WHERE (USGS_24K_TOPOMAP_BOUNDARIES.Shape.STContains(i.SHAPE) = 1);