grails - How to make GORM create an index on Map? -


in grails 2.3.7 project, have product domain class, this:

class product {     string code     string description     map attributes      static constraints = {         code(unique: true)     }      static mapping = {         code index: 'code_idx'         attributes fetch: 'join'         cache true         id generator: 'hilo'     } } 

it translates database:

create table product (id bigint not null, version bigint not null, code varchar(255) not null unique, description varchar(255) not null, primary key (id)); create table product_attributes (attributes bigint, attributes_idx varchar(255), attributes_elt varchar(255) not null); create index code_idx on product (code); 

with 4000 products in database, scaffold listing shows them fine.

except, when click "sort" on code - because there no index - server this:

explain select this_.id id14_0_, this_.version version14_0_, this_.code code14_0_, this_.description descript4_14_0_,  attributes2_.attributes attributes14_2_, attributes2_.attributes_elt attributes3_2_, attributes2_.attributes_idx attributes2_2_  product this_ left outer join product_attributes attributes2_  on this_.id=attributes2_.attributes  order lower(this_.code) desc limit 90, 100  +----+-------------+--------------+------+---------------+------+---------+------+-------+---------------------------------+ | id | select_type | table        | type | possible_keys | key  | key_len | ref  | rows  |                           | +----+-------------+--------------+------+---------------+------+---------+------+-------+---------------------------------+ |  1 | simple      | this_        |  | null          | null | null    | null |  4086 | using temporary; using filesort | |  1 | simple      | attributes2_ |  | null          | null | null    | null | 43975 |                                 | +----+-------------+--------------+------+---------------+------+---------+------+-------+---------------------------------+ 

obviously, takes ages. can manually add index:

alter table `product_attributes` add index(`attributes`); 

and works ok. think should have been created automatically in first place - there little sense in schema without index - ok, can ping gorm it. question - can put domain class have gorm add index ?

grails doesn't automatically create indexes on such columns 'attributes' in example. in order create , manage these indexes highly recommend using database migration plugin. documentation written, , outlines how use it.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -