virtual_columns.txt (675B)
Can you explain the concept of virtual columns in MariaDB and provide a use case? Virtual columns in MariaDB are columns that are not physically stored in the table (unless explicitly set to STORED), but are instead computed on the fly based on an expression. A use case of a virtual column could be to allow indexing to happen in situations where the WHERE clause needs to do typechecking. For example, a query's WHERE clause might do LENGTH(column_value) on column1, in which case an index on column1 would not help. However, if we generate the column with "GENERATED ALWAYS AS LENGTH(column_value), the virtual column can be indexed to boost the speeds of slow selects.