AntDB是一款分布式数据库产品,其分布式的特性决定了当咱们使用某些字段,例如tableoid和xc_node_id系统字段,及enum类型字段,xc_node_id,xc_node_str(), adb_node_oid() GUC变量可能出现如下问题。node
一、各个节点的值不同,作等值、比较操做时须要注意,结果可能不正确;git
二、order by操做可能无效,只要是各个节点相同的值内部存储不相同的类型github
下面举例说明:sql
建立表,插入数据。数据库
create table tt(c1 int, c2 int, c3 text);分布式
insert into tt values(1,1,'a'), (2,2,'b'), (3,3,'c'), (4,4,'d') ;post
tableoid各个节点的值有可能不同测试
postgres=# select tableoid, * from tt;3d
tableoid | c1 | c2 | c3postgresql
----------+----+----+----
16410 | 1 | 1 | a
16410 | 2 | 2 | b
16412 | 3 | 3 | c
16412 | 4 | 4 | d
(4 rows)
在coordinator上:
在datanode上,tableoid和pg_class中关于此表的行。
由此可知,在coordinator上和不一样的datanode上,tableoid是有可能不一样的,所以,利用tableoid去做join操做可能得不到预期结果。
例如,利用在coordinator上利用tableoid和pg_class的oid做join获取表的名字,就得不到预期结果。
xc_node_id:
数据分布在两个datanode上,两个datanode的xc_node_id不一样。
postgres=# select xc_node_id, * from tt;
xc_node_id | c1 | c2 | c3
------------+----+----+----
1853972 | 1 | 1 | a
1853972 | 2 | 2 | b
709075352 | 3 | 3 | c
709075352 | 4 | 4 | d
(4 rows)
pgxc_node_str:不一样节点的pgxc_node_str名字不一样,与node表中起的名字同样。
postgres=# select * from pgxc_node_str();
pgxc_node_str
---------------
coord0
(1 row)
postgres=# select * from pgxc_node_str();
pgxc_node_str
---------------
dm0
(1 row)
adb_node_oid:
postgres=# select * from adb_node_oid();
adb_node_oid
--------------
11990
(1 row)
datanode上显示为0
postgres=# select * from adb_node_oid();
adb_node_oid
--------------
0
(1 row)
枚举类型字段:
测试:
CREATE TYPE rainbow AS ENUM ('red', 'orange', 'yellow', 'green', 'blue', 'purple');
CREATE TABLE enumtest (col rainbow);
INSERT INTO enumtest values ('yellow'), ('red'), ('green'), ('orange');
SELECT * FROM enumtest WHERE col = 'orange';
SELECT * FROM enumtest WHERE col > 'orange';
在coordinator上查询pg_enum:
postgres=# select * from pg_enum ;
enumtypid | enumsortorder | enumlabel
-----------+---------------+-----------
16388 | 1 | red
16388 | 2 | orange
16388 | 3 | yellow
16388 | 4 | green
16388 | 5 | blue
16388 | 6 | purple
(6 rows)
在datanode上查询pg_enum:
postgres=# select * from pg_enum ;
enumtypid | enumsortorder | enumlabel
-----------+---------------+-----------
16385 | 1 | red
16385 | 2 | orange
16385 | 3 | yellow
16385 | 4 | green
16385 | 5 | blue
16385 | 6 | purple
(6 rows)
参考:
QQ交流群:496464280
源码地址:http://github.com/ADBSQL
欢迎广大postgresql爱好者使用和交流。