当前位置:网站首页>KunlunDB对MySQL私有DML语法的支持
KunlunDB对MySQL私有DML语法的支持
2022-04-22 22:16:00 【KunlunDB 昆仑数据库】
前言
为了让MySQL的应用更为便捷地迁移到KunlunDB,我们做了很多兼容MySQL的工作。
本篇章主要介绍KunlunDB现在已经支持的MySQL常用的私有DML语法,以及这些语法与原生MySQL的差异。
一、兼容MySQL的insert ignore语法
功能: 忽略违背唯一约束的新元组。
示例:
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 1
postgres -> insert ignore into t1(a,b) values (4,4);
INSERT 0 0
和原生MySQL的差异:
- 只忽略唯一性约束,如果违背其他约束(例如分区约束、非null约束),则报错。
例如:
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)
二、兼容MySQL的INSERT…ONDUPLICATE KEY UPDATE…语法
功能: 插入数据;如果违背了某个唯一约束,则转变为更新操作,对其中一个冲突的元组进行更新。
示例:
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 2
postgres -> select * from t1;
a | b
---+---
3 | 2
4 | 4
和原生MySQL的差异:
- 暂不支持在ON DUPLICATE KEY UPDATE子句中使用VALUES()函数来引用新值,可以使用excluded虚拟表来代替。
例如:
postgres -> INSERT INTO t1 VALUES(3,0) ON DUPLICATE KEY UPDATE b = excluded.b;
INSERT 0 2
postgres -> 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"
- 往临时表批量写入多个新元组时,如果新元组之间存在唯一性冲突,则会报错(根本原因是临时表存在于计算节点,使用的不是innodb引擎)。
例如:
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 ->
- 临时表返回的影响行数的差异。即使更新前后的值相同,临时表返回的影响行数仍然大于0。
例如:
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 1
postgres -> INSERT INTO t1 VALUES(5,5) ON DUPLICATE KEY UPDATE b=excluded.b;
INSERT 0 1
三、兼容mysql的replace into语法
功能: 插入元组;如果存在冲突的旧元组,则删除所有与之冲突的旧元组。
示例:
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
postgres -> replace into t1 values(3,4);
INSERT 0 3
postgres -> select * from t1;
a | b
---+---
3 | 4
(1row)
和原生MySQL的差异:
- 往临时表批量写入多个新元组时,如果新元组之间存在唯一性冲突,则会报错(根本原因是临时表存在于计算节点,使用的不是innodb引擎)。
例如:
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 3
postgres -> 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.
四、兼容MySQL的update/delete…order by…limit… 语法
功能: 指定更新/删除的元组的顺序和数量。
示例:
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 4
postgres -> 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的差异:
- 暂不支持指定分区表的更新/删除的顺序(注意:临时表的分区表已经支持)。 当然,实际使用中需要严格规定更新/删除顺序的场景是极少的,这一限制并不会对KunlunDB的用户造成困扰。
例如:
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 ->
END
昆仑数据库是一个HTAP NewSQL分布式数据库管理系统,可以满足用户对海量关系数据的存储管理和利用的全方位需求。
应用开发者和DBA的使用昆仑数据库的体验与单机MySQL和单机PostgreSQL几乎完全相同,因为首先昆仑数据库支持PostgreSQL和MySQL双协议,支持标准SQL:2011的
DML 语法和功能以及PostgreSQL和MySQL对标准
SQL的扩展。同时,昆仑数据库集群支持水平弹性扩容,数据自动拆分,分布式事务处理和分布式查询处理,健壮的容错容灾能力,完善直观的监测分析告警能力,集群数据备份和恢复等
常用的DBA 数据管理和操作。所有这些功能无需任何应用系统侧的编码工作,也无需DBA人工介入,不停服不影响业务正常运行。
昆仑数据库具备全面的OLAP
数据分析能力,通过了TPC-H和TPC-DS标准测试集,可以实时分析最新的业务数据,帮助用户发掘出数据的价值。昆仑数据库支持公有云和私有云环境的部署,可以与docker,k8s等云基础设施无缝协作,可以轻松搭建云数据库服务。
请访问 http://www.zettadb.com/ 获取更多信息并且下载昆仑数据库软件、文档和资料。 KunlunDB项目已开源
【GitHub:】 https://github.com/zettadb 【Gitee:】
https://gitee.com/zettadb
版权声明
本文为[KunlunDB 昆仑数据库]所创,转载请带上原文链接,感谢
https://blog.csdn.net/KunLunDB_Linda/article/details/124351691
边栏推荐
- MySql--表的操作
- Rasa课程、Rasa培训、Rasa面试、Rasa实战系列之Rasa全新全局词槽映射的 3 大方法
- 2.60-假设我们将一个w位的字中的字节从0(最低位)到w/8- 1(最高位)编号。写出下面C函数的代码,它会返回一个无符号值,其中参数x的字节i被替换成字节b。
- Pangolin安装报错:make: *** 没有规则可制作目标“pypangolin_pip_install”。 停止。
- cluster_acc计算
- 数组取反-数组和字符串取反都行
- CAS统一身份认证(二):Overlay配置管理
- How to judge how many levels of insurance the enterprise should do? What is the significance of waiting insurance?
- Analysis of real questions and answers of software designers in the morning in the second half of 2021
- js力扣每日一题(2022/4/22)---396.旋转函数
猜你喜欢

Centos7安装mysql

396. 旋转函数 / 剑指 Offer II 013. 二维子矩阵的和

Advanced multithreading (6) -- locking mechanism
![[intranet penetration] - vulnstack (I)](/img/d4/b7267b8306b353ea6a8ac22d64f9f6.png)
[intranet penetration] - vulnstack (I)

41.0:GemBox. Spreadsheet|. Document|. Pdf|. Presentation
![[4.1] trigger trigger and evictor cleaner of flick window operator](/img/68/9a32ba6cc484237cd2c7015e5179be.png)
[4.1] trigger trigger and evictor cleaner of flick window operator

动态规划:分组背包问题

USPS数据集_kmeans使用总结

ACL2022 | 利用中文语言层级异质图强化预训练语言模型

条件编译分析及使用
随机推荐
数组去重-基本数据类型
讲座录播|图数据库中的子图匹配算法-邹磊
牛客BM41. 输出二叉树的右视图
repeat_string删除部分字符
二分法应用:875. 爱吃香蕉的珂珂
OJ每日一练——下落又弹起的小球
MySql--数据库基础
初学单片机点亮第一个外设--LED灯
行人重识别综述之Person Re-identification:Past, Present and Future
R语言数据分析从入门到高级:(九)数据清洗技巧之数据表连接大全
Analysis of real questions and answers of software designers in the morning in the second half of 2021
The PMP certificate has expired. Is it necessary to renew it
删除 vector 内所有指定的元素
OJ每日一练——猴子吃桃问题
LeetCode 199. 二叉树的右视图
GBase 8s V8.8 SQL 指南:教程-6.1.2(3)
学习笔记2-0417
Come to a Vue boss and see if there is an iframe cache scheme?
给复杂的数组结构数据换key
Steps to build appinventor2 on the window