HHH-7840 org.hibernate.id.IncrementGenerator very slow
This commit is contained in:
parent
1f690e7aa6
commit
263a84154e
|
@ -53,6 +53,7 @@ import org.hibernate.type.Type;
|
||||||
*
|
*
|
||||||
* @author Gavin King
|
* @author Gavin King
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
||||||
|
|
||||||
|
@ -103,7 +104,7 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
||||||
for ( int i=0; i < tables.length; i++ ) {
|
for ( int i=0; i < tables.length; i++ ) {
|
||||||
final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) );
|
final String tableName = dialect.quote( normalizer.normalizeIdentifierQuoting( tables[i] ) );
|
||||||
if ( tables.length > 1 ) {
|
if ( tables.length > 1 ) {
|
||||||
buf.append( "select " ).append( column ).append( " from " );
|
buf.append( "select max(" ).append( column ).append( ") as mx from " );
|
||||||
}
|
}
|
||||||
buf.append( Table.qualify( catalog, schema, tableName ) );
|
buf.append( Table.qualify( catalog, schema, tableName ) );
|
||||||
if ( i < tables.length-1 ) {
|
if ( i < tables.length-1 ) {
|
||||||
|
@ -112,7 +113,7 @@ public class IncrementGenerator implements IdentifierGenerator, Configurable {
|
||||||
}
|
}
|
||||||
if ( tables.length > 1 ) {
|
if ( tables.length > 1 ) {
|
||||||
buf.insert( 0, "( " ).append( " ) ids_" );
|
buf.insert( 0, "( " ).append( " ) ids_" );
|
||||||
column = "ids_." + column;
|
column = "ids_.mx";
|
||||||
}
|
}
|
||||||
|
|
||||||
sql = "select max(" + column + ") from " + buf.toString();
|
sql = "select max(" + column + ") from " + buf.toString();
|
||||||
|
|
Loading…
Reference in New Issue