分表优化:千万级数据的插入方法
考虑到数据优化,现将千万级数据作分表存储便与查询。
sql如何查找出number中第一位为1的数据:
标准写法:
select substring(cast(adv_id as varchar) from 1 for 1) as a1 from zhoz_sub_dat_6_3;
常规写法:
select substring(cast(adv_id as varchar), 1,1) as a1 from zhoz_sub_dat_6_3;
INSERT INTO zhoz_sub_dat_6_3
(media_id, adv_id, course_id, serial_code, os, carrier, media_referrer) SELECT media_id, adv_id, course_id, serial_code, os, carrier, media_referrer FROM zhoz_total_dat WHERE delete_flg=false AND substring(cast(adv_id as varchar), 1,1) = '2' AND substring(cast(media_id as varchar), 1,1) = '6';
这样执行多次就可以比较快速的Copy数据。
以上为PostgreSQL数据库,其它原理类似。
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30