rockyou12
V2EX  ›  数据库

要 update 个 3000W 行的大表做数据 migration,怎么操作比较好

  •  
  •   rockyou12 · Jan 13, 2020 · 3087 views
    This topic created in 2321 days ago, the information mentioned may be changed or developed.

    数据库是 postgresql,以前经纬度用的单独字段,现在像用 point 类型再加 postgis 做分析。表有优化,相当于做了表分区,现在 sql 是

    update t_gps
    set location = ST_GeomFromText('Point(' || "lont" || ' ' || "lat" || ')', 4326);
    create index idx_gps_location on t_gps using gist ("location");
    

    但在测试库试了下,真的很慢。一般这种更新方案怎么做比较好?

    4 replies    2020-01-14 09:40:32 +08:00
    nandaye
        1
    nandaye  
       Jan 13, 2020   ❤️ 1
    create table test as select t_gps.*,ST_GeomFromText('Point(' || "lont" || ' ' || "lat" || ')', 4326) as location from t_gps;
    drot table t_gps;
    rename test to t_gps;
    rockyou12
        2
    rockyou12  
    OP
       Jan 13, 2020
    @nandaye 感谢,思路懂了
    dswyzx
        3
    dswyzx  
       Jan 13, 2020
    @nandaye 跟建索引一个套路哇.
    duhui
        4
    duhui  
       Jan 14, 2020
    drot table t_gps; 改成 rename t_gps to t_gps_bak; 比较好吧
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4104 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 10:12 · PVG 18:12 · LAX 03:12 · JFK 06:12
    ♥ Do have faith in what you're doing.