Skip to content

Commit

Permalink
HHH-16589 Limit in clause padding to Dialect.getInExpressionCountLimi…
Browse files Browse the repository at this point in the history
…t and fix negated in predicate splitting
  • Loading branch information
beikov committed Jun 20, 2023
1 parent 5695536 commit 1cc94c7
Showing 1 changed file with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6839,13 +6839,6 @@ else if ( !supportsRowValueConstructorSyntaxInInList() ) {
}
}

inListPredicate.getTestExpression().accept( this );
if ( inListPredicate.isNegated() ) {
appendSql( " not" );
}
appendSql( " in (" );
String separator = NO_SEPARATOR;

int bindValueCount = listExpressions.size();
int bindValueMaxCount = bindValueCount;

Expand Down Expand Up @@ -6881,6 +6874,19 @@ else if ( bindValueCount < bindValuePaddingCount ) {
}
}

final boolean parenthesis = !inListPredicate.isNegated()
&& inExprLimit != 0 && listExpressions.size() > inExprLimit;
if ( parenthesis ) {
appendSql( OPEN_PARENTHESIS );
}

inListPredicate.getTestExpression().accept( this );
if ( inListPredicate.isNegated() ) {
appendSql( " not" );
}
appendSql( " in (" );
String separator = NO_SEPARATOR;

final Iterator<Expression> iterator = listExpressions.iterator();
int itemNumber = 0;
while ( iterator.hasNext() && ( inExprLimit == 0 || itemNumber < inExprLimit ) ) {
Expand All @@ -6904,11 +6910,15 @@ else if ( bindValueCount < bindValuePaddingCount ) {

if ( inExprLimit > 0 && bindValueCount > inExprLimit ) {
do {
append( ") or " );
inListPredicate.getTestExpression().accept( this );
if ( inListPredicate.isNegated() ) {
append( ") and " );
inListPredicate.getTestExpression().accept( this );
appendSql( " not" );
}
else {
append( ") or " );
inListPredicate.getTestExpression().accept( this );
}
appendSql( " in (" );
separator = NO_SEPARATOR;
itemNumber = 0;
Expand All @@ -6924,13 +6934,23 @@ else if ( bindValueCount < bindValuePaddingCount ) {

if ( inClauseParameterPaddingEnabled ) {
final Expression lastExpression = itemAccessor.apply( listExpressions.get( listExpressions.size() - 1 ) );
for ( ; itemNumber < bindValueMaxCount; itemNumber++ ) {
final int end;
if ( inExprLimit > 0 ) {
end = Math.min( bindValueMaxCount, inExprLimit );
}
else {
end = bindValueMaxCount;
}
for ( ; itemNumber < end; itemNumber++ ) {
appendSql( separator );
lastExpression.accept( this );
separator = COMMA_SEPARATOR;
}
}
appendSql( CLOSE_PARENTHESIS );
if ( parenthesis ) {
appendSql( CLOSE_PARENTHESIS );
}
}

@Override
Expand Down

0 comments on commit 1cc94c7

Please sign in to comment.