Generated Columns for JSON Indexes
You cannot index a JSON column directly, but you can create a generated column from a JSON path and index that.
You cannot index a JSON column directly, but you can create a generated column from a JSON path and index that.
ALTER TABLE products
ADD COLUMN ram INT
GENERATED ALWAYS AS (attributes->'$.ram') STORED,
ADD INDEX idx_ram (ram);
-- Now this query uses the index
SELECT name FROM products WHERE ram = 16;
STORED generated columns use disk space; VIRTUAL are recomputed on read.