mysql中的_rowid

前言

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

而在MySQL中也有一个相似的隐藏列_rowid来标记惟一的标识。可是须要注意_rowid并非一个真实存在的列,其本质是一个非空惟一列的别名。html

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

_rowid究竟是什么

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

由于在某些状况下_rowid是不存在的,其只存在于如下状况:数据库

  1. 当表中存在一个数字类型的单列主键时,_rowid其实就是指的是这个主键列
  2. 当表中不存在主键但存在一个数字类型非空惟一列时,_rowid其实就是指的是对应非空惟一列

须要注意如下状况是不存在_rowidui

  1. 主键列或者非空惟一列的类型不是数字类型
  2. 主键是联合主键
  3. 惟一列不是非空的。

详情能够参考MySQL官方文档内容:code

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:htm

  • _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.

参考资料

  1. 13.1.14 CREATE INDEX Syntax
  2. Re: Oracle ROWID equivalent in MySQL
相关文章
相关标签/搜索