-
Notifications
You must be signed in to change notification settings - Fork 250
Improved N-1 join query performance for DW SQL #2631
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
9ed5207
init commit
lingxiao-microsoft f84978f
added unit tests
lingxiao-microsoft c5e59c3
minor updates
lingxiao-microsoft 2a284e9
Merge branch 'main' into lingxiao/dw-sql-perf
lingxiao-microsoft 1c74fa8
fixing format
lingxiao-microsoft a484736
addressing comments
lingxiao-microsoft b423ea7
added a base class for mssql and dwsql
lingxiao-microsoft a11ff9f
refactor the feature flag functionality
lingxiao-microsoft 6060241
added table alias when building columns
lingxiao-microsoft da8a948
set the right default value for the flag
lingxiao-microsoft eaf9501
Merge branch 'main' into lingxiao/dw-sql-perf
lingxiao-microsoft 7f1f2dc
addressing latest comments 4/1
lingxiao-microsoft 62e1e7c
fixed format
lingxiao-microsoft 5b9154e
Merge branch 'main' into lingxiao/dw-sql-perf
lingxiao-microsoft 0a4b33a
removed unused code
lingxiao-microsoft 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
namespace Azure.DataApiBuilder.Config.ObjectModel | ||
{ | ||
/// <summary> | ||
/// The class is used for ephemeral feature flags to turn on/off features in development | ||
/// </summary> | ||
public class FeatureFlags | ||
{ | ||
/// <summary> | ||
/// By default EnableDwNto1JoinQueryOptimization is disabled | ||
/// We should change the default as True once got more confidence with the fix | ||
/// </summary> | ||
public bool EnableDwNto1JoinQueryOptimization { get; set; } | ||
|
||
public FeatureFlags() | ||
{ | ||
this.EnableDwNto1JoinQueryOptimization = false; | ||
} | ||
} | ||
} |
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
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,132 @@ | ||
using Azure.DataApiBuilder.Config.ObjectModel; | ||
using Azure.DataApiBuilder.Core.Models; | ||
|
||
namespace Azure.DataApiBuilder.Core.Resolvers | ||
{ | ||
/// <summary> | ||
/// Base query builder class for T-SQL engine | ||
/// Can be used by dwsql and mssql | ||
/// </summary> | ||
public abstract class BaseTSqlQueryBuilder : BaseSqlQueryBuilder | ||
Aniruddh25 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
protected const string FOR_JSON_SUFFIX = " FOR JSON PATH, INCLUDE_NULL_VALUES"; | ||
protected const string WITHOUT_ARRAY_WRAPPER_SUFFIX = "WITHOUT_ARRAY_WRAPPER"; | ||
|
||
/// <summary> | ||
/// Build the Json Path query needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with JSON PATH format</returns> | ||
protected virtual string BuildJsonPath(SqlQueryStructure structure) | ||
{ | ||
string query = string.Empty; | ||
query += FOR_JSON_SUFFIX; | ||
if (!structure.IsListQuery) | ||
{ | ||
query += "," + WITHOUT_ARRAY_WRAPPER_SUFFIX; | ||
} | ||
|
||
return query; | ||
} | ||
|
||
/// <summary> | ||
/// Build the predicates query needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with predicates</returns> | ||
protected virtual string BuildPredicates(SqlQueryStructure structure) | ||
{ | ||
return JoinPredicateStrings( | ||
structure.GetDbPolicyForOperation(EntityActionOperation.Read), | ||
structure.FilterPredicates, | ||
Build(structure.Predicates), | ||
Build(structure.PaginationMetadata.PaginationPredicate)); | ||
} | ||
|
||
/// <summary> | ||
/// Build the Group By Clause needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with group-by clause</returns> | ||
protected virtual string BuildGroupBy(SqlQueryStructure structure) | ||
{ | ||
// Add GROUP BY clause if there are any group by columns | ||
if (structure.GroupByMetadata.Fields.Any()) | ||
{ | ||
return $" GROUP BY {string.Join(", ", structure.GroupByMetadata.Fields.Values.Select(c => Build(c)))}"; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Build the Having clause needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with having clause</returns> | ||
protected virtual string BuildHaving(SqlQueryStructure structure) | ||
{ | ||
if (structure.GroupByMetadata.Aggregations.Count > 0) | ||
{ | ||
List<Predicate>? havingPredicates = structure.GroupByMetadata.Aggregations | ||
.SelectMany(aggregation => aggregation.HavingPredicates ?? new List<Predicate>()) | ||
.ToList(); | ||
|
||
if (havingPredicates.Any()) | ||
{ | ||
return $" HAVING {Build(havingPredicates)}"; | ||
} | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Build the Order By clause needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with order-by clause</returns> | ||
protected virtual string BuildOrderBy(SqlQueryStructure structure) | ||
{ | ||
if (structure.OrderByColumns.Any()) | ||
{ | ||
return $" ORDER BY {Build(structure.OrderByColumns)}"; | ||
} | ||
|
||
return string.Empty; | ||
} | ||
|
||
/// <summary> | ||
/// Build the aggregation columns needed to append to the main query | ||
/// </summary> | ||
/// <param name="structure">Sql query structure to build query on</param> | ||
/// <returns>SQL query with aggregation columns</returns> | ||
protected virtual string BuildAggregationColumns(SqlQueryStructure structure) | ||
{ | ||
string aggregations = string.Empty; | ||
if (structure.GroupByMetadata.Aggregations.Count > 0) | ||
{ | ||
if (structure.Columns.Any()) | ||
{ | ||
aggregations = $",{BuildAggregationColumns(structure.GroupByMetadata)}"; | ||
} | ||
else | ||
{ | ||
aggregations = $"{BuildAggregationColumns(structure.GroupByMetadata)}"; | ||
} | ||
} | ||
|
||
return aggregations; | ||
} | ||
|
||
/// <summary> | ||
/// Build the aggregation columns needed to append to the main query | ||
/// </summary> | ||
/// <param name="metadata">GroupByMetadata</param> | ||
/// <returns>SQL query with aggregation columns</returns> | ||
protected virtual string BuildAggregationColumns(GroupByMetadata metadata) | ||
{ | ||
return string.Join(", ", metadata.Aggregations.Select(aggregation => Build(aggregation.Column, useAlias: true))); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.