Avoid rendering unnecessary parenthesis for junctions

This commit is contained in:
Christian Beikov 2022-01-30 16:20:50 +01:00
parent cd555de724
commit afdedb0fc5
1 changed files with 12 additions and 4 deletions

View File

@ -5076,10 +5076,18 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
} }
private void visitJunctionPredicate(Junction.Nature nature, Predicate p) { private void visitJunctionPredicate(Junction.Nature nature, Predicate p) {
if ( p instanceof Junction && nature != ( (Junction) p ).getNature() ) { if ( p instanceof Junction ) {
appendSql( OPEN_PARENTHESIS ); final Junction junction = (Junction) p;
p.accept( this ); // If we have the same nature, or if this is a disjunction and the operand is a conjunction,
appendSql( CLOSE_PARENTHESIS ); // then we don't need parenthesis, because the AND operator binds stronger
if ( nature == junction.getNature() || nature == Junction.Nature.DISJUNCTION ) {
p.accept( this );
}
else {
appendSql( OPEN_PARENTHESIS );
p.accept( this );
appendSql( CLOSE_PARENTHESIS );
}
} }
else { else {
p.accept( this ); p.accept( this );