File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed
Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -169,7 +169,7 @@ https://help.aliyun.com/document_detail/35457.html
169169create writeable external table oss_ext ....;
170170```
171171
172- 3\. 3 导入到HybridDB for PostgreSQL
172+ 3\. 3 导入(合并,存在则更新,不存在则插入)到HybridDB for PostgreSQL
173173
174174```
175175begin;
@@ -189,6 +189,42 @@ insert into feed_uniq (...) select * from oss_ext;
189189调用OSS API清除对应的oss bucket
190190```
191191
192+ 附加知识点,如果目标端是PG,可以用insert xxx on conflict xxx do xxx;的合并语法。如果是9.5以前的版本,可以使用函数合并的方法例如:
193+
194+ ```
195+ do language plpgsql $$
196+ declare
197+ x tmp;
198+ begin
199+ for x in select * from tmp
200+ loop
201+ update old_tbl set xx=xx where pk=x.pk;
202+ if not found then
203+ insert into old_tbl values (x.*);
204+ end if;
205+ end loop;
206+ exception when others then
207+ return;
208+ end;
209+ $$;
210+ ```
211+
212+ 注意,HDB请不要使用以上函数式MERGE方法,因为HDB的所有DML都是2PC的,单条单条的处理性能不好,如果使用了列存则有一个更加严重的问题。
213+
214+ HDB的列存是每次事务结束记录列存BLOCK级别偏移量作为事务结束标记,需要调用系统的FSYNC接口进行持久化,一个事务不管多大,凡是事务结束时,每个列对应的数据文件的最后一个追加的BLOCK是需要被冻结的,下次事务就会使用新追加的BLOCK。
215+
216+ 由于HDB的列存储持久化机制的问题,如果我们使用类似PostgreSQL的insert on conflict或function合并的方法,会导致非常严重的性能问题。
217+
218+ 建议HDB的数据合并,采用三步走的方法。
219+
220+ 1、需要合并的数据写入临时表。
221+
222+ 2、采用delete from xx using tmp where xx.pk=tmp.pk;删除重复数据。
223+
224+ 3、采用insert into xx select * from tmp;写入。
225+
226+ 以上三步可以在事务中完成。
227+
192228### 调度系统
193229将以上的调度事务,写入调度平台,设置好依赖关系,就可以实现增量、准实时的数据写入到HybridDB for PostgreSQL了。
194230
You can’t perform that action at this time.
0 commit comments