Grails 添加域字段作为数据库索引

发布于 2024-12-20 13:00:47 字数 348 浏览 0 评论 0原文

我在我的项目中使用 grails 1.2.2 和 1.3.7。 我想向域表添加索引。

class Test {
String name
String surname

static mapping = {
name column: 'name', index: 'test_dx'
surname column: 'surname', index: 'test_dx'
}

我尝试

使用两个版本的 grails 和 dbCreate = "create" 或 dbCreate = "create-drop" 或 dbCreate = "update" (是我想使用的),但没有创建“自定义索引”。

I'm using grails 1.2.2 and 1.3.7 in my project.
I want to add an index to the domain's table.

class Test {
String name
String surname

static mapping = {
name column: 'name', index: 'test_dx'
surname column: 'surname', index: 'test_dx'
}

}

I tried with the two version of grails and with dbCreate = "create" or dbCreate = "create-drop" or dbCreate = "update" (is the one I want to use) but no "custom index" created.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇俏 2024-12-27 13:00:47

你的例子对我有用。如果我使用 MySQL 数据库在 update 模式下运行我的应用程序,那么我会从 MySQL 控制台得到以下信息:

mysql> show index from test;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| test  |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| test  |          1 | test_dx  |            1 | name        | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| test  |          1 | test_dx  |            2 | surname     | A         |           0 |     NULL | NULL   |      | BTREE      |         |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)

您正在使用什么数据库?

Your example works for me. If I run my app in update mode with a MySQL database, then I get this from the MySQL console:

mysql> show index from test;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| test  |          0 | PRIMARY  |            1 | id          | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| test  |          1 | test_dx  |            1 | name        | A         |           0 |     NULL | NULL   |      | BTREE      |         |
| test  |          1 | test_dx  |            2 | surname     | A         |           0 |     NULL | NULL   |      | BTREE      |         |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)

What database are you using?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文