MariaDB 能否创建一个函数式索引基于函数的索引

问题描述

我可以像在 Oracle 中一样在 MariaDB 中创建功能索引吗:

create index fnc_idx on table_name (to_char(date_col,'MM-YYYY'));

或任何替代解决方案...? 问候

解决方法

您可以使用计算列作为方法:

CREATE TABLE `orders` (
  `id` int(11) NOT NULL AUTO_INCREMENT,`order_date` datetime NOT NULL,-- add calculated column
  `order_month` VARCHAR(6) AS (CONCAT(MONTH(order_date),YEAR(order_date))) PERSISTENT,`client_id` int(11) NOT NULL,PRIMARY KEY (`id`),-- add calculated column index
  INDEX (`order_month`)
);

MariaDB fiddle

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...