functional-index

How to make MySQL use functional index on a datetime column?

我的未来我决定 提交于 2020-12-16 02:23:05
问题 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`) -- <--

How to make MySQL use functional index on a datetime column?

帅比萌擦擦* 提交于 2020-12-16 02:19:24
问题 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`) -- <--