Skip to content

Commit 07b44a6

Browse files
committed
HHH-8370 remove support for row value constructor and adjust naming of new support
1 parent a517221 commit 07b44a6

File tree

4 files changed

+18
-35
lines changed

4 files changed

+18
-35
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6209,8 +6209,8 @@ public boolean supportsRowValueConstructorSyntaxInInSubQuery() {
62096209
}
62106210

62116211
/**
6212-
* If the dialect supports {@link org.hibernate.dialect.Dialect#supportsRowValueConstructorSyntax() row values},
6213-
* does it allow using them in a derived table within an EXISTS predicate that emulates an IN-list?
6212+
* This pattern avoids the SQL length and performance issues of large disjunctions,
6213+
* and emulates tuple-based IN-list comparisons using a derived VALUES table.
62146214
* <p>
62156215
* For example:
62166216
* <pre>
@@ -6220,13 +6220,8 @@ public boolean supportsRowValueConstructorSyntaxInInSubQuery() {
62206220
* WHERE T.FIELD1 = V.FIELD1 AND T.FIELD2 = V.FIELD2
62216221
* )
62226222
* </pre>
6223-
* This pattern avoids the SQL length and performance issues of large disjunctions,
6224-
* and emulates tuple-based IN-list comparisons using a derived VALUES table.
6225-
*
6226-
* @return True if this SQL dialect is known to support row value constructors in
6227-
* derived tables for EXISTS-based IN-list emulation; false otherwise.
62286223
*/
6229-
public boolean supportsRowValueConstructorSyntaxInDerivedTableInList() {
6224+
public boolean supportsValuesListForInListExistsEmulation() {
62306225
return false;
62316226
}
62326227
}

hibernate-core/src/main/java/org/hibernate/dialect/SQLServerDialect.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ public boolean supportsSimpleQueryGrouping() {
12451245

12461246
@Override
12471247
public boolean supportsRowValueConstructorSyntax() {
1248-
return getVersion().isSameOrAfter( 10 );
1248+
return false;
12491249
}
12501250

12511251
@Override
@@ -1264,7 +1264,7 @@ public boolean supportsRowValueConstructorSyntaxInInList() {
12641264
}
12651265

12661266
@Override
1267-
public boolean supportsRowValueConstructorSyntaxInDerivedTableInList() {
1267+
public boolean supportsValuesListForInListExistsEmulation() {
12681268
return getVersion().isSameOrAfter( 10 );
12691269
}
12701270
}

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.function.Consumer;
2222
import java.util.function.Function;
2323
import java.util.function.Supplier;
24-
import java.util.stream.Collectors;
2524

2625
import org.hibernate.AssertionFailure;
2726
import org.hibernate.Internal;
@@ -7643,49 +7642,38 @@ public void visitInListPredicate(InListPredicate inListPredicate) {
76437642
getSqlTuple( listExpression )
76447643
.getExpressions().get( 0 );
76457644
}
7646-
else if ( dialect.supportsRowValueConstructorSyntaxInDerivedTableInList() ) {
7645+
else if ( dialect.supportsValuesListForInListExistsEmulation() ) {
76477646
if ( inListPredicate.isNegated() ) {
76487647
appendSql( "not " );
76497648
}
7650-
appendSql( "exists (select 1 from (values " );
76517649

7652-
List<SqlTuple> listTuples = listExpressions.stream()
7653-
.map( SqlTupleContainer::getSqlTuple )
7654-
.toList();
7655-
for ( int i = 0; i < listTuples.size(); i++ ) {
7650+
appendSql( "exists (select 1 from (values " );
7651+
for ( int i = 0; i < listExpressions.size(); i++ ) {
76567652
if ( i > 0 ) {
76577653
appendSql( ", " );
76587654
}
7659-
76607655
appendSql( OPEN_PARENTHESIS );
7661-
renderCommaSeparatedSelectExpression( listTuples.get(i).getExpressions() );
7656+
renderCommaSeparatedSelectExpression( List.of( listExpressions.get( i ) ) );
76627657
appendSql( CLOSE_PARENTHESIS );
76637658
}
7664-
7665-
List<Expression> expressions = lhsTuple.getExpressions()
7666-
.stream()
7667-
.filter( expression -> expression.getColumnReference() != null )
7668-
.collect( Collectors.toList() );
76697659
appendSql( ") as v(" );
7660+
7661+
final List<? extends SqlAstNode> expressions = lhsTuple.getExpressions();
76707662
for ( int i = 0; i < expressions.size(); i++ ) {
76717663
if ( i > 0 ) {
76727664
appendSql( ", " );
76737665
}
7674-
appendSql( expressions.get( i ).getColumnReference().getColumnExpression() );
7666+
appendSql( "col_" + i );
76757667
}
7676-
76777668
appendSql( ") where " );
7669+
76787670
for ( int i = 0; i < expressions.size(); i++ ) {
76797671
if ( i > 0 ) {
76807672
appendSql( " and " );
76817673
}
7682-
7683-
Expression expression = expressions.get( i );
7684-
expression.accept( this );
7685-
appendSql( " = v." );
7686-
appendSql( expression.getColumnReference().getColumnExpression() );
7674+
expressions.get( i ).accept( this );
7675+
appendSql( " = v.col_" + i );
76877676
}
7688-
76897677
appendSql( CLOSE_PARENTHESIS );
76907678
return;
76917679
}

hibernate-core/src/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectCompositeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testCompositeQueryWithInPredicate(EntityManagerFactoryScope scope) {
5252
);
5353

5454
var query = sqlStatementInterceptor.getSqlQueries().get( 0 );
55-
assertTrue( query.endsWith( "where exists (select 1 from (values (?,?), (?,?)) as v(id1, id2) where ewci1_0.id1 = v.id1 and ewci1_0.id2 = v.id2)" ) );
55+
assertTrue( query.endsWith( "where exists (select 1 from (values (?,?), (?,?)) as v(col_0, col_1) where ewci1_0.id1 = v.col_0 and ewci1_0.id2 = v.col_1)" ) );
5656
}
5757

5858
@Test
@@ -72,7 +72,7 @@ public void testCompositeQueryWithNotInPredicate(EntityManagerFactoryScope scope
7272
);
7373

7474
var query = sqlStatementInterceptor.getSqlQueries().get( 0 );
75-
assertTrue( query.endsWith( "where not exists (select 1 from (values (?,?), (?,?)) as v(id1, id2) where ewci1_0.id1 = v.id1 and ewci1_0.id2 = v.id2)" ) );
75+
assertTrue( query.endsWith( "where not exists (select 1 from (values (?,?), (?,?)) as v(col_0, col_1) where ewci1_0.id1 = v.col_0 and ewci1_0.id2 = v.col_1)" ) );
7676
}
7777

7878
@Test
@@ -93,6 +93,6 @@ public void testCompositeQueryWithMultiplePredicatesIncludingIn(EntityManagerFac
9393
);
9494

9595
var query = sqlStatementInterceptor.getSqlQueries().get( 0 );
96-
assertTrue( query.endsWith( "where ewci1_0.description=? and exists (select 1 from (values (?,?), (?,?)) as v(id1, id2) where ewci1_0.id1 = v.id1 and ewci1_0.id2 = v.id2)" ) );
96+
assertTrue( query.endsWith( "where ewci1_0.description=? and exists (select 1 from (values (?,?), (?,?)) as v(col_0, col_1) where ewci1_0.id1 = v.col_0 and ewci1_0.id2 = v.col_1)" ) );
9797
}
9898
}

0 commit comments

Comments
 (0)