Since MySQL 5.7 one can put indexes on expressions, aka functional indexes, using generated columns. Basically you first need to use the generated column to define the functional expression, then indexed this column.
Quite useful when dealing with JSON functions, you can find an example here and the documentation there.
Starting with MySQL 8.0.13 we have now an easiest way to create functional indexes (or functional key parts as mentioned in the documentation) \o/
Let’s see how with a quick practical example.
One of my colleague asked me : « Is an ALTER TABLE with many specifications is faster than 1 ALTER TABLE by specification ? »
The answers seems quite intuitive, anyway figures are better than a long speech…
Context :
MySQL Community Server 5.5.22
InnoDB table with 8 539 238 rows.
17 columns with INT, CHAR, VARCHAR, TEXT, DATETIME, … fields