您现在的位置是:主页 > news > wordpress 回复提醒/重庆百度seo
wordpress 回复提醒/重庆百度seo
admin2025/4/28 0:25:29【news】
简介wordpress 回复提醒,重庆百度seo,qq浏览器小程序,深圳专业网站建设公司多少钱项目背景: 最近在做异构数据同步方面(非实时)的工作,从oracle,gbase,postgresql向mysql数据库中同步,对于没有自增字段(自增ID或时间字段)的业务表,做差异同步是一件非常麻烦的事情…
项目背景:
最近在做异构数据同步方面(非实时)的工作,从oracle,gbase,postgresql向mysql数据库中同步,对于没有自增字段(自增ID或时间字段)的业务表,做差异同步是一件非常麻烦的事情,主要体现在记录的新增、更新与删除上
备注:源库只提供一个只读权限的用户
ctid在pg中的作用
ctid是用来指向自身或新元组的元组标识符,怎么理解呢?下面能过几个实验来测试一下
satdb=# create table test_ctid(id int,name varchar(100));
satdb=# insert into test_ctid values(1,‘a’),(1,‘a’);
satdb=# insert into test_ctid values(2,‘a’),(3,‘a’);
查看记录的ctid值
satdb=# select id,name,ctid from test_ctid;
id | name | ctid
----±-----±------
1 | a | (0,1)
1 | a | (0,2)
2 | a | (0,3)
3 | a | (0,4)
(4 rows)
对id为2的记录进行更新
satdb=# update test_ctid set name=‘b’ where id=2;
UPDATE 1
这里可以看到id=2的记录指向了新的元组标识符 (0,5)
satdb=# select id,name,ctid from test_ctid;
id | name | ctid
----±-----±------
1 | a | (0,1)
1 | a | (0,2)
3 | a | (0,4)
2 | b | (0,5)
(4 rows)
satdb=# select * from test_ctid where ctid=’(0,1)’;
id | name
----±-----
1 | a
(1 row)
删除 id=3的记录后,对应的ctid(0,4)不存在了
satdb=# delete from test_ctid where id=3;
DELETE 1
satdb=# select *,ctid from test_ctid;
id | name | ctid
----±-----±------
1 | a | (0,1)
1 | a | (0,2)
2 | b | (0,5)
(3 rows)
再插入一条记录时,看看会不会使用(0,4)这个标识符
satdb=# insert into test_ctid values(3,‘d’);
INSERT 0 1
satdb=# select *,ctid from test_ctid;
id | name | ctid
----±-----±------
1 | a | (0,1)
1 | a | (0,2)
2 | b | (0,5)
3 | d | (0,6)
这里新插入的记录不会使用(0,4),而是直接分配新的标识符(0,6)
总结:
1、ctid的作用与oracle rowid类似,可以唯一标识一条记录
2、记录的更新后,后生产新的ctid
3、记录删除后,新插入的记录不会使用已经删除记录的ctid
4、基于ctid可以实现记录的去重操作
5、基于ctid可以实现差异增量同步(新增、删除、更新)