Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Feature Request] Allow to specify the size of the indexes in the domain mapping #1856

Open
4 tasks
ppazos opened this issue Dec 11, 2024 · 0 comments
Open
4 tasks

Comments

@ppazos
Copy link

ppazos commented Dec 11, 2024

When working with indexes in MySQL (maybe in other databases too), there is an index size limit. If there is a string field that is bigger than the index size, Grails doesn't create the index even if it's defined in the mapping.

In MySQL it's possible to define a big varchar, then for the index to be created:

CREATE TABLE t1 (
col1 VARCHAR(10),
col2 VARCHAR(4096),
INDEX (col1, col2(10))
);

Without the size in the index, this error is thrown: Specified key was too long; max key length is 3072 bytes

CREATE TABLE t1 (
col1 VARCHAR(10),
col2 VARCHAR(4096),
INDEX (col1, col2)
);

Though something like that defined as a Grails Domain class would fail silently.

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Use MySQL as the database.

  2. Define a domain with a big string constraint:

class DataIndex {

  String archetypeId
  String archetypePath

   static constraints = {
      archetypePath(maxSize: 2048)
   }

   static mapping = {
      archetypeId index: 'aid,aidpath'
      archetypePath index: 'aidpath'
   }
}
  1. Run the app so the database schema is generated.
  2. You will notice the index that should contain archetypeId and archetypePath is not created in the database.

Expected Behaviour

There is no problem with the behavior, since the current mapping DSL doesn't allow to specify the size of the index. What I would propose is something like a maxSize on the long field when defining the indexes, because that is the one that causes issues independently of the index or indexes that include the corresponding table column:

class DataIndex {

  String archetypeId
  String archetypePath

   static constraints = {
      archetypePath(maxSize: 2048)
   }

   static mapping = {
      archetypeId index: 'aid,aidpath'
      archetypePath index: 'aidpath', maxSize: 255
   }
}

Actual Behaviour

An index size is not supported in the mapping DSL.

Environment Information

  • Operating System: Linux Minth 21.3
  • GORM Version: the one that's on Grails 5.3.3
  • Grails Version (if using Grails): Grails 5.3.3
  • JDK Version: OpenJDK 11.0.20.1

Example Application

  • TODO: link to github repository with example that reproduces the issue
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant