Can someone explain how to define multi column indexes in Grails? The documentation is at best sparse.
This for example does not seem to work at all: http://grails.org/GORM+Index+definitions
I've had some luck with this, but the results seems random at best. Definitions that works in one domain class does not when applied to another (with different names of course). http://www.grails.org/doc/1.1/guide/single.html#5.5.2.6%20Database%20Indices
Some working examples and explanations would be highly appreciated!
The solution that has worked for me for multi-column indexes is:
class ClassName {
String name
String description
String state
static mapping = {
name index: 'name_idx'
description index: 'name_idx'
state index: 'name_idx'
}
}
This creates an index called 'name_idx' with the three columns in the index.
Downside: the columns are listed in the index in alphabetical order, not the order that they were entered.
To make your index multi-column, list the columns with comma separator (note, no space after the comma, to avoid this bug. The second URL you point to hits the bug, as it says:
index:'Name_Idx, Address_Index'
with a space; it should work as
index:'Name_Idx,Address_Index'
The first URL you point to was a proposed change (I don't believe it's implemented currently and have no idea how likely it is to ever be).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With