MariaDB 10.3 序列
在MariaDB 10.3版本中sequence是特殊的表,和表使用相同的namespace,因此表和序列的名字不能相同。 MariaDB [wuhan]> select version();
+--------------------+
| version() |
+--------------------+
| 10.3.8-MariaDB-log |
+--------------------+
1 row in set (0.000 sec) MariaDB [wuhan]> create sequence s;
Query OK, 0 rows affected (0.477 sec)
MariaDB [wuhan]> show create sequence s;
+-------+--------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------------------------------------------+
| s | CREATE SEQUENCE `s` start with 1 minvalue 1 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB |
+-------+--------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.075 sec) MariaDB [wuhan]> show create table s\G
*************************** 1. row ***************************
Table: s
Create Table: CREATE TABLE `s` (
`next_not_cached_value` bigint(21) NOT NULL,
`minimum_value` bigint(21) NOT NULL,
`maximum_value` bigint(21) NOT NULL,
`start_value` bigint(21) NOT NULL COMMENT 'start value when sequences is created or value if RESTART is used',
`increment` bigint(21) NOT NULL COMMENT 'increment value',
`cache_size` bigint(21) unsigned NOT NULL,
`cycle_option` tinyint(1) unsigned NOT NULL COMMENT '0 if no cycles are allowed, 1 if the sequence should begin a new cycle when maximum_value is passed',
`cycle_count` bigint(21) NOT NULL COMMENT 'How many cycles have been done'
) ENGINE=InnoDB SEQUENCE=1
1 row in set (0.000 sec) MariaDB [wuhan]> select * from s\G
*************************** 1. row ***************************
next_not_cached_value: 1
minimum_value: 1
maximum_value: 9223372036854775806
start_value: 1
increment: 1
cache_size: 1000
cycle_option: 0
cycle_count: 0
1 row in set (0.001 sec)
cycle_count每次递增。 可以看到序列是一种特殊的表,对这种表不能update和delete,不能将表名和序列名命名为一样的,否则报错。
MariaDB [wuhan]> update s set increment=2 ;
ERROR 1031 (HY000): Storage engine SEQUENCE of the table `wuhan`.`s` doesn't have this option
MariaDB [wuhan]> delete from s where increment=1;
ERROR 1031 (HY000): Storage engine SEQUENCE of the table `wuhan`.`s` doesn't have this option
MariaDB [wuhan]> create table s(a int);
ERROR 1050 (42S01): Table 's' already exists
但是对表的重命名、删除操作生效:
MariaDB [wuhan]> alter table s rename to ss;
Query OK, 0 rows affected (0.291 sec) MariaDB [wuhan]> rename table ss to s;
Query OK, 0 rows affected (0.022 sec) MariaDB [wuhan]> drop table s;
Query OK, 0 rows affected (0.076 sec) 对序列进行FLUSH TABLE操作将会关闭序列,生成的下一个序列值将会根据序列对象生成,实际上将会丢弃缓存cached 值。
MariaDB [wuhan]> create sequence s;
Query OK, 0 rows affected (0.024 sec) MariaDB [wuhan]> select nextval(s),lastval(s);
+------------+------------+
| nextval(s) | lastval(s) |
+------------+------------+
| 1 | 1 |
+------------+------------+
1 row in set (0.059 sec) MariaDB [wuhan]> select nextval(s),lastval(s);
+------------+------------+
| nextval(s) | lastval(s) |
+------------+------------+
| 2 | 2 |
+------------+------------+
1 row in set (0.001 sec) MariaDB [wuhan]> flush table s;
Query OK, 0 rows affected (0.001 sec) MariaDB [wuhan]> select nextval(s),lastval(s);
+------------+------------+
| nextval(s) | lastval(s) |
+------------+------------+
| 1001 | 1001 |
+------------+------------+
1 row in set (0.001 sec) MariaDB [wuhan]> flush table s;
Query OK, 0 rows affected (0.000 sec) MariaDB [wuhan]> select nextval(s),lastval(s);
+------------+------------+
| nextval(s) | lastval(s) |
+------------+------------+
| 2001 | 2001 |
+------------+------------+
1 row in set (0.001 sec) 缺点:
由于在MariaDB中在很多应用场景中序列对象充当普通的表,将会受到lock table操作的影响。但是在其他DBMS中则不会受影响,比如oracle中的序列。 序列兼容性:
MariaDB兼容ANSI SQL和oracle 序列的语法,oracle 语法的序列需要将SQL_MODE设置为SQL_MODE=oracle. 序列备份:
由于序列是只有一行数据的常规表,因此mysqldump可以很好的支持。 序列和复制:
若在master-master复制或者galera复制中使用序列,需要设置 INCREMENT=0,以告知sequence对象使用
auto_increment_increment和 auto_increment_offset对每个服务器产生唯一的序列值。
转自:
https://mariadb.com/kb/en/library/sequence-overview/ CREATE SEQUENCE `s` start with 10000000000000 minvalue 10000000000000 maxvalue 9223372036854775806 increment by 1 cache 1000 nocycle ENGINE=InnoDB
MariaDB 10.3 序列的更多相关文章
- MySQL与MariaDB核心特性比较详细版v1.0(覆盖mysql 8.0/mariadb 10.3,包括优化、功能及维护)
注:本文严禁任何形式的转载,原文使用word编写,为了大家阅读方便,提供pdf版下载. MySQL与MariaDB主要特性比较详细版v1.0(不含HA).pdf 链接:https://pan.baid ...
- 从MySQL 5.5迁移到Mariadb 10.1.14
从MySQL 5.5迁移到Mariadb 10.1.14 迁移计划如下: 1.备份MySQL 5.5的数据库,对指定库进行备份. 2.还原到Mariadb,然后建立复制. 3.然后就可以愿意啥时候切换 ...
- mariadb 10.2.3支持延时复制
在mysql 5.6开始就支持延时复制,这在一些需要维护大量非标准化系统或者运维技术水平较低的公司和开发人员众多的项目组这是一个非常有价值的特性,可以说误操作的概率跟一个城市车祸概率的水平差不多了,我 ...
- MariaDB 10.1配置
[mysqld]datadir=C:/Program Files/MariaDB 10.1/dataport=3306sql_mode="STRICT_TRANS_TABLES,NO_ENG ...
- Mariadb 10.1 joiner节点加入报错WSREP: Failed to prepare for incremental state transfer
Mariadb 10.1 galera cluster 集群joiner 节点加入集群 会出现这种报错,导致mysql一直点点点,这里我贴出报错.2016年04月19日13:34:58 2016-04 ...
- mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法
mariadb 10 多源复制(Multi-source replication) 业务使用场景分析,及使用方法 官方mysql一个slave只能对应一个master,mariadb 10开始支持多源 ...
- 循环-10. 求序列前N项和*
/* * Main.c * C10-循环-10. 求序列前N项和 * Created on: 2014年7月30日 * Author: Boomkeeper *******部分通过******* */ ...
- SQLServer2012 和 MariaDB 10.0.3 分页效率的对比
1. 实验环境 R910服务器, 16G内存 SqlServer 2012 64bit MariaDB 10.0.3 64bit (InnoDB) 2. 实验表情况 rtlBill ...
- Docker MariaDB 10.3 Galera Cluster 集群同步复制 多主 Docker Haproxy 负载均衡
mariadb 现有动态列,支持json格式存储,类似mongodb的bson,但是操作能力较为尴尬,中间件有spider,我非常感兴趣的一个东西 关于spider 这里有一篇很好的博文,有时间一定得 ...
随机推荐
- 一些开源的dashboard 解决方案
简单收集了以下开源dashboard 的项目,记录下 plotly-dash 基于python 的dash 开发工具,很不错 项目地址 https://github.com/plotly/dash k ...
- 12-网页,网站,微信公众号基础入门(编写后台PHP程序,实现Airkiss配网)
https://www.cnblogs.com/yangfengwu/p/11067590.html 首先说一下,这两个地方需要配置一样 网站根目录建个文件夹 airkiss的文件夹 里面放上 ind ...
- ACM数据结构-树状数组
模板: int n; int tree[LEN]; int lowbit(int x){ return x&-x; } void update(int i,int d){//index,del ...
- Markdown&Latex学习笔记,qwq
目录 推荐的文章 居中 字体 加颜色 指数 分数 根号 神奇的符号(不要多想qwq) 箭头 小于号 大括号 累加符号 累乘符号 下标 \(\phi\)&\(\varphi\) \(\equiv ...
- Zookeeper循环注册监听器
Zookeeper中的监听器只执行一次,需要在watcher类中重写process方法,以达到重复注册监听器的效果 /** * 连接zk服务器 * */ public static void conn ...
- shell 四则运算
test.sh #/bin/bash read -p "请输入第一个数:" a read -p "请输入第二个数:" b if [ $a -gt $b ] th ...
- 「BJOI2018」治疗之雨
传送门 Description 有\(m+1\)个数,第一个数为\(p\),每轮:选一个数\(+1\),再依次选\(k\)个数\(-1\) 要求如果第一个数\(=N\),不能选它\(+1\),如果第一 ...
- 三个面向对象相关的装饰器@property@staticmathod@classmethod
@property 先看实例: from math import pi class Circle: def __init__(self,r): self.r = r @property def per ...
- Vue使用NProgress
NProgress是页面跳转是出现在浏览器顶部的进度条官网:http://ricostacruz.com/nprogress/github:https://github.com/rstacruz/np ...
- H3C交换机恢复出厂设置
reset saved-configuration reboot 恢复出厂设置后查看当前配置: ..............................