-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-8370 SQL Server IN-list Performance Improvement #10335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1245,7 +1245,7 @@ public boolean supportsSimpleQueryGrouping() { | |
|
|
||
| @Override | ||
| public boolean supportsRowValueConstructorSyntax() { | ||
| return false; | ||
| return getVersion().isSameOrAfter( 10 ); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -1263,4 +1263,8 @@ public boolean supportsRowValueConstructorSyntaxInInList() { | |
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean supportsRowValueConstructorSyntaxInDerivedTableInList() { | ||
| return getVersion().isSameOrAfter( 10 ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The minimum supported version is already |
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...rc/test/java/org/hibernate/orm/test/dialect/functional/SQLServerDialectCompositeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * Copyright Red Hat Inc. and Hibernate Authors | ||
| */ | ||
| package org.hibernate.orm.test.dialect.functional; | ||
|
|
||
| import org.hibernate.cfg.AvailableSettings; | ||
| import org.hibernate.dialect.SQLServerDialect; | ||
| import org.hibernate.orm.test.jpa.CompositeId; | ||
| import org.hibernate.orm.test.jpa.EntityWithCompositeId; | ||
| import org.hibernate.testing.jdbc.SQLStatementInspector; | ||
| import org.hibernate.testing.orm.junit.EntityManagerFactoryScope; | ||
| import org.hibernate.testing.orm.junit.JiraKey; | ||
| import org.hibernate.testing.orm.junit.Jpa; | ||
| import org.hibernate.testing.orm.junit.RequiresDialect; | ||
| import org.hibernate.testing.orm.junit.Setting; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * @author Rob Green | ||
| */ | ||
| @JiraKey( value = "HHH-8370" ) | ||
| @RequiresDialect( value = SQLServerDialect.class, majorVersion = 10 ) | ||
| @Jpa( | ||
| annotatedClasses = { EntityWithCompositeId.class }, | ||
| integrationSettings = { | ||
| @Setting( name = AvailableSettings.USE_SQL_COMMENTS, value = "true" ), | ||
| }, | ||
| useCollectingStatementInspector = true | ||
| ) | ||
| public class SQLServerDialectCompositeTest { | ||
| @Test | ||
| public void testCompositeQueryWithInPredicate(EntityManagerFactoryScope scope) { | ||
| final SQLStatementInspector sqlStatementInterceptor = scope.getCollectingStatementInspector(); | ||
| sqlStatementInterceptor.clear(); | ||
|
|
||
| List<CompositeId> compositeIds = new ArrayList<>(); | ||
| compositeIds.add( new CompositeId( 1,2 ) ); | ||
| compositeIds.add( new CompositeId( 3,4 ) ); | ||
|
|
||
| scope.inTransaction( entityManager -> { | ||
| entityManager.createQuery( "SELECT e FROM EntityWithCompositeId e WHERE e.id IN (:ids)" ) | ||
| .setParameter( "ids", compositeIds ) | ||
| .getResultList(); | ||
| } | ||
| ); | ||
|
|
||
| var query = sqlStatementInterceptor.getSqlQueries().get( 0 ); | ||
| 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)" ) ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompositeQueryWithNotInPredicate(EntityManagerFactoryScope scope) { | ||
| final SQLStatementInspector sqlStatementInterceptor = scope.getCollectingStatementInspector(); | ||
| sqlStatementInterceptor.clear(); | ||
|
|
||
| List<CompositeId> compositeIds = new ArrayList<>(); | ||
| compositeIds.add( new CompositeId( 1,2 ) ); | ||
| compositeIds.add( new CompositeId( 3,4 ) ); | ||
|
|
||
| scope.inTransaction( entityManager -> { | ||
| entityManager.createQuery( "SELECT e FROM EntityWithCompositeId e WHERE e.id NOT IN (:ids)" ) | ||
| .setParameter( "ids", compositeIds ) | ||
| .getResultList(); | ||
| } | ||
| ); | ||
|
|
||
| var query = sqlStatementInterceptor.getSqlQueries().get( 0 ); | ||
| 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)" ) ); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCompositeQueryWithMultiplePredicatesIncludingIn(EntityManagerFactoryScope scope) { | ||
| final SQLStatementInspector sqlStatementInterceptor = scope.getCollectingStatementInspector(); | ||
| sqlStatementInterceptor.clear(); | ||
|
|
||
| List<CompositeId> compositeIds = new ArrayList<>(); | ||
| compositeIds.add( new CompositeId( 1,2 ) ); | ||
| compositeIds.add( new CompositeId( 3,4 ) ); | ||
|
|
||
| scope.inTransaction( entityManager -> { | ||
| entityManager.createQuery( "SELECT e FROM EntityWithCompositeId e WHERE e.description = :description AND e.id IN (:ids)" ) | ||
| .setParameter( "ids", compositeIds ) | ||
| .setParameter( "description", "test" ) | ||
| .getResultList(); | ||
| } | ||
| ); | ||
|
|
||
| var query = sqlStatementInterceptor.getSqlQueries().get( 0 ); | ||
| 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)" ) ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.