之前是采用的join的方法来增量更新。详情见:
http://blog.youkuaiyun.com/qq_20641565/article/details/52763663
现在有一种新方案如下:
Select b.id,b.name,b.addr,b.updated_date
From
(
select a.*,row_number() over(distribute by a.id sort by updated_date) as rn
from
(
Select id,name,addr, updated_date from test
Union all
Select id,name,addr, updated_date from test_delta
where y=’2016’ and m=’10’ and d=’09’
) a
) b
Where b.rn = 1
把中间表和最终表进行union all合并,然后取出相同主键的那条数据updated_date最新的那条数据。
这种方法和前面left join的方法都很消耗性能,其中left join是合并的时候消耗性能,而union all 是排序的时候消耗性能。总体测试上面来看,union all 略优于 left join