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 这里有一篇很好的博文,有时间一定得 ...
随机推荐
- [Algorithm] 350. Intersection of Two Arrays II
Given two arrays, write a function to compute their intersection. Example 1: Input: nums1 = [1,2,2,1 ...
- Good Article Good sentence HDU - 4416 (后缀数组)
Good Article Good sentence \[ Time Limit: 3000 ms\quad Memory Limit: 32768 kB \] 题意 给出一个 \(S\) 串,在给出 ...
- LINUX下的gdb调试方法
首先对目标文件进行编译 例如: gcc test.c -o test 这时会生成一个文件test,然后我们就可以对test进行调试了 示例: gdb test 好了以后是设定断点 示例: break ...
- X-factor Chain(信息学奥赛一本通 1628)
题目描述 输入正整数 x,求 x 的大于 1 的因子组成的满足任意前一项都能整除后一项的序列的最大长度,以及满足最大长度的序列的个数. 输入 多组数据,每组数据一行,包含一个正整数 x. 对于全部数据 ...
- IntelliJ IDEA 统一设置编码为utf-8编码 /idea设置编码
问题一. File->Settings->Editor->File Encodings 问题二. File->Other Settings->Default Settin ...
- PowerDesigner应用02 逆向工程之导出PDM文件前过滤元数据(表、视图、存储过程等)
在上一篇文章<PowerDesigner应用01 逆向工程之配置数据源并导出PDM文件>步骤二中导出了目标数据库对应的PDM文件, 该文件中展示出了所有表的信息与关系. 某些业务场景下只需 ...
- [技术博客] rails控制台调试路由
目录 rails console 获得路由 app.xxx_path 发送请求 获得响应 作者:庄廓然 rails console 在项目目录下执行rails console test 可以进入测试模 ...
- 强烈建议为你的Android项目加上 largeHeap 属性
小内存机器使用“微信”时,看视频经常崩溃(out of memory) ,小内存机器有时候明明内存还很多,却还是抛出“内存不够”,应该就是每个APP能用“堆大小”的限制. 如上图,Android项目的 ...
- java定时任务框架Quartz入门与Demo搭建
- linux中SIGHUP与nohup的关系
SIGHUP信号与控制终端 UNIX中进程组织结构为 session (会话)包含一个前台进程组及一个或多个后台进程组,一个进程组包含多个进程.一个session可能会有一个session首进程, ...