【问题标题】:MariaDB can we create a functional index ( index based on a function )MariaDB我们可以创建一个函数索引(基于函数的索引)
【发布时间】:2021-02-10 10:19:01
【问题描述】:

我可以像在 Oracle 中一样在 MariaDB 中创建函数索引吗?

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

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

【问题讨论】:

    标签: mariadb database-indexes


    【解决方案1】:

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

    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

    【讨论】:

    • 感谢@Slava Rozhnev 的帮助,将检查它。问候:)
    猜你喜欢
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    相关资源
    最近更新 更多