Last active
July 29, 2019 16:26
-
-
Save lwzm/c93f274ad7e9f2dd0f7afe0f18158c05 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- _ 是老数据,想把 t 作为补丁更新至 _ , 参考下面 | |
-- 执行速度只和 t 的数据量有关,和目标 _ 数据量关系不大(索引),t 数据量有 100W 时,2秒搞定 | |
select 'edit'; | |
replace into _ (k, v) | |
select t.k, t.v from t inner JOIN _ on t.k=_.k where t.v!=_.v; -- update exists | |
select changes(); | |
select 'new'; | |
insert into _ (k, v) | |
select t.k, t.v from t left JOIN _ on t.k=_.k where _.v is null; -- find new | |
select changes(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment