A key inside a JSON column filtered on four hundred thousand times a day, promoted without changing any application code.
ALTER TABLE customers
ADD COLUMN tier VARCHAR(32)
GENERATED ALWAYS AS (settings->>'$.tier') STORED,
ADD INDEX idx_tier (tier);
-- and the query, unchanged:
SELECT id FROM customers WHERE settings->>'$.tier' = ?;
-- the optimiser matches the expression to the generated
-- column and uses the index. 2.1M rows → 412.
The optimiser matching a functional expression to a stored generated column is what makes this a zero-code change, and it is fragile — the expression must match exactly, so JSON_UNQUOTE(JSON_EXTRACT(...)) written the long way does not match ->>. Confirming with EXPLAIN is not optional, because the failure is silent and looks like the index not helping.