Virtual columns in MySQL and MariaDB

March 4, 2016
Author
Stephane Combaudon
Share this Post:

MariaDB no longer meeting your needs?

Migrate to Percona software for MySQL – an open source, production-ready, and enterprise-grade MySQL alternative.

Learn More


Virtual columns in MySQL and MariaDB

In this blog post, we compare virtual columns in MySQL and MariaDB.

Virtual columns are one of the standout features in MySQL 5.7. They allow you to store a value derived from one or more columns in the same table. This is a powerful way to build functional indexes. The feature has been available in MariaDB for some time, so it’s worth comparing the implementations.

Documentation

The MariaDB documentation is easy to find.

MySQL 5.7 documentation is less obvious, but the best reference is here.

MariaDB documentation does not clearly explain when to use persistent vs virtual columns. Indexes are only supported on persistent columns, but trade-offs could be better documented.

MySQL documentation suggests using virtual columns by default unless computation cost is high. Stored columns are not required for indexing in most cases.

Syntax

Creating a virtual column is similar in both systems:

However, NOT NULL is not supported in MariaDB:

Materialized columns also differ:

  • MariaDB: PERSISTENT
  • MySQL: STORED

Adding a Virtual Column

MySQL 5.7:

This is a metadata-only change and executes instantly.

MariaDB:

This requires a full table rebuild and is not online. Writes may stall during the operation.


MariaDB insert impact

Indexing

MariaDB requires virtual columns to be PERSISTENT to be indexed.

MySQL 5.7 allows indexing virtual columns without storing them, except when used as a primary key.

Example:

Differences:

  • MySQL: Online operation
  • MariaDB: Blocking operation

Conclusion

While MySQL 5.7 and MariaDB 10 appear similar in supporting virtual columns, their implementations differ significantly in syntax, performance, and operational impact.

MySQL 5.7 provides a more production-friendly implementation, especially for large tables and high-traffic environments.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved