如何在mariadb上创建功能索引?

时间:2019-05-29 08:21:54

标签: mariadb

我正尝试在mariadb 5.5上创建功能索引,如下所示...

MariaDB [testdb]> create table foo(c1 datetime);
Query OK, 0 rows affected (0.43 sec)

MariaDB [testdb]> alter table foo add c2 varchar(10) AS (date_format(c1, '%Y-%m-%d')); 
Query OK, 0 rows affected (0.22 sec)               
Records: 0  Duplicates: 0  Warnings: 0

MariaDB [testdb]> desc foo;
+-------+-------------+------+-----+---------+---------+
| Field | Type        | Null | Key | Default | Extra   |
+-------+-------------+------+-----+---------+---------+
| c1    | datetime    | YES  |     | NULL    |         |
| c2    | varchar(10) | YES  |     | NULL    | VIRTUAL |
+-------+-------------+------+-----+---------+---------+
2 rows in set (0.03 sec)

MariaDB [testdb]> create index idx_foo on foo(c1, c2);
ERROR 1904 (HY000): Key/Index cannot be defined on a non-stored computed column
MariaDB [testdb]> 

有什么用VIRUAL列创建基于组合列的索引的方法吗?

任何建议将不胜感激。

谢谢。

1 个答案:

答案 0 :(得分:1)

请参阅文档:

  

Generated (Virtual and Persistent/Stored) Columns

     

...

     

MariaDB,直到10.2.2

     

在MariaDB 10.2.2及更低版本中,以下声明适用于   生成列的索引:

     
      
  • 不支持在VIRTUAL生成的列上定义索引。
  •   
  • ...
  •   
     

...

相关问题