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

2020-01-13 11:42:02 +08:00
 rockyou12

数据库是 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");

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

2196 次点击
所在节点    数据库
4 条回复
nandaye
2020-01-13 11:46:45 +08:00
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
2020-01-13 14:20:42 +08:00
@nandaye 感谢,思路懂了
dswyzx
2020-01-13 16:15:43 +08:00
@nandaye 跟建索引一个套路哇.
duhui
2020-01-14 09:40:32 +08:00
drot table t_gps; 改成 rename t_gps to t_gps_bak; 比较好吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/637431

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX