基于PostgreSQL集群数据库系统概览
2021-10-30 21:16:36 阿炯

本文总结了基于PostgreSQL的集群数据库:Postgres-XCPostgres-XL,并在后部介绍了基于它们的两款国产数据库集群:AntDBTBase,并附带对两者的对比。

单体数据库随着系统交易量的不断上升,数据库读写性能出现了严重下降。可以借助分库分表中间件,比如mycat之类工具来实现分库分表,缓解单库的读写性能。但是分库分表中间件对事务支持相当有限,如果要保证数据一致性,就需要借助于分布式事务中间件。分布式数据库逐渐成为解决数据一致性的选择,目前分布式数据库产品已经比较成熟,已经可以支持ACID事务。

在传统关系型数据库上增加了切片集群,增加了协调节点,增加了全局时钟,这样就演变成了分布式数据库。

PGXC架构:这个名字是PostgreSQL-XC的简称,它是一种提供写可靠性,多主节点数据同步,数据传输的开源集群方案。之所以被叫做PGXC,并不是专指PostgreSQL-XC这种分布式数据库。

NewSQL架构:NewSQL是由NoSQL键值数据库发展而来,它是一类新的数据库架构方案,不仅具有NoSQL对海量数据的存储管理能力,还保持了传统数据库支持ACID和SQL等特性。主要有以下特性:放弃了PGXC架构中单体数据库的事务支持在BigTable基础上构建了事务支持引入分片机制,主要采用Range动态分片技术,跟HASH分片相比,数据可以不用固定的在某一个分片上可靠性方面,放弃传统数据库的主从复制,采用Paxos、Raft等共识算法来保证HA存储引擎方面,使用LSM-Tree替换B+树模型,写入性能更高支持事务管理。

PGXC数据库

PGXC数据库由传统关系型数据库基于分库分表的技术演化而来,优点是性能比较稳定,缺点是写入能力有限,这是由架构风格决定的。来介绍几款主流的PGXC数据库,代表如下:

1.AntDB
由亚信科技开发,基于开源PostgreSQL内核研发的,主要特点是对Oracle兼容性高,分布式事务支持2PC协议和MVCC,集群支持动态扩展。

2.TBase
TBase是腾讯数据平台团队在基于PostgreSQL研发的,支持HTAP(Hybrid Transaction and Analytical Process),主要由协调节点、数据节点和全局事务管理器(GTM)组成。特点如下:分布式事务支持RC和RR两个隔离级别支持高性能分区表,数据检索效率高SQL语法兼容SQL2003标准、也支持PostgreSQL语法和Oracle主要语法

3.GuassDB 300
GuassDB 300由华为研发,也是基于开源PostgreSQL研发的,支持HTAP,支持SQL92、SQL99和SQL2003语法,并且支持提供存储过程、触发器、分页等。目前在招商银行、工商银行和民生银行有使用。

NewSQL数据库

NewSQL数据库有很大的架构上的优势,但是首先难度也很大,我们来看一下目前主流的数据库产品。

1.Spanner
谷歌Spanner可以说是NewSQL数据库的鼻祖,后来的好多数据库都是借鉴了Spanner的思想。它有下面几个特性:使用GPS加原子钟的方式来实现全局时钟,这就就是引入了true time,支持全球化部署支持线性一致性。

2.TiDB
TiDB也是非常有名的一块NewSQL数据库,由PingCAP研发,支持HTAP,支持线性一致性,一个亮点是兼容mysql协议和生态。

3.Ocean Base
蚂蚁集团研发,按照官方说法,2020年5月,OceanBase以7.07亿tpmC的在线事务处理性能,打破了去年自己创造的TPC-C 世界纪录。截止至目前,OceanBase 是第一个也是唯一一个上榜的中国数据库。虽然官方说Ocean Base高度兼容各种主流关系型数据库,但是业界普遍认为对Oracle兼容不太好。采用Paxos分布式选举算法来实现高可用。

4.SequoiaDB
巨杉金融级分布式数据库,它具有如下特性:完整支持分布式事务、强一致、多副本高可用,满足分布式核心交易业务需求支持 MySQL、PostgreSQL、SparkSQL 和 MariaDB 四种关系型数据库实例,100%兼容MySQL语法支持HTAP混合事务/分析处理,目前在广发、民生等金融机构有一定使用。

5.CockroachDBYugabyteDB
这2个数据库放在一起讲的原因是它们不支持线性一致性,只支持最终一致性,因为它们使用的是混合逻辑时钟(Hybrid Logical Clocks),它们的设计思想都是来自Spanner。

CockroachDB采用了Range分区,同时使用raft算法的改进算法multi raft,每个Range对应的是一个Raft Group,让多分片并行处理提升性能。

YugabyteDB除了NewSQL的特性外,还支持文档数据库接口,查询层支持同时SQL和CQL两种API,SQL API是基于PostgreSQL改的,所以对PostgreSQL的支持非常好;还有业界有名MPP类型数据库Greenplum


接下来介绍一篇一位国内的DBA大佬在2019年11月份所写的对比文章:去O路上的历程--开源分布式数据库产品对比(TBase VS AntDB)

公司的领导让我这个 DBA 继续调研可以用来去 O 的相关分布式数据库产品,此前已经调研过亚信科技的 AntDB。鉴于腾讯的 TBase 在 2019 年 11 月 7 日的 Techo 大会现场官宣开源,正好借此机会研究下,并和 AntDB 做个对比测试。

鉴于之前已经对 AntDB 有所了解,知道它是基于提供写可靠性,多主节点数据同步,数据传输的开源集群方案 Postgres-XC 实现的。看过 TBase 开源地址的官方文档介绍,发现它也是基于开源 Postgres-XC 方案实现的。既然两种产品的实现原理都是一样的,那么谁在数据库易用性、性能优化和 Oracle 的兼容性(去 O 成本考量)方面做得更好,谁就更容易被市场接受。下面就从下面几个方面对两款数据库产品做出比对测试,并给出分析报告:
1.安装部署
2.Oracle 兼容度
3.数据库的性能
4.数据库高可用
5.数据库执行计划
6.数据库扩展工具集

先决条件

此次对比采用三台虚拟主机,采用GTM(1)、Coordinator(2)、Datanode(2)节点的集群架构;
TBase 版本:psql (PostgreSQL 10.0 TBase V2)
AntDB 版本:psql (5.0devel based on PG 11.5)

相较于pg10、11在并行计算、分区功能增强、存储过程支持等方面得到了增强。

安装部署
源码包按照官方文档编译并安装
TBase 集群部署,和PGXC 采用一样的方式,使用pgxc_ctl 命令,生成pgxc_ctl.conf配置文件,通过修改该配置文件完成集群的初始化、启停等管理操作;
AntDB 集群部署提供了adbmgr 管理工具,通过该工具的指令实现主机节点添加修改、分发、集群节点的添加修改、初始化、集群节点参数配置、集群启停等操作,易用性要优于TBase;

Oracle 兼容度
当前我们很多的应用跑在了Oracle 数据库上,有些应用已经比较老旧,没有人维护,针对这些应用的迁移,我们不希望有任何应用方面的更改,因此在数据库和Oracle的兼容性方面,我们希望能达到一个较高的兼容度。接下来对TBase 和AntDB 对Oracle 的兼容性我会重点进行对比测试。

测试的要点:
1.数据类型
2.数据库函数
3.数据类型隐式转换
4.SQL 语法兼容度

1.数据类型
 

TBase

AntDB

浮点

支持

支持

整形

支持

支持

小数

支持

支持

字符串

支持

支持

二进制

不支持CLOBBLOBLONG

支持CLOBBLOBLONG

日期/时间

部分支持,TBase date类型不带时间和Oracle date不完全兼容

支持

布尔类型

支持

支持

rowid

不支持

支持

xml

支持

支持

json

支持

支持



2.数据库函数
 

TBase

AntDB

substr

支持

支持

sign

支持

支持

sinh

支持

支持

tanh

支持

支持

cosh

支持

支持

trim

支持

支持

coalesce

支持

支持

extract

支持

支持

greatest

支持

支持

last_day

支持

支持

least

支持

支持

length

支持

支持

lnnvl

支持

支持

max

支持

支持

min

支持

支持

mod

支持

支持

month_between

支持

支持

to_yminterval

支持

支持

nullif

支持

支持

numtodsinterval

支持

支持

numtoyminterval

支持

支持

round_date

支持

支持

to_timestamp

支持

支持

rpad

支持

支持

to_single_byte

支持

支持

sessiontimezone

支持

支持

to_date

Tbase   to_date函数对月份解析有错误;
  tbase=# SELECT TO_date('January 15, 2010, 11:00 P.M.','Mon dd, YYYY, HH:MI   P.M.') FROM DUAL;
  ERROR:  invalid value "ar"   for "dd"
  DETAIL:  Value must be an integer.

支持

to_date+to_dsinterval

TBase计算错误,正确值应该是2016-01-04 14:20:50
  postgres=# select to_date('1-3-2016 10:30:00','MM-DD-yyyy hh:mi:ss') +   to_dsinterval('1 3:50:50')  as ndate   from dual;
          ndate       
  ---------------------
   2016-01-04 03:50:50
  (1 row)

支持

soundex

TBase不支持soundex函数;
  tbase=# select soundex('moon') from dual;
  ERROR:  function soundex(unknown) does   not exist
  LINE 1: select soundex('moon') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

sys_extract_utc

TBase不支持sys_extract_utc函数;
  tbase=# SELECT SYS_EXTRACT_UTC(TIMESTAMP '2012-04-19 17:30:00 +08:00 ')   "CURRENT UTC TIME" FROM     DUAL;
  ERROR:  function   sys_extract_utc(timestamp without time zone) does not exist
  LINE 1: SELECT SYS_EXTRACT_UTC(TIMESTAMP '2012-04-19 17:30:00 +08:00...
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

trunc

TBasetrunc函数传参参数类型支持不够,对数值型的支持(正负)不够,数据类型隐式转换不够;
  tbase=# select trunc(3.25,'') from dual;
  ERROR:  invalid input syntax for   integer: ""
  LINE 1: select trunc(3.25,'') from dual;
                            ^
  tbase=# select trunc(100.984,-2.8) from dual;
  ERROR:  function trunc(numeric,   numeric) does not exist
  LINE 1: select trunc(100.984,-2.8) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  tbase=# select trunc(100.984,2.8) from dual;
  ERROR:  function trunc(numeric,   numeric) does not exist
  LINE 1: select trunc(100.984,2.8) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

add_months

TBase add_months对传入的参数值转换有错误;
  tbase=# select add_months(to_date('2000-2-29','YYYY-MM-DD'),12.1) from dual;
  ERROR:  function add_months(date,   numeric) does not exist
  LINE 1: select add_months(to_date('2000-2-29','YYYY-MM-DD'),12.1) fr...
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  tbase=# select add_months(to_date('2000-2-29','YYYY-MM-DD'),-12.55) from   dual;
  ERROR:  function add_months(date,   numeric) does not exist
  LINE 1: select add_months(to_date('2000-2-29','YYYY-MM-DD'),-12.55) ...
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

bitand

Tbase不支持bitand函数;
  tbase=# select bitand(1,3) from dual;
  ERROR:  function bitand(integer,   integer) does not exist
  LINE 1: select bitand(1,3) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

instr

Tbaseinstr函数传参参数类型支持不够,对数值型的支持不够
 
,数据类型隐式转换不够;
  ERROR:  function instr(integer,   integer) does not exist
  LINE 1: select instr(1234,23) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  ERROR:  function instr(numeric,   unknown) does not exist
  LINE 1: select instr(to_number(123.56),'.') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  ERROR:  function instr(double   precision, integer) does not exist
  LINE 1: select instr(exp(2),0)  from   dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  ERROR:  function instr(double   precision, double precision) does not exist
  LINE 1: select instr(exp(2),exp(2))    from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

lpad

Tbaselpad函数传参参数类型支持不够,对数值型的支持不够
 
,数据类型隐式转换不够;
  tbase=# select lpad(3.545, 5) from dual;
  ERROR:  function lpad(numeric, integer)   does not exist
  LINE 1: select lpad(3.545, 5) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  tbase=# select lpad(4, 5) from dual;
  ERROR:  function lpad(integer, integer)   does not exist
  LINE 1: select lpad(4, 5) from dual;
                 ^
  HINT:  No function matches the given name   and argument types. You might need to add explicit type casts.

支持

nanvl

Tbasenanlvl函数传参参数类型支持不够,对空值的支持不够;
  tbase=# select nanvl('','') from dual;
  ERROR:  invalid input syntax for type   double precision: ""
  LINE 1: select nanvl('','') from dual;
                       ^
  tbase=# select nanvl('',null) from dual;
  ERROR:  invalid input syntax for type   double precision: ""
  LINE 1: select nanvl('',null) from dual;

支持

new_time

Tbase不支持new_time函数;
  tbase=# select sysdate bj_time,new_time(sysdate,'PDT','GMT') los_angles from   dual;
  ERROR:  function new_time(timestamp   without time zone, unknown, unknown) does not exist
  LINE 1: select sysdate bj_time,new_time(sysdate,'PDT','GMT') los_ang...
                                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

next_day

Tbase对函数next_day传参支持数据类型不够,不支持numeric隐式转换为int
  tbase=# select next_day(sysdate,2.4) from dual;
  ERROR:  function next_day(timestamp   without time zone, numeric) does not exist
  LINE 1: select next_day(sysdate,2.4) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

trim

Tbase对函数trim传参数据类型支持不够,不支持数值型隐式转换为字符型;
  tbase=# select trim(both 1 from 121) from dual;
  ERROR:  function   pg_catalog.btrim(integer, integer) does not exist
  LINE 1: select trim(both 1 from 121) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

translate

Tbase对函数translate传参数据类型支持不够,不支持数值型隐式转换为字符型;
  tbase=# SELECT TRANSLATE(121, 12, 3) FROM DUAL;
  ERROR:  function translate(integer,   integer, integer) does not exist
  LINE 1: SELECT TRANSLATE(121, 12, 3) FROM DUAL;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  tbase=# SELECT TRANSLATE('999,999.99', '9', 0) FROM DUAL;
  ERROR:  function translate(unknown,   unknown, integer) does not exist
  LINE 1: SELECT TRANSLATE('999,999.99', '9', 0) FROM DUAL;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

to_timestamp_tz

Tbase to_timestamp_tz函数对月份解析有错误;
  tbase=# SELECT to_timestamp_tz('January 15, 2010, 11:00 P.M.','Mon dd, YYYY,   HH:MI P.M.') FROM DUAL;
  ERROR:  invalid value "ar"   for "dd"
  DETAIL:  Value must be an integer.

支持

NLS_CHARSET_ID

Tbase不支持函数NLS_CHARSET_ID
  tbase=# SELECT NLS_CHARSET_ID('utf8') FROM DUAL;
  ERROR:  function   nls_charset_id(unknown) does not exist
  LINE 1: SELECT NLS_CHARSET_ID('utf8') FROM DUAL;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

NLS_CHARSET_NAME

Tbase不支持函数NLS_CHARSET_NAME
  tbase=# SELECT NLS_CHARSET_NAME(2) FROM DUAL;
  ERROR:  function   nls_charset_name(integer) does not exist
  LINE 1: SELECT NLS_CHARSET_NAME(2) FROM DUAL;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

nls_initcap

Tbase不支持函数nls_initcap
  tbase=# select nls_initcap('ab cde') from dual;
  ERROR:  function nls_initcap(unknown)   does not exist
  LINE 1: select nls_initcap('ab cde') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

nls_lower

Tbase不支持函数nls_lower
  tbase=# select nls_lower('AB CDe') from dual;
  ERROR:  function nls_lower(unknown)   does not exist
  LINE 1: select nls_lower('AB CDe') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

nls_upper

Tbase不支持函数nls_upper
  tbase=# select nls_upper('ab cDe') from dual;
  ERROR:  function nls_upper(unknown)   does not exist
  LINE 1: select nls_upper('ab cDe') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

nvl

Tbase对函数nvl参数传递数据类型支持不够,不支持数据类型隐式转换;
  tbase=# select nvl(1.4,4) from dual;
  ERROR:  function nvl(numeric, integer)   does not exist
  LINE 1: select nvl(1.4,4) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.
  tbase=# select nvl(exp(2),4.8) from dual;
  ERROR:  function nvl(double precision,   numeric) does not exist
  LINE 1: select nvl(exp(2),4.8) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

nvl2

Tbase对函数nvl2参数传递数据类型支持不够,不支持数据类型的隐式转换;
  tbase=# select nvl2(3,'4.9',5) from dual;
  ERROR:  invalid input syntax for   integer: "4.9"
  LINE 1: select nvl2(3,'4.9',5) from dual;
  tbase=# select nvl2(4,4.8,5) from dual;
  ERROR:  function nvl2(integer, numeric,   integer) does not exist
  LINE 1: select nvl2(4,4.8,5) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

to_timestamp

Tbase to_timestamp函数对月份解析有错误
  tbase=# SELECT TO_timestamp('January 15, 2010, 11:00 P.M.','Mon dd, YYYY,   HH:MI P.M.') FROM DUAL;
  ERROR:  invalid value "ar"   for "dd"
  DETAIL:  Value must be an integer.

支持

regexp_count

Tbase不支持函数regexp_count
  tbase=# select regexp_count('abcdfbc','Bc',1,'i') from dual;
  ERROR:  function regexp_count(unknown,   unknown, integer, unknown) does not exist
  LINE 1: select regexp_count('abcdfbc','Bc',1,'i') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

regexp_instr

Tbase不支持函数regexp_instr
  tbase=# SELECT regexp_instr('abc1def', '[[:digit:]]',1,1,1) output  from dual;
  ERROR:  function regexp_instr(unknown,   unknown, integer, integer, integer) does not exist
  LINE 1: SELECT regexp_instr('abc1def', '[[:digit:]]',1,1,1) output  ...
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

regexp_like

Tbase不支持函数regexp_like
  tbase=# select * from t4test where regexp_like(name,'345');
  ERROR:  function regexp_like(character   varying, unknown) does not exist
  LINE 1: select * from t4test where regexp_like(name,'345');
                                     ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

regexp_replace

Tbase不支持函数regexp_replace;
  tbase=# SELECT regexp_replace('abc1def2', '[[:digit:]]','@',1,2) output  from dual;
  ERROR:  function   regexp_replace(unknown, unknown, unknown, integer, integer) does not exist
  LINE 1: SELECT regexp_replace('abc1def2', '[[:digit:]]','@',1,2) out...
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

remainder

Tbase不支持函数remainder;
  tbase=# select remainder(7,5) from dual;
  ERROR:  function remainder(integer,   integer) does not exist
  LINE 1: select remainder(7,5) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

replace

Tbase函数replace传参数据类型支持不够;
  tbase=# select replace('abc', 'a') from dual;
  ERROR:  function replace(unknown,   unknown) does not exist
  LINE 1: select replace('abc', 'a') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

round

Tbase函数round传参数据类型支持不够,不支持数据类型隐式转换;
  tbase=# select round(100.984,2.8) from dual;
  ERROR:  function round(numeric,   numeric) does not exist
  LINE 1: select round(100.984,2.8) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

rpad

Tbase函数rpad传参数据类型支持不够,不支持数据类型隐式转换;
  tbase=# select rpad(3.545, 5) from dual;
  ERROR:  function rpad(numeric, integer)   does not exist
  LINE 1: select rpad(3.545, 5) from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

to_number

Tbase函数to_number参数传递的格式化选项支持不够;
  tbase=# select to_number(89.987,'99.9999') from dual;
  ERROR:  function to_number(numeric,   unknown) does not exist
  LINE 1: select to_number(89.987,'99.9999') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持

to_char

Tbase函数to_char参数传递的格式化选项支持不够;
  tbase=# select to_char(to_char(24.50),'099.999') from dual;
  ERROR:  function to_char(text, unknown)   does not exist
  LINE 1: select to_char(to_char(24.50),'099.999') from dual;
                 ^
  HINT:  No function matches the given   name and argument types. You might need to add explicit type casts.

支持



通过对比数据库函数,TBase 在函数兼容性方面和AntDB 差距较大,主要体现在部分函数无法支持,函数支持的数据类型不丰富,不支持数据类型的隐式转换。而AntDB 完全兼容Oracle 所列的常用的函数。此外,在函数兼容性方面TBase 是通过UDF 、扩展等方式实现,兼容有限,而AntDB 是数据库内核级别实现的支持。

3.数据类型隐式转换
 

TBase

AntDB

隐式数据类型转换

 

在某些符合场景(函数传参)TBase对数据类型隐式转换支持不够;包含greatestleastsubstrlengthtrimnext_daytranslate等函数

示例:
  tbase=# SELECT SUBSTR(exp(2),1,6) sub FROM DUAL;
  ERROR:  function substr(double   precision, integer, integer) does not exist
 
  tbase=# SELECT SUBSTR('abcde',tanh(1),6) sub FROM DUAL;
  ERROR:  function substr(unknown, double   precision, integer) does not exist
 
tbase=# select '1'+'1' from dual;

ERROR:    operator is not unique: unknown + unknown

示例:

antdb=#   select '1'+'1' from dual;

 ?COLUMN?

----------

        2

(1   row)

 

antdb=#   SELECT SUBSTR(exp(2),1,6) sub FROM DUAL;
    SUB    
  --------
   7.3890
  (1 row)
 
  antdb=# SELECT SUBSTR('abcde',tanh(1),6) sub FROM DUAL;
    SUB   
  -------
   abcde
  (1 row)
  AntDB
支持Oracle数据类型隐式转换



AntDB 在内核级别实现了兼容Oracle 数据类型的隐式转换,而TBase 仅仅支持有限的数据类型隐式转换。

4.SQL 语法兼容度
 

TBase

AntDB

connect   by

TBase不支持start   with connect by的层次查询语法;

AntDB支持connect   by语法;

 

rownumrowid

TBase不支持rownumrowid

AntDB支持rownumrowid

listaggwm_concat

TBase不支持listaggwm_concat

AntDB支持listaggwm_concat行列转换;

minus运算

TBase不支持minus运算符;

AntDB支持minus运算;

乘法运算

TBase进行乘法运算的时候数据类型隐式转换支持不够;

AntDB乘法运算兼容Oracle数据隐式转换;

加法运算

TBase进行加法运算的时候数据类型隐式转换支持不够;

AntDB加法运算兼容Oracle数据隐式转换;

减法运算

TBase进行减法运算的时候数据类型隐式转换支持不够;

AntDB减法运算兼容Oracle数据隐式转换;

除法运算

TBase进行除法运算的时候数据类型隐式转换支持不够;

AntDB除法运算兼容Oracle数据隐式转换;

||字符连接运算

TBase||连接运算时候数据类型的数值转换为字符型隐式转换支持不够;

AntDB||连接运算兼容Oracle数据隐式转换;

表别名

Tbase不支持表数据更新时的表别名;

AntDB支持表数据更新时的表别名;

Oracle投影列名大小写保持一致

Oracle字段名是大写,TBase不兼容;

AntDB支持设置参数upper_out_oracle_target控制是否兼容Oracle字段大写;

oracle中表左右连接(+)写法

TBase不兼容Oracle中表连接(+)这种写法;

AntDB支持Oracle表连接(+)的写法;

alter修改表结构

Tbase不支持modify命令,不支持add后面列名加括号的写法;

AntDB支持modify语法,支持add命令后面加括号的写法;

PLSQL/PIPE   ROW

 

Tbase不支持Oracle   PLSQL语法,不支持函数创建,不支持pipe row的使用

 

AntDB支持Oracle函数、存储过程创建,支持PIPE ROW的使用

PLSQL/table()函数

 

Tbase不支持Oracle   table函数;

AntDB支持Oracle   table函数;

 

分析函数keep first/last

 

TBase不支持keep   first/last分析函数;

AntDB支持keep   first/last分析函数;

 

序列取值

 

Tbase不支持使用.nextval的方式获取序列的下一返回值;

Antdb支持使用序列.nextval的方式返回序列的值;

多表关联更新

 

Tbase不支持Oracle多表关联update语法;

AntDB支持Oracle   多表关联Update语法;

 

死锁检测

 

TBase在跨CN节点无法检测死锁,事务一直锁等待;

AntDB在跨CN节点可以发现检测死锁;

分区表

TBase不支持Oracle的分区表建表语法;

AntDB兼容Oracle语法支持HashRangeList分区;

存储过程、函数

TBase不支持Oracle存储过程、函数的创建;

 

AntDB兼容Oracle存储过程、函数的语法,支持存储过程、函数的创建;

Savepoint

TBase支持事务savepoint,支持子事务;

AntDB不支持子事务,不支持savepoint



从上表可以看出在SQL 语法兼容方面,AntDB 对Oracle 的支持度远比TBase 要高,但是在子事务的支持性上不如TBase。

性能测试

为验证数据库的性能,我采用了sysbench 和benchmarksql 两种测试工具,分别对AntDB 和TBase 在同等条件(硬件环境、数据库参数配置、测试数据量)下进行了性能比对;
 

TBase

AntDB

同等条件下sysbench测试

 

OLTP   test statistics:
      queries performed:
          read:                            140406
          write:                           40088
          other:                           20030
          total:                           200524
      transactions:                        10001  (
317.77 per sec.)
      read/write requests:                 180494 (
5735.07 per sec.)
      other operations:                    20030  (636.44 per sec.)
      ignored errors:                      28     (0.89 per sec.)
      reconnects:                          0      (0.00 per sec.)

 

OLTP   test statistics:
      queries performed:
          read:                            141120
          write:                           40242
          other:                           20082
          total:                           201444
      transactions:                        10002  (
674.30 per sec.)
      read/write requests:                 181362 (
12226.73 per sec.)
      other operations:                    20082  (1353.85 per sec.)
      ignored errors:                      78     (5.26 per sec.)
      reconnects:                          0      (0.00 per sec.)
 
AntDB性能大致是TBase2倍。

同等条件下tpcc测试

 

17:23:53,593   [Thread-15] INFO   jTPCC : Term-00,   mTOTAL: 7104    Memory Usage: 113MB /   1928MB              
  17:23:53,593 [Thread-15] INFO   jTPCC :   Term-00,
  17:23:53,593 [Thread-15] INFO   jTPCC :   Term-00,
Measured   tpmC (NewOrders) = 71.76
  17:23:53,594 [Thread-15] INFO   jTPCC :   Term-00, Measured tpmTOTAL = 156.9
  17:23:53,594 [Thread-15] INFO   jTPCC :   Term-00, Session Start     = 2019-11-12   17:16:56
  17:23:53,594 [Thread-15] INFO   jTPCC :   Term-00, Session End       = 2019-11-12   17:23:53
  17:23:53,594 [Thread-15] INFO   jTPCC :   Term-00, Transaction Count = 1090
  17:23:53,594 [Thread-15] INFO   jTPCC :   Term-00, New OrderTransaction Count = 499
  17:23:53,595 [Thread-15] INFO   jTPCC :   Term-00, Transaction that execution successfully Count = 619(56.79%)
  17:23:53,595 [Thread-15] INFO   jTPCC :   Term-00, Transaction that execution fails as expected Count = 3(0.28%)
  17:23:53,595 [Thread-15] INFO   jTPCC :   Term-00, Transaction that execution error Count = 468(42.94%)

16:44:46,438   [Thread-10] INFO   jTPCC : Term-00, ent   tpmTOTAL: 6912    Memory Usage: 443MB /   1928MB         
  16:44:46,438 [Thread-10] INFO   jTPCC :   Term-00,
  16:44:46,438 [Thread-10] INFO   jTPCC :   Term-00, Measured tpmC (NewOrders) =
105.87
  16:44:46,438 [Thread-10] INFO   jTPCC :   Term-00, Measured tpmTOTAL = 219.23
  16:44:46,438 [Thread-10] INFO   jTPCC :   Term-00, Session Start     = 2019-11-12   16:39:41
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, Session End       = 2019-11-12   16:44:46
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, Transaction Count = 1113
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, New OrderTransaction Count = 538
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, Transaction that execution successfully Count = 783(70.35%)
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, Transaction that execution fails as expected Count = 2(0.18%)
  16:44:46,439 [Thread-10] INFO   jTPCC :   Term-00, Transaction that execution error Count = 328(29.47%)
 
AntDB大致是TBase1.5

 



可以看出AntDB 的性能大致是TBase 的1.5-2 倍。

数据库高可用
 

TBase

AntDB

集群高可用

暂未提供自动故障恢复功能,需要手工执行故障切换、备节点提升等操作;

AntDB提供集群自愈功能,发现主节点故障自动提升从节点,待故障节点恢复后可以通过rewind功能重新加入集群;



TBase 在集群数据库高可用方面提供了相关的手工处置方式,缺少自动化的实现,需要借助于第三方工具。AntDB 提供了集群自愈的功能,在发现主节点故障的情况下会自动切换从节点,并提供了主节点故障恢复后重新快速加入集群的功能(可以轻松通过AntDB 的adbmgr 管理工具实现)。

数据库执行计划
 

TBase

AntDB

执行计划改进

 

TBase执行复杂查询无法自动有效利用并行;
 
执行复杂的关联查询无法有效利用数据节点的计算能力;

 

AntDB优化:
  1.
利用数据节点资源并行查询
  2.
对于大量数据查询执行计划下沉数据节点执行减少节点间数据通信



如下是取自TPCH 模型的Q6 和Q8 测试SQL :

Q6 查询:


Q8 查询:


查看AntDB 的Q8 执行计划:


经过上面的测试,AntDB 在复杂查询执行计划方面增强了并行查询和采用Reduce 功能优化了Join 的效率,效果优于TBase。


数据库扩展工具集
 

TBase

AntDB

数据备份恢复

暂未提供全局数据备份恢复工具;

可以使用pg_dump等逻辑备份工具进行数据备份;

AntDB提供优化改进后的数据库备份管理工具barman,支持基于barrier的备份恢复;

数据库迁移/迁移评估

暂未提供数据库迁移工具和迁移评估工具;

AntDB提供优化改进后的ora2pg工具,可以实现从OracleMySQLAntDB数据库的迁移;
  AntDB
提供迁移评估报告工具;

SQL Replay

暂未提供数据库sql replay的工具;

AntDB提供a2o工具(基于逻辑复制的方式实现)支持AntDB数据库同步数据至其他数据库;

Web监控

暂未提供web监控工具;

AntDB提供了AdbMonitor Web监控工具,查看当前数据库集群的运行状态、慢查询、锁信息等内容;



相比于TBase ,AntDB 在数据库备份恢复、数据库迁移、SQL Replay 、Web 监控方面提供了各种工具,方便了数据库的运维管理。

小结
经过上面的测试可以看出,AntDB 从数据库的安装部署,Oracle 的兼容性,到数据库的性能,执行计划优化、运维工具集的完善,都要比开源的 TBase V2 版本要更符合我们的去 O 的需求。当然了,不论是 AntDB 还是 TBase 和 Oracle 比起来,还是有很多需要支持和完善的地方( AWR 报告、EM 、数据闪回功能等),毕竟 Oracle 已经称霸关系型数据库这么多年了。