KingbaseES 中的xmin,xmax等系统字段说明
在KingbaseES中,当我们创建一个数据表时,数据库会隐式增加几个系统字段。这些字段由系统进行维护,用户一般不会感知它们的存在。
例如,以下语句创建了一个简单的表:
create table test(col number);
insert into test(col) values (1),(2),(3);
从定义上来看,表 test 中只有一个字段;但是当我们查询数据字典表 sys_attribute 时,结果却不是如此:
test=# \d test
数据表 "public.test"
栏位 | 类型 | 校对规则 | 可空的 | 预设
------+---------+----------+--------+------
col | numeric
test=# select attname, attnum, atttypid::regtype from sys_attribute where attrelid = 'test'::regclass;
attname | attnum | atttypid
----------+--------+----------
tableoid | -6 | oid
cmax | -5 | cid
xmax | -4 | xid
cmin | -3 | cid
xmin | -2 | xid
ctid | -1 | tid
col | 1 | numeric
(7 行记录)
查询结果显示,表test一共包含7个字段。KingbaseES为我们增加了6个额外的系统字段,它们的attnum属性都是负数。
下面让我们分别看看这些系统字段的作用。
tableoid
tableoid 字段代表了数据所在表的对象 id(OID),也就是数据字典表 sys_class 中与该表信息相关的数据行。
test=# select oid, relname from sys_class where relname = 'test';
oid | relname
-------+---------
51137 | test
(1 行记录)
test=# select tableoid, col from test ;
tableoid | col
----------+-----
51137 | 1
51137 | 2
51137 | 3
(3 行记录)
tableoid 的另一个用途就是在涉及分区表查询或者UNION操作时标识数据行所在的具体表(分区)。例如存在以下分区表:
test=# create table t_list(a int,b int)
test-# partition by list(a)
test-# (
test(# partition p1 values (1,2,3,4,5),
test(# partition p2 values (6,7,8,9,10)
test(# );
CREATE TABLE
test=# insert into t_list values(1,1);
INSERT 0 1
test=# insert into t_list values(7,1);
INSERT 0 1
test=# select tableoid::regclass,a from t_list;
tableoid | a
-----------+---
t_list_p1 | 1
t_list_p2 | 7
(2 行记录)
ctid
ctid 字段代表了数据行在表中的物理位置,也就是行标识(tuple identifier),由一对数值组成(块编号和行索引)。ctid 类似于 Oracle 中的伪列 ROWID。
需要注意的是,ctid的值有可能会改变(例如 VACUUM FULL);因此ctid不适合作为一个长期的行标识,应该使用主键作为行的逻辑标识。
test=# select ctid ,col from test;
ctid | col
-------+-----
(0,1) | 1
(0,2) | 2
(0,3) | 3
(3 行记录)
test=# delete from test where col = 1;
DELETE 1
test=# select ctid ,col from test;
ctid | col
-------+-----
(0,2) | 2
(0,3) | 3
(2 行记录)
test=# vacuum full test;
VACUUM
test=# select ctid ,col from test;
ctid | col
-------+-----
(0,1) | 2
(0,2) | 3
(2 行记录)
xmin
xmin代表了该行版本(row version)的插入事务ID(XID)。行版本是数据行的具体状态,每次更新操作都会为相同的逻辑行创建一个新的行版本(多版本并发控制,MVCC)。
xmin 字段可以用于查看数据行的插入时间,需要事先打开track_commit_timestamp参数(前两行插入时参数未设置所以没有查询到时间)。
test=# insert into test(col) values (4),(5),(6);
INSERT 0 3
test=# select col,to_char(sys_xact_commit_timestamp(xmin) ,'YYYY-MM-DD HH24:MI:SS') AS insert_time from test;
col | insert_time
-----+---------------------
2 |
3 |
4 | 2023-01-06 11:24:47
5 | 2023-01-06 11:24:47
6 | 2023-01-06 11:24:47
(5 行记录)
xmax
xmax 字段代表了删除该行的事务 ID,对于未删除的行版本显示为 0。非零的 xmax 通常意味着删除事务还没有提交,或者删除操作被回滚。
session 1:
test=# begin;
BEGIN
test=# update test set col=1 where col =4;
UPDATE 1
test=# select xmax,col from test;
xmax | col
------+-----
0 | 2
0 | 3
0 | 1
(3 行记录)
test=# delete from test where col =3;
DELETE 1
在事务未提交的情况下,在开一个新会话进行查询:
session 2
test=# select xmax,col from test;
xmax | col
-------+-----
0 | 2
42292 | 3
42292 | 4
(3 行记录)
KingbaseES的update操作是一个先delete后insert的过程,所以在事务未提交的情况下,session 2能看到记录4被42292事务删除的信息。
session 1事务提交后,session 2 查询结果:
test=# select xmax,col from test;
xmax | col
------+-----
0 | 2
0 | 1
(2 行记录)
cmin/cmax
代表元组变更的命令在插入事务中的命令标识(从0开始累加)。
test=# begin;
BEGIN
test=# insert into test values (3);
INSERT 0 1
test=# insert into test values (4);
INSERT 0 1
test=# insert into test values (5);
INSERT 0 1
test=# commit;
COMMIT
test=# insert into test values (6);
INSERT 0 1
test=# select cmin,cmax,col,xmin from test;
cmin | cmax | col | xmin
------+------+-----+-------
0 | 0 | 2 | 42290
0 | 0 | 1 | 42292
0 | 0 | 3 | 42293
1 | 1 | 4 | 42293
2 | 2 | 5 | 42293
0 | 0 | 6 | 42294
KingbaseES 中的xmin,xmax等系统字段说明的更多相关文章
- SY全局系统字段
声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...
- [转]ArcGIS计算图斑的四邻坐标(XMin,XMax,YMin,YMax)
1.背景: 在国土,调查等行业业务里面经常有需要计算某个图斑的四邻坐标,即xmax,xmin,ymin,ymax;也就是常说的MBR(最小外包矩形),本教程演示如何计算一个shapefile文件上的图 ...
- 获取sqlserver数据库中所有库、表、字段名的方法
获取sqlserver数据库中所有库.表.字段名的方法 2009年03月12日 星期四 下午 12:51 1.获取所有数据库名: SELECT Name FROM Master..SysDatabas ...
- ABAP系统字段
SY是一个全局的结构体变量,在词典中已定义过.输入SE11到ABAP字典中. 输入SYST点击显示 附录D 系统字段功能列表 字段名 类型 长度 应用目的 说明 ABCDE CHAR 26 常量 字母 ...
- Mysql中设置默认时间为系统当前时间
Mysql中设置默认时间为系统当前时间 数据库设计时会遇到的一种情况:将系统当前时间设成默认值存储 数据库设计编码: CREATE TABLE `test` ( `name` varchar(50) ...
- ABAP 数据字典中的参考表和参考字段的作用
ABAP数据字典中的参考表和参考字段的作用 大家最初在SE11中创建表和结构的时候都会遇到一个问题,如果设定了某个字段为QUAN或者CURR类型,也就是数量或金额的时候,总会要求输入一个参考 ...
- 提高安全性而在HTTP响应头中可以使用的各种响应头字段
本文介绍在Web服务器做出响应时,为了提高安全性而在HTTP响应头中可以使用的各种响应头字段.由于部分浏览器中有可能对某些字段或选项不提供支持,所以在使用这些字段时请先确认客户端环境. X-Frame ...
- [置顶] c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date'
c++,vc6.0,中友元函数,无法访问私有字段(private)的问题(problem),cannot access private member declared in class 'Date' ...
- 通过Web.config中的configSections配置自己系统的全局常量
通过Web.config中的configSections配置自己系统的全局常量 随着系统的庞大,你的全局信息保存在appsitting里可能会比较乱,不如为模块写个自定义的全局常量吧 首先在Web.C ...
- 5 个在 Linux 中管理文件类型和系统时间的有用命令
对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...
随机推荐
- 超详细的 springboot & mybatis 程序入门
ps:网上有很多类似的入门案例,我也是看了被人的之后自己写的一个 估计有哥们懒 我把数据表格拿上来,数据自己填吧 CREATE TABLE `tb_user` ( `id` int(10) DEFAU ...
- Linux上安装和部署git
本机环境: [git@rhel-server .ssh]$ cat /proc/version Linux version 2.6.32-358.el6.x86_64 1.安装 yum install ...
- win32- GetWindowText
从编辑框中获取控件文本 一般常用的方法是, wchar_t buffer[100]; GetWindowText(hWnd, buffer, sizeof(buffer) / sizeof(buffe ...
- 【Android 抓包对抗】代理检查绕过
1. 安装apk,点进去发现一点就挂 2. apk 拖入到jadx中观察,发现多出检查,一旦满足条件就会退出 .... if (((ConnectivityManager) getSystemServ ...
- 变量,六大数据类型之字符串、列表、元祖----day02
1.变量:可以改变的量,实际具体指的是内存中的一块存储空间 (1)变量的概念 (2)变量的声明 (3)变量的命名 (4)变量的交换 *常量就是不可改变的量,python当中没有明确定义常量的关键字,所 ...
- Celery在Django项目中集成
使用celery第一件要做的最为重要的事情是需要先创建一个Celery实例对象,我们一般叫做celery应用对象,或者更简单直接叫做一个app.app应用对象是我们使用celery所有功能的入口,比如 ...
- 【LeetCode回溯算法#05】分割回文串(复习双指针判断回文以及substr函数使用记录)
分割回文串 力扣题目链接 给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 .返回 s 所有可能的分割方案. 回文串 是正着读和反着读都一样的字符串. 示例 1: 输入:s = ...
- Centos系统下,各种服务重启
1.sudo systemctl start firewalld 2../redis-server /usr/local/bin/redis.conf 3.mongod -f /etc/mongod ...
- 【Azure Function App】Java Function在运行中遇见内存不足的错误
问题描述 在Function的Code+Test界面进行函数触发可以成功.因为Function为Blob Trigger,当在Blob容器下上传文件后,Function可以被正常触发但是报 outof ...
- redis 安装的参考文章
redis 安装 : https://www.runoob.com/redis/redis-install.html