简体   繁体   English

Grails和GORM:如何在域类上指定等效的CREATE INDEX?

[英]Grails & GORM: How to specify CREATE INDEX equivalent on a domain-class?

May I share my frustration. 我可以分享我的挫败感。 GORM (and Grails..) seems to have a VERY limited documentation regarding database indices. GORM(和Grails ..)似乎关于数据库索引的文档非常有限。 I haven't found any help from anywhere on how to create an index for a domain class when I want the index to be something more than just what has been documented here: http://grails.org/doc/latest/guide/GORM.html . 当我希望索引不仅仅是此处记录的内容时,我从任何地方都没有找到关于如何为域类创建索引的任何帮助: http : //grails.org/doc/latest/guide/ GORM.html

Here's in SQL what I would like to achieve the Grails' way: 在SQL中,我想实现Grails的方式:

CREATE INDEX very_fast_index 
ON slow_table(date DESC NULLS LAST) 
WHERE is_latest = true;

Seems like I could tell GORM to create an index for the date column. 似乎我可以告诉GORM为日期列创建索引。 But looks like there's ZERO options for adding the other criteria. 但是,似乎有用于添加其他条件的零选项。

As I hate when simple things are made extremely complicated, I've created these indices manually in the PostgreSQL CLI. 我讨厌简单的事情变得极其复杂,所以我在PostgreSQL CLI中手动创建了这些索引。 Not from Grails, which would be more portable. 不是来自Grails,后者会更便于携带。 I do not want to write any HQL, as I don't like that idea either. 我也不想写任何HQL,因为我也不喜欢这个想法。

Any ideas? 有任何想法吗? I've got none other than the manual way. 除了手动方式,我别无他法。

HQL is a Data manipulation language non a Data definition language so is not useful for your needs. HQL是一种数据操作语言,不是一种数据定义语言,因此对于您的需求没有用。 If you want to use database vendor specific features you have to bypass hibernate and use the lower level jdbc connection to do SQL querys. 如果要使用数据库供应商特定的功能,则必须绕过休眠模式,并使用较低级别的jdbc连接来执行SQL查询。 In grails you can use dataSource bean to make query the groovy way . 在grails中,可以使用dataSource bean进行常规的查询。 Of course this tight you to a specific database (in your case Postgres). 当然,这会使您无法使用特定的数据库(在您的情况下为Postgres)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM