Derived values, automatically
A generated column is computed from an expression over other columns of the same row. Two flavors:
- VIRTUAL — computed on read; takes no extra storage. Default if you don't say.
- STORED — computed on write and stored in the row; faster to read, takes space.
Use them for derived values you query often (e.g., the domain part of an email, the length of a content blob, a JSON-extracted field). Generated columns can be indexed — including STORED ones for very fast lookups.
Tip:
STORED generated columns + indexes are the cleanest way to materialize a derived value for query performance without writing an UPDATE trigger. The schema enforces the derivation; you can't accidentally store an inconsistent value.