diff --git a/gradle/version.properties b/gradle/version.properties index b0bf7e7db6..a09450312c 100644 --- a/gradle/version.properties +++ b/gradle/version.properties @@ -1 +1 @@ -hibernateVersion=6.0.0-SNAPSHOT \ No newline at end of file +hibernateVersion=6.0.0.BENCHMARK \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java index 5c80e0da90..199a18a4b5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstProcessingStateImpl.java @@ -85,10 +85,6 @@ public class SqlAstProcessingStateImpl // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // SqlExpressionResolver - protected Map sqlSelectionMap() { - return Collections.emptyMap(); - } - @Override public Expression resolveSqlExpression( String key, @@ -104,38 +100,9 @@ public class SqlAstProcessingStateImpl expressionMap.put( key, expression ); } - return normalize( expression ); - } - - protected Expression normalize(Expression expression) { - final Clause currentClause = currentClauseAccess.get(); - if ( sqlSelectionMap() != null && ( currentClause == Clause.ORDER || currentClause == Clause.GROUP ) ) { - // see if this (Sql)Expression is used as a selection, and if so - // wrap the (Sql)Expression in a special wrapper with access to both - // the (Sql)Expression and the SqlSelection. - // - // This is used for databases which prefer to use the position of a - // selected expression (within the select-clause) as the - // order-by, group-by or having expression - final SqlSelection selection = sqlSelectionMap().get( expression ); - if ( selection != null ) { - return new SqlSelectionExpression( selection ); - } - } - return expression; } -// @Override -// public Expression resolveSqlExpression(NonQualifiableSqlExpressible sqlSelectable) { -// final Expression expression = normalize( sqlSelectable.createExpression() ); -// final Consumer expressionConsumer = resolvedExpressionConsumerAccess.get(); -// if ( expressionConsumer != null ) { -// expressionConsumer.accept( expression ); -// } -// return expression; -// } - @Override public SqlSelection resolveSqlSelection( Expression expression, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java index 18c8a99c62..2cd348fd66 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQueryPartProcessingStateImpl.java @@ -62,16 +62,11 @@ public class SqlAstQueryPartProcessingStateImpl public QueryPart getInflightQueryPart() { return queryPart; } -// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // SqlExpressionResolver - private Map sqlSelectionMap; - private Map> fetchParentSqlSelectionMap; - - @Override - protected Map sqlSelectionMap() { - return sqlSelectionMap; - } + private Map sqlSelectionMap; @Override public SqlSelection resolveSqlSelection( @@ -79,42 +74,49 @@ public class SqlAstQueryPartProcessingStateImpl JavaType javaType, FetchParent fetchParent, TypeConfiguration typeConfiguration) { - final SqlSelection existing; - if ( sqlSelectionMap == null ) { - sqlSelectionMap = new HashMap<>(); - existing = null; - } - else { - existing = sqlSelectionMap.get( expression ); - } - - if ( existing != null && deduplicateSelectionItems ) { - return existing; - } - final Map fetchParentSelections; - if ( !deduplicateSelectionItems && fetchParent != null ) { - // De-duplicate selection items within the root of a fetch parent - final FetchParent root = fetchParent.getRoot(); - if ( fetchParentSqlSelectionMap == null ) { - fetchParentSqlSelectionMap = new HashMap<>(); - fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() ); + final Map selectionMap; + if ( deduplicateSelectionItems ) { + final SqlSelection existing; + if ( sqlSelectionMap == null ) { + sqlSelectionMap = new HashMap<>(); + existing = null; } else { + existing = (SqlSelection) sqlSelectionMap.get( expression ); + } + + if ( existing != null ) { + return existing; + } + //noinspection unchecked + selectionMap = (Map) sqlSelectionMap; + } + else if ( fetchParent != null ) { + // De-duplicate selection items within the root of a fetch parent + final Map> fetchParentSqlSelectionMap; + final FetchParent root = fetchParent.getRoot(); + if ( sqlSelectionMap == null ) { + sqlSelectionMap = fetchParentSqlSelectionMap = new HashMap<>(); + fetchParentSqlSelectionMap.put( root, selectionMap = new HashMap<>() ); + } + else { + //noinspection unchecked + fetchParentSqlSelectionMap = (Map>) sqlSelectionMap; final Map map = fetchParentSqlSelectionMap.get( root ); if ( map == null ) { - fetchParentSqlSelectionMap.put( root, fetchParentSelections = new HashMap<>() ); + fetchParentSqlSelectionMap.put( root, selectionMap = new HashMap<>() ); } else { - fetchParentSelections = map; + selectionMap = map; } } - final SqlSelection sqlSelection = fetchParentSelections.get( expression ); + final SqlSelection sqlSelection = selectionMap.get( expression ); if ( sqlSelection != null ) { return sqlSelection; } } else { - fetchParentSelections = null; + selectionMap = null; } final SelectClause selectClause = ( (QuerySpec) queryPart ).getSelectClause(); @@ -128,10 +130,8 @@ public class SqlAstQueryPartProcessingStateImpl selectClause.addSqlSelection( sqlSelection ); - sqlSelectionMap.put( expression, sqlSelection ); - - if ( fetchParentSelections != null ) { - fetchParentSelections.put( expression, sqlSelection ); + if ( selectionMap != null ) { + selectionMap.put( expression, sqlSelection ); } return sqlSelection; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index 4fdb325919..11947f164c 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -1596,11 +1596,13 @@ public abstract class AbstractSqlAstTranslator implemen private boolean hasDuplicateSelectItems(QuerySpec querySpec) { final List sqlSelections = querySpec.getSelectClause().getSqlSelections(); - final Map map = new IdentityHashMap<>( sqlSelections.size() ); + final Map map = new IdentityHashMap<>( sqlSelections.size() ); for ( int i = 0; i < sqlSelections.size(); i++ ) { - map.put( sqlSelections.get( i ).getExpression(), null ); + if ( map.put( sqlSelections.get( i ).getExpression(), Boolean.TRUE ) != null ) { + return true; + } } - return map.size() != sqlSelections.size(); + return false; } protected boolean supportsSimpleQueryGrouping() {