INNODB_VIRTUAL 表提供有关 InnoDB 虚拟生成列 以及基于虚拟生成列的列的元数据。The INNODB_VIRTUAL table provides
metadata about InnoDB
virtual generated
columns and columns upon which virtual generated columns
are based.
对于基于某一虚拟生成列的每一列,INNODB_VIRTUAL 表中会出现一行。A row appears in the INNODB_VIRTUAL
table for each column upon which a virtual generated column is
based.
INNODB_VIRTUAL 表具有以下列:The INNODB_VIRTUAL table has these
columns:
TABLE_ID表示与虚拟列关联的表的标识符;与
INNODB_TABLES.TABLE_ID相同的值。An identifier representing the table associated with the virtual column; the same value asINNODB_TABLES.TABLE_ID.POSThe position value of the virtual generated column. The value is large because it encodes the column sequence number and ordinal position. The formula used to calculate the value uses a bitwise operation:
((
nth virtual generated column for the InnoDB instance + 1) << 16) + the ordinal position of the virtual generated column例如,如果
InnoDB实例中的第一个虚拟生成列是表的第三列,则公式为(0 + 1) << 16) + 2。InnoDB实例中的第一个虚拟生成列始终为编号 0。作为表中的第三列,虚拟生成列的序数位置为 2。序数位置从 0 开始计数。For example, if the first virtual generated column in theInnoDBinstance is the third column of the table, the formula is(0 + 1) << 16) + 2. The first virtual generated column in theInnoDBinstance is always number 0. As the third column in the table, the ordinal position of the virtual generated column is 2. Ordinal positions are counted from 0.BASE_POS虚拟生成列所基于的列的序数位置。The ordinal position of the columns upon which a virtual generated column is based.
示例Example
mysql>CREATE TABLE `t1` (`a` int(11) DEFAULT NULL,`b` int(11) DEFAULT NULL,`c` int(11) GENERATED ALWAYS AS (a+b) VIRTUAL,`h` varchar(10) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;mysql>SELECT * FROM INFORMATION_SCHEMA.INNODB_VIRTUALWHERE TABLE_ID IN(SELECT TABLE_ID FROM INFORMATION_SCHEMA.INNODB_TABLESWHERE NAME LIKE "test/t1");+----------+-------+----------+ | TABLE_ID | POS | BASE_POS | +----------+-------+----------+ | 98 | 65538 | 0 | | 98 | 65538 | 1 | +----------+-------+----------+
注意事项Notes
如果将一个常量值分配给一个虚拟生成列,如下面的表所示,该列的条目不会出现在
INNODB_VIRTUAL表中。要显示条目,虚拟生成列必须有一个基础列。If a constant value is assigned to a virtual generated column, as in the following table, an entry for the column does not appear in theINNODB_VIRTUALtable. For an entry to appear, a virtual generated column must have a base column.CREATE TABLE `t1` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, `c` int(11) GENERATED ALWAYS AS (5) VIRTUAL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
然而,此类列的元数据会出现在
INNODB_COLUMNS表中。However, metadata for such a column does appear in theINNODB_COLUMNStable.你必须拥有
PROCESS权限才能查询此表。You must have thePROCESSprivilege to query this table.使用
INFORMATION_SCHEMACOLUMNS表或SHOW COLUMNS语句查看关于此表列的更多信息,包括数据类型和默认值。Use theINFORMATION_SCHEMACOLUMNStable or theSHOW COLUMNSstatement to view additional information about the columns of this table, including data types and default values.