在 SQL Server 2008 R2 中使用几何时释放内存

发布于 2025-01-17 12:54:07 字数 1716 浏览 0 评论 0原文

该文本在Google翻译中翻译。

当使用SQL Server 2008 R2中的几何函数时,我注意到我的服务器内存正在增加,并且我无法发布使用的内存。

我有一张桌子,我们存储不同的多边形,覆盖了我城市的不同社区。

CREATE TABLE dbo.Mapa_MSB (
  id int IDENTITY(1, 1) NOT NULL,
  zona varchar(50),
  GeogCol1 geometry,
  GeogCol2 AS [GeogCol1].[STAsText]()
)

因此,我有一个函数,其参数是我城市中一个点的坐标,因此它返回了点输入的不同多边形。使用坐标,我使用几何形状:: stgeomfromtext('point(x,y)',4326)

declare @geo geometry
declare @flete geometry
declare @result geometry

set @geo = geometry::STGeomFromText('POINT(-100.35171446 25.66744965)', 4326)

,然后我将一个光标从我的mapa_msb表中读取所有多边形,我使用稳定功能使我返回我是否进入多边形,结果存储在临时内存中,最后我执行一个简单的查询以获取有相交的不同多边形。

declare @resultado_temporal table(
    resultado varchar(max),
    zona varchar(50))

declare @id int,
        @zona varchar(50),
        @GeogCol1 geometry
                
declare localiza_cursor cursor for
select id, zona, GeogCol1
from Zonas2.dbo.Mapa_MSB
        
open localiza_cursor

fetch next from localiza_cursor
into @id, @zona, @GeogCol1

while @@FETCH_STATUS = 0
begin
    select @flete = GeogCol1 from Zonas2.dbo.Mapa_MSB where id = @id    
    
    set @flete = @flete.MakeValid()
    
    if @flete.STIsValid() = 1
    begin
        select @result = @flete.STIntersection(@geo)
    
        insert into @resultado_temporal
        select @result.STAsText(), @zona
        where @result.STAsText() <> 'GEOMETRYCOLLECTION EMPTY'
    end
    
    fetch next from localiza_cursor
    into @id, @zona, @GeogCol1  
end

close localiza_cursor
deallocate localiza_cursor

select * from @resultado_temporal

每当我使用此过程时,服务器的内存都会上升,我该怎么做才能优化此过程,或者以使服务器的内存不会上升?

This text was translated in Google Translate.

When using the geometry functions in SQL Server 2008 R2, I have noticed that my server memory is increasing, and I have no way to release used memory.

I have a table where we store the different polygons that cover the different neighborhoods of my city.

CREATE TABLE dbo.Mapa_MSB (
  id int IDENTITY(1, 1) NOT NULL,
  zona varchar(50),
  GeogCol1 geometry,
  GeogCol2 AS [GeogCol1].[STAsText]()
)

So, I have a function whose parameters are the coordinates of a point in my city, and with this it returns the different polygons that point enters. With the coordinates I create my point using geometry::STGeomFromText('POINT(X, Y)', 4326)

declare @geo geometry
declare @flete geometry
declare @result geometry

set @geo = geometry::STGeomFromText('POINT(-100.35171446 25.66744965)', 4326)

Then I make a cursor to read all my polygons from my Mapa_MSB table, and I use the STIntersection function so that it returns me whether or not that point enters that polygon, the result is stored in a temporary memory, and at the end I perform a simple query to obtain the different polygons where there was an intersection.

declare @resultado_temporal table(
    resultado varchar(max),
    zona varchar(50))

declare @id int,
        @zona varchar(50),
        @GeogCol1 geometry
                
declare localiza_cursor cursor for
select id, zona, GeogCol1
from Zonas2.dbo.Mapa_MSB
        
open localiza_cursor

fetch next from localiza_cursor
into @id, @zona, @GeogCol1

while @@FETCH_STATUS = 0
begin
    select @flete = GeogCol1 from Zonas2.dbo.Mapa_MSB where id = @id    
    
    set @flete = @flete.MakeValid()
    
    if @flete.STIsValid() = 1
    begin
        select @result = @flete.STIntersection(@geo)
    
        insert into @resultado_temporal
        select @result.STAsText(), @zona
        where @result.STAsText() <> 'GEOMETRYCOLLECTION EMPTY'
    end
    
    fetch next from localiza_cursor
    into @id, @zona, @GeogCol1  
end

close localiza_cursor
deallocate localiza_cursor

select * from @resultado_temporal

Every time I use this procedure, the memory of my server is going up, what can I do to optimize this procedure or so that the memory of the server does not go up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看轻我的陪伴 2025-01-24 12:54:07

我已经设法优化了代码,我找到了“Beginning Spatial with SQL Server 2008”这本书,其中他们建议使用Filter()函数,所以我设法优化代码,如下所示:

declare @geo geometry

set @geo = geometry::STGeomFromText('POINT(-100.35171446 25.66744965)', 4326)

select GeogCol2, zona
from Zonas2.dbo.Mapa_MSB
where GeogCol1.MakeValid().Filter(@geo) = 1 

I already managed to optimize the code, I found the book "Beginning Spatial with SQL Server 2008", where they recommend using the Filter() function, so I managed to optimize the code, being like this:

declare @geo geometry

set @geo = geometry::STGeomFromText('POINT(-100.35171446 25.66744965)', 4326)

select GeogCol2, zona
from Zonas2.dbo.Mapa_MSB
where GeogCol1.MakeValid().Filter(@geo) = 1 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文