Skip to main content
InterviewHubPRO
Section Overview
Q34

Question 34 of 50

Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

68%
MySQL & InnoDB (50 Qs)•Part 3: Advanced Internals, Scale & Production Patterns (Senior / Lead)

What are Virtual and Generated Columns in MySQL 8.0?

senior LevelDatabases & SQLMySQL

In Simple Words: Columns whose values are calculated dynamically from an expression:

  • VIRTUAL: Calculated on-the-fly when read; consumes 0 disk storage. Can be indexed!
  • STORED: Evaluated and written to disk when the row is inserted or updated.
  • Great for extracting and indexing fields from JSON documents: ALTER TABLE orders ADD COLUMN customer_country VARCHAR(50) AS (data->>'$.country') VIRTUAL;