I'm using MySQL 8.0.30 and known that it's supporting for Functional index. However I tried to create an index base on sum of some fields, it's very easy as below, but index is not used, even in possible indexes, it's not showed as well.
Here is my table
CREATE TABLE `sample_product` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`avai_qty` double DEFAULT NULL,
`picked_qty` double DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `functional_index` (((`avai_qty` + `picked_qty`)))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
And here is my query
select * from sample_product where avai_qty + picked_qty > 5000;
I tried to run explain
{
"query_block": {
"cost_info": {
"query_cost": "0.35"
},
"select_id": 1,
"table": {
"access_type": "ALL",
"attached_condition": "((`sample_product`.`avai_qty` + `sample_product`.`picked_qty`) > 5000)",
"cost_info": {
"data_read_per_join": "1K",
"eval_cost": "0.10",
"prefix_cost": "0.35",
"read_cost": "0.25"
},
"filtered": "100.00",
"rows_examined_per_scan": 1,
"rows_produced_per_join": 1,
"table_name": "sample_product",
"used_columns": [
"id",
"name",
"avai_qty",
"picked_qty"
]
}
}
}
I'm not sure if it's MySQL's bug or I did something wrong.
I have tried to show index and here is result, it has functional index as I defined