[hibernate-issues] [Hibernate-JIRA] Created: (HHH-3597) Schema generation creates redundant indexes when using the Mysql5InnodbDialect

Mark Matthews (JIRA) noreply at atlassian.com
Tue Nov 11 12:47:15 EST 2008


Schema generation creates redundant indexes when using the Mysql5InnodbDialect
------------------------------------------------------------------------------

                 Key: HHH-3597
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3597
             Project: Hibernate Core
          Issue Type: Bug
          Components: core
         Environment: MySQL and any version of Hibernate with the Mysql5InnodbDialect (I checked trunk, the issue is still there)
            Reporter: Mark Matthews
            Priority: Critical


Mysql5InnodbDialect incorrectly adds indexes when adding foreign key constraints. Since MySQL-4.1.2, Innodb has automatically added an index if needed, or re-uses one if it can when adding a foreign key constraint. Adding it by "hand" creates a duplicate index, which wastes resources (i/o, cpu, disk space).

Reworking the following method fixes the issue:
    
@Override
    public String getAddForeignKeyConstraintString(
        String constraintName,
        String[] foreignKey,
        String referencedTable,
        String[] primaryKey, boolean referencesPrimaryKey) {
        
        String cols = StringHelper.join(", ", foreignKey);
        
        return new StringBuffer(30)
            .append(" add constraint ")
            .append(constraintName)
            .append(" foreign key (")
            .append(cols)
            .append(") references ")
            .append(referencedTable)
            .append(" (")
            .append( StringHelper.join(", ", primaryKey) )
            .append(')')
            .toString();
    }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list