Mysql中rowid作用是什么_mysql中的_rowid[通俗易懂]

(104) 2023-06-10 11:12

Hi,大家好,我是编程小6,很荣幸遇见你,我把这些年在开发过程中遇到的问题或想法写出来,今天说一说Mysql中rowid作用是什么_mysql中的_rowid[通俗易懂],希望能够帮助你!!!。

前言

在Oracle数据库的表中的每一行数据都有一个唯一的标识符,称为rowid,在Oracle内部通常就是使用它来访问数据的。

而在MySQL中也有一个类似的隐藏列_rowid来标记唯一的标识。但是需要注意_rowid并不是一个真实存在的列,其本质是一个非空唯一列的别名。

PS:本文是基于MySQL 5.7进行研究的

_rowid到底是什么

在前文提到了_rowid并不是一个真实存在的列,其本质是一个非空唯一列的别名。为什么会这么说呢?

因为在某些情况下_rowid是不存在的,其只存在于以下情况:

当表中存在一个数字类型的单列主键时,_rowid其实就是指的是这个主键列

当表中不存在主键但存在一个数字类型的非空唯一列时,_rowid其实就是指的是对应非空唯一列。

需要注意以下情况是不存在_rowid的

主键列或者非空唯一列的类型不是数字类型

主键是联合主键

唯一列不是非空的。

详情可以参考MySQL官方文档内容:

If a table has a PRIMARY KEY or UNIQUE NOT NULL index that consists of a single column that has an integer type, you can use _rowid to refer to the indexed column in SELECT statements, as follows:

_rowid refers to the PRIMARY KEY column if there is a PRIMARY KEY consisting of a single integer column. If there is a PRIMARY KEY but it does not consist of a single integer column, _rowid cannot be used.

Otherwise, _rowid refers to the column in the first UNIQUE NOT NULL index if that index consists of a single integer column. If the first UNIQUE NOT NULL index does not consist of a single integer column, _rowid cannot be used.

参考资料

13.1.14 CREATE INDEX Syntax

Re: Oracle ROWID equivalent in MySQL

上一篇

已是最后文章

下一篇

已是最新文章

发表回复