HHH-14109 Use 'in expression count limit' if calculated count is greather than 'in expression count limit'
This commit is contained in:
parent
da77ef948c
commit
80a59af39f
|
@ -538,7 +538,11 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
|
||||||
if ( inClauseParameterPaddingEnabled ) {
|
if ( inClauseParameterPaddingEnabled ) {
|
||||||
int bindValuePaddingCount = MathHelper.ceilingPowerOfTwo( bindValueCount );
|
int bindValuePaddingCount = MathHelper.ceilingPowerOfTwo( bindValueCount );
|
||||||
|
|
||||||
if ( bindValueCount < bindValuePaddingCount && (inExprLimit == 0 || bindValuePaddingCount < inExprLimit) ) {
|
if ( inExprLimit > 0 && bindValuePaddingCount > inExprLimit ) {
|
||||||
|
bindValuePaddingCount = inExprLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( bindValueCount < bindValuePaddingCount ) {
|
||||||
bindValueMaxCount = bindValuePaddingCount;
|
bindValueMaxCount = bindValuePaddingCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,11 +74,8 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti
|
||||||
sqlStatementInterceptor.clear();
|
sqlStatementInterceptor.clear();
|
||||||
|
|
||||||
doInJPA( this::entityManagerFactory, entityManager -> {
|
doInJPA( this::entityManagerFactory, entityManager -> {
|
||||||
return entityManager.createQuery(
|
return entityManager.createQuery( "select p from Person p where p.id in :ids" )
|
||||||
"select p " +
|
.setParameter( "ids", IntStream.range( 0, MAX_COUNT ).boxed().collect( Collectors.toList() ) )
|
||||||
"from Person p " +
|
|
||||||
"where p.id in :ids" )
|
|
||||||
.setParameter( "ids", IntStream.range( 0, MAX_COUNT ).boxed().collect(Collectors.toList()) )
|
|
||||||
.getResultList();
|
.getResultList();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -89,6 +86,30 @@ public class MaxInExpressionParameterPaddingTest extends BaseEntityManagerFuncti
|
||||||
}
|
}
|
||||||
expectedInClause.append( ")" );
|
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() ));
|
assertTrue(sqlStatementInterceptor.getSqlQueries().get( 0 ).endsWith( expectedInClause.toString() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue