HHH-14109 Use 'in expression count limit' if calculated count is greather than 'in expression count limit'

This commit is contained in:
Oliver Breidenbach 2020-07-17 12:17:17 +02:00 committed by Sanne Grinovero
parent da77ef948c
commit 80a59af39f
2 changed files with 31 additions and 6 deletions

View File

@ -538,7 +538,11 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
if ( inClauseParameterPaddingEnabled ) {
int bindValuePaddingCount = MathHelper.ceilingPowerOfTwo( bindValueCount );
if ( bindValueCount < bindValuePaddingCount && (inExprLimit == 0 || bindValuePaddingCount < inExprLimit) ) {
if ( inExprLimit > 0 && bindValuePaddingCount > inExprLimit ) {
bindValuePaddingCount = inExprLimit;
}
if ( bindValueCount < bindValuePaddingCount ) {
bindValueMaxCount = bindValuePaddingCount;
}
}

View File

@ -74,11 +74,8 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti
sqlStatementInterceptor.clear();
doInJPA( this::entityManagerFactory, entityManager -> {
return entityManager.createQuery(
"select p " +
"from Person p " +
"where p.id in :ids" )
.setParameter( "ids", IntStream.range( 0, MAX_COUNT ).boxed().collect(Collectors.toList()) )
return entityManager.createQuery( "select p from Person p where p.id in :ids" )
.setParameter( "ids", IntStream.range( 0, MAX_COUNT ).boxed().collect( Collectors.toList() ) )
.getResultList();
} );
@ -89,6 +86,30 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti
}
expectedInClause.append( ")" );
assertTrue( sqlStatementInterceptor.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ) );
}
@TestForIssue( jiraKey = "HHH-14109" )
@Test
public void testInClauseParameterPaddingToLimit() {
sqlStatementInterceptor.clear();
doInJPA( this::entityManagerFactory, entityManager -> {
return entityManager.createQuery(
"select p " +
"from Person p " +
"where p.id in :ids" )
.setParameter( "ids", IntStream.range( 0, 10 ).boxed().collect(Collectors.toList()) )
.getResultList();
} );
StringBuilder expectedInClause = new StringBuilder();
expectedInClause.append( "in (?" );
for ( int i = 1; i < MAX_COUNT; i++ ) {
expectedInClause.append( " , ?" );
}
expectedInClause.append( ")" );
assertTrue(sqlStatementInterceptor.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ));
}