Skip to content

Commit a26e667

Browse files
committed
HHH-19768 Prefer values list rendering to emulate in-list tuples over select unions
1 parent 0e3ef8a commit a26e667

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7664,7 +7664,24 @@ public void visitInListPredicate(InListPredicate inListPredicate) {
76647664
}
76657665
else if ( !dialect.supportsRowValueConstructorSyntaxInInList() ) {
76667666
// Some DBs like Oracle support tuples only for the IN subquery predicate
7667-
if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsUnionAll() ) {
7667+
if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsValuesList() ) {
7668+
inListPredicate.getTestExpression().accept( this );
7669+
if ( inListPredicate.isNegated() ) {
7670+
appendSql( " not" );
7671+
}
7672+
appendSql( " in (select * from (values" );
7673+
char separator = ' ';
7674+
for ( Expression expression : listExpressions ) {
7675+
appendSql( separator );
7676+
appendSql( OPEN_PARENTHESIS );
7677+
renderCommaSeparated( getSqlTuple( expression ).getExpressions() );
7678+
appendSql( CLOSE_PARENTHESIS );
7679+
separator = ',';
7680+
}
7681+
appendSql( CLOSE_PARENTHESIS );
7682+
appendSql( CLOSE_PARENTHESIS );
7683+
}
7684+
else if ( dialect.supportsRowValueConstructorSyntaxInInSubQuery() && dialect.supportsUnionAll() ) {
76687685
inListPredicate.getTestExpression().accept( this );
76697686
if ( inListPredicate.isNegated() ) {
76707687
appendSql( " not" );

0 commit comments

Comments
 (0)