apache / apache/grails-core

How to define composite index order ?

Open
#14,424 1 comment 1 reaction 0 assignees View on GitHub
relates-to: grails-data-hibernate5
Dominant language
Groovy
Stars
2.9k
Forks
975
Avg merge
1d 22h
Merged PRs (30d)
92

Description

Here is a sample:

```groovy
class Nft {
String token
String address

static mapping = {
token index: 'idx_nft'
address index: 'idx_nft'
}
}
```

The result index is:

```sh
psql -c '\d+ nft' db
Table "public.nft"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
---------+------------------------+-----------+----------+---------------------------------+----------+--------------+-------------
id | bigint | | not null | nextval('nft_id_seq'::regclass) | plain | |
version | bigint | | not null | | plain | |
address | character varying(255) | | not null | | extended | |
token | character varying(255) | | not null | | extended | |
Indexes:
"nft_pkey" PRIMARY KEY, btree (id)
"idx_nft" btree (address, token)
Access method: heap
```

The composite index is: ` "idx_nft" btree (address, token)`.

How do I define a composite index in order `(token, address)`?

Thanks.

Contributor guide

Open the contributing guide

Research direction

Start with the static mapping block in the issue and compare its generated PostgreSQL index with the requested `(token, address)` order. Check the Grails mapping documentation or relevant mapping tests for composite-index ordering; done means the supported configuration and resulting index order are documented clearly.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, postgresql
Domain
databases
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.