【问题标题】:Postgres invalid memory alloc request size 1073741824Postgres 无效的内存分配请求大小 1073741824
【发布时间】:2019-06-16 08:25:14
【问题描述】:

当我运行持久查询 [1] 以根据子查询的结果更新几何列时,我收到以下错误“无效的内存分配请求大小 1073741824”。

有人知道如何解决这个错误吗?或者如何修改更新查询以更好地生成几何?

[1]

UPDATE hp 
SET the_geom = lines.the_geom 
FROM (
    SELECT hp_id, st_makeline(the_geom) the_geom
    FROM ( 
        SELECT hp_id, st_collect(the_geom) the_geom
        FROM (
            SELECT sbp.hp_id, point_sequence, sobr.the_geom
            FROM sbp 
            JOIN sobr ON sbp.bp_id=sobr.id
            ORDER BY hp_id, point_sequence
        ) t
        GROUP BY hp_id
    ) tt
    GROUP BY hp_id) lines 
WHERE lines.hp_id = hp.id AND hp.the_geom IS NULL;

这是查询计划:

Update on hp  (cost=133655367.27..139530992.38 rows=1 width=268)
  ->  Nested Loop  (cost=133655367.27..139530992.38 rows=1 width=268)
        ->  Subquery Scan on lines  (cost=133655366.69..139529271.88 rows=200 width=104)
              ->  GroupAggregate  (cost=133655366.69..139529269.88 rows=200 width=40)
                    Group Key: sbp.hp_id
                    ->  GroupAggregate  (cost=133655366.69..139510248.44 rows=1267929 width=40)
                          Group Key: sbp.hp_id
                          ->  Sort  (cost=133655366.69..134489514.21 rows=333659008 width=48)
                                Sort Key: sbp.hp_id, sbp.poradove_cislo_bodu
                                ->  Hash Join  (cost=7282892.98..76155670.90 rows=333659008 width=48)
                                      Hash Cond: (sbp.bp_id = sobr.id)
                                      ->  Seq Scan on sbp  (cost=0.00..8104984.08 rows=333659008 width=24)
                                      ->  Hash  (cost=4761304.88..4761304.88 rows=124139688 width=40)
                                            ->  Seq Scan on sobr  (cost=0.00..4761304.88 rows=124139688 width=40)
        ->  Index Scan using hp_id_key on hp  (cost=0.57..8.59 rows=1 width=172)
              Index Cond: (id = lines.hp_id)
              Filter: (the_geom IS NULL)

感谢所有建议!

【问题讨论】:

    标签: sql postgresql postgis postgresql-9.6


    【解决方案1】:

    我认为您采取了不必要的步骤,我会尝试:

    SET the_geom = lines.the_geom 
    FROM (
        SELECT sbp.hp_id,
        st_makeline(sobr.the_geom ORDER BY hp_id, point_sequence) as the_geom
        FROM sbp 
        JOIN sobr 
        ON sbp.bp_id=sobr.id
        GROUP BY hp_id
        ) lines
    WHERE lines.hp_id = hp.id AND hp.the_geom IS NULL;
    

    但如果没有样本数据,我不能 100% 确定它会起作用

    【讨论】:

    • 谢谢!它似乎可以正常工作并且速度更快!
    猜你喜欢
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-30
    • 2017-01-18
    • 2021-12-12
    • 1970-01-01
    • 2020-12-06
    相关资源
    最近更新 更多