V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rockyou12
V2EX  ›  数据库

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

  •  
  •   rockyou12 · 2020-01-13 11:42:02 +08:00 · 2183 次点击
    这是一个创建于 1558 天前的主题,其中的信息可能已经有所发展或是发生改变。

    数据库是 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 条回复    2020-01-14 09:40:32 +08:00
    nandaye
        1
    nandaye  
       2020-01-13 11:46:45 +08:00   ❤️ 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
       2020-01-13 14:20:42 +08:00
    @nandaye 感谢,思路懂了
    dswyzx
        3
    dswyzx  
       2020-01-13 16:15:43 +08:00
    @nandaye 跟建索引一个套路哇.
    duhui
        4
    duhui  
       2020-01-14 09:40:32 +08:00
    drot table t_gps; 改成 rename t_gps to t_gps_bak; 比较好吧
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   860 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 21:44 · PVG 05:44 · LAX 14:44 · JFK 17:44
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.