lightdb 支持以任何顺序指定建表选项

发布时间 2023-08-04 17:18:54作者: winter-loo

背景

lightdb 在为了兼容 oracle 和 mysql 语法,,在 postgresql 原有的建表选项上新增了一些选项并自定义了一些选项:

  1. compress/nocompress
  2. logging/nologging
  3. with primary key
  4. distributed by
  5. engine=innodb/myisam
  6. default charset=…
  7. collate=…
  8. comment=…
  9. with update current_timestamp
  10. storage (…)

这些选项在使用上有顺序要求,给用户带来了十分不好的体验。在 lightdb LightDB1.0.V202303.00.000 版本中,允许这些选项可以以任何顺序出现在原有 PG 建表选项的后面。为了向后兼容,还允许 tablespace 选项以任意顺序指定。

用例

搭建数据库环境

\! mkdir /tmp/foo
create tablespace tbs_foo location '/tmp/foo';
create table pfoo(pa int);

建表语句如下:

-- ok
create table foo2(a int) using heap storage(INITIAL 8M MAXSIZE 1G);
 
-- -- lightdb options can be specified in any order
create table foo3(a int) compress logging;
create table foo4(a int) compress with primary key;
create table foo5(a int) compress engine=innodb;
create table foo6(a int) compress default charset=utf8;
create table foo7(a int) compress collate=utf8;
create table foo8(a int) compress comment='';
create table foo9(a int) compress with update current_timestamp;
create table foo10(a int) compress storage(INITIAL 8M MAXSIZE 1G);
create table foo11(a int) comment='' collate=utf8 default charset=utf8 engine=innodb with primary key storage(INITIAL 8M MAXSIZE 1G) logging compress;
create table foo12(a int) using heap tablespace tbs_foo compress nologging;

这里不再列出其他组合情况,用户可自测。