Skip to main content
Virtual columns are read-only metadata columns that the database exposes on native tables. They describe where a row is physically stored — which tablet, rowset, segment, and row position it comes from. Virtual columns are computed at query time on the BE (or CN) node. They are not stored on disk, consume no storage space, and are not part of the table schema. As a result, they:
  • do not appear in SELECT *,
  • do not appear in DESCRIBE <table> or SHOW CREATE TABLE <table>,
  • must be referenced explicitly by name.
Virtual columns are mainly used for diagnostics, for example analyzing how data is distributed across tablets, or locating the physical position of a specific row.

Available virtual columns

Column names are case-insensitive: _tablet_id_ and _TABLET_ID_ refer to the same virtual column. Together, _tablet_id_, _rowset_id_ (or _rss_id_), _segment_id_, and _row_id_ identify the physical position of a row at the moment it is read.

Usage

Virtual columns are available on native tables in the internal catalog (Duplicate Key, Aggregate, Unique Key, and Primary Key tables) and on materialized views. Tables in external catalogs do not expose virtual columns. You can reference a virtual column anywhere an ordinary column is allowed in a query: in the SELECT list, WHERE, GROUP BY, ORDER BY, aggregate functions, and joins. When a query involves multiple tables, qualify the column with the table name or alias, for example t._tablet_id_. The following examples use this table:

Query a virtual column

Virtual columns are hidden from SELECT *:

Analyze data distribution across tablets

Group by _tablet_id_ to see how many rows each tablet holds. This is a quick way to detect data skew caused by an unbalanced bucketing key.
To count the tablets that actually contain data:

Locate the physical position of a row

Filter on a virtual column

Note A predicate on a virtual column is evaluated while the data is being scanned. It does not reduce the set of tablets that the query reads.

Usage notes

  • Virtual columns describe physical storage, not business data. Their values can change when the underlying data is reorganized — for example by compaction, by a new load, by a schema change, or by replica migration. Do not store them as business keys, and do not rely on them to correlate rows across queries.
  • Virtual columns are query-only. They cannot be loaded into, updated, or declared in CREATE TABLE.
  • The database does not collect column statistics for virtual columns.
  • The names of virtual columns are reserved. By default, you cannot create a table column with any of these names, because a table column of the same name shadows the virtual column and makes both impossible to reference in a query. If you need such a column name, set the FE dynamic parameter allow_system_reserved_names to TRUE. See CREATE TABLE for details.

Enable or disable virtual columns

Virtual columns are controlled by the FE dynamic parameter enable_virtual_columns, which defaults to true. To disable them for the whole cluster:
When virtual columns are disabled, a query that references one fails with an error such as Column '_tablet_id_' cannot be resolved.