首页 > 数据库 > 国内数据库 > KunlunBase对MySQL私有DML语法的支持
为了让MySQL的应用更为便捷地迁移到 KunlunBase,我们做了很多兼容MySQL的工作。
本篇章主要介绍 KunlunBase现在已经支持的MySQL常用的私有DML语法,以及这些语法与原生MySQL的差异。
功能: 忽略违背唯一约束的新元组。
示例:
postgres -> create table t1(a int primary key, b int not null unique); CREATE TABLE # 违背唯一约束,不进行插入 postgres -> insert ignore into t1(a,b) values (4,4); INSERT 0 1postgres -> insert ignore into t1(a,b) values (4,4); INSERT 0 0
和原生MySQL的差异:
例如:
postgres -> insert ignore into t1(a,b) values (4,NULL); ERROR: null value in column "b" violates not-null constraint DETAIL: Failing row contains (4, null)
功能:插入数据;如果违背了某个唯一约束,则转变为更新操作,对其中一个冲突的元组进行更新。
示例:
postgres -> create table t1 (a int primary key, b int not null unique); CREATE TABLE postgres -> insert into t1 values(3,3), (4,4); INSERT 0 2# 插入的数据和已有的两个元组都冲突,但只更新了其中一个元组(3,3) postgres -> insert into t1 values(3,4) on duplicate key update b=2; INSERT 0 2postgres -> select * from t1; a | b ---+--- 3 | 2 4 | 4
和原生MySQL的差异:
例如:
postgres -> INSERT INTO t1 VALUES(3,0) ON DUPLICATE KEY UPDATE b = excluded.b; INSERT 0 2postgres -> select * from t1; a | b ---+--- 3 | 0 4 | 4(2rows) postgres -> INSERT INTO t1 VALUES(3,0) ON DUPLICATE KEY UPDATE b=VALUES(b); ERROR: syntax error at or near "VALUES"
例如:
postgres -> create temp table t1(a int primary key, b int not null unique); CREATE TABLE postgres -> INSERT INTO t1 VALUES(5,5), (5,6) ON DUPLICATE KEY UPDATE b = excluded.b; ERROR: ON CONFLICT DO UPDATE command cannot affect row a secondtime HINT: Ensure that norows proposed for insertion within the same command have duplicate constrained values. postgres ->
例如:
postgres -> create temp table t1(a int primary key, b int not null unique); CREATE TABLE postgres -> INSERT INTO t1 VALUES(5,5) ON DUPLICATE KEY UPDATE b=excluded.b; INSERT 0 1postgres -> INSERT INTO t1 VALUES(5,5) ON DUPLICATE KEY UPDATE b=excluded.b; INSERT 0 1
功能:插入元组;如果存在冲突的旧元组,则删除所有与之冲突的旧元组。
示例:
postgres -> create table t1(a int primary key, b int not null unique); CREATE TABLE postgres -> insert into t1 values(3,3),(4,4); INSERT 0 2postgres -> replace into t1 values(3,4); INSERT 0 3postgres -> select * from t1; a | b ---+--- 3 | 4(1row)
和原生MySQL的差异:
例如:
postgres -> create table t1(a int primary key, b int not null unique); CREATE TABLE postgres -> replace into t1 values(1,1),(1,2); INSERT 0 3postgres -> create temp table t2(a int primary key,b int not null unique); CREATE TABLE postgres -> replace into t2 values(1,1),(1,2); ERROR: REPLACEINTO command cannot affect row a secondtime HINT: Ensure that norows proposed for insertion within the same command have duplicate constrained values.
功能:指定更新/删除的元组的顺序和数量。
示例:
postgres -> create table t1 (a int primary key, b int); CREATE TABLE postgres -> insert into t1 select generate_series(1,100),generate_series(1,100); INSERT 0 100# 对非分区表的有序更新 postgres -> update t1 set b=b+1 order by a desc limit 4 returning*; a | b -----+----- 100 | 101 99 | 100 98 | 99 97 | 98(4rows) UPDATE 4postgres -> drop table t1; DROP TABLE postgres -> CREATE TABLE t1 (A INT PRIMARY KEY,B INT) PARTITION BY RANGE(a); CREATE TABLE postgres -> CREATE TABLE t1p1 PARTITION OF t1 FOR VALUES FROM (0) TO (100); CREATE TABLE postgres -> CREATE TABLE t1p2 PARTITION OF t1 FOR VALUES FROM (100) TO (200); CREATE TABLE postgres -> insert into t1 select generate_series(0,199); INSERT 0 200# 指定分区表删除的总量 postgres -> delete from t1 limit 4 returning *; a | b ---+--- 0 | 1 | 2 | 3 | (4rows) DELETE 4
和原生MySQL的差异:
例如:
postgres -> CREATE TABLE t1 (A INT PRIMARY KEY, B INT) PARTITION BY RANGE(a); CREATE TABLE postgres -> CREATE TABLE t1p1 PARTITION OF t1 FOR VALUESFROM (0) TO (100); CREATE TABLE postgres -> CREATE TABLE t1p2 PARTITION OF t1 FORVALUESFROM (100) TO (200); CREATE TABLE # 不能指定分区表删除顺序 postgres -> delete from t1 order by a limit 4 returning *; ERROR: Kunlun-db: Cannot push down plan postgres ->
推荐阅读
KunlunBase架构介绍
KunlunBase技术优势介绍
KunlunBase技术特点介绍
PostgreSQL vs MySQL TPC-H 测试
Kunlun-Storage vs PostgreSQL OLTP 测试
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70011764/viewspace-2888309/ ,如需转载,请注明出处,否则将追究法律责任。