Virtual Column Support in the Optimizer
Example
CREATE TABLE t1 (json_data JSON);
INSERT INTO t1 VALUES('{"column1": 1234}');
INSERT INTO t1 ...ALTER TABLE t1
ADD COLUMN vcol1 INT AS (cast(json_value(json_data, '$.column1') AS INTEGER)),
ADD INDEX(vcol1);-- This uses the index before 11.8:
EXPLAIN SELECT * FROM t1 WHERE vcol1=100;
-- Starting from 11.8, this uses the index, too:
EXPLAIN SELECT * FROM t1
WHERE cast(json_value(json_data, '$.column1') AS INTEGER)=100;+------+-------------+-------+------+---------------+-------+---------+-------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+-------+---------+-------+------+-------+
| 1 | SIMPLE | t1 | ref | vcol1 | vcol1 | 5 | const | 1 | |
+------+-------------+-------+------+---------------+-------+---------+-------+------+-------+General Considerations
Accessing JSON fields
Cast the Value to the Desired Type
Specify the Collation for Strings
References
Last updated
Was this helpful?

