How to make MySQL use functional index on a datetime column?
问题 Say I'm running MySQL 8 with a table data containing about 1M rows. And I want to filter a datetime column on date a range (using a date index). CREATE TABLE `data` ( `rowId` int NOT NULL AUTO_INCREMENT, `data` json NOT NULL, `created` DATETIME NOT NULL, -- <-- datetime column for a date index `created_date` DATE AS (cast(`created` as date)) NOT NULL, -- <-- generated date column PRIMARY KEY (`rowId`), INDEX (`created`), -- <-- datetime index w/ cardinality ~ 1M INDEX (`created_date`) -- <--