Skip to content
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

Query: Improve extensibility of null semantics processor #20854

Merged
merged 1 commit into from
May 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/EFCore.Relational/Properties/RelationalStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@
<data name="ClientGroupByNotSupported" xml:space="preserve">
<value>Client side GroupBy is not supported.</value>
</data>
<data name="UnexpectedJoinPredicateShape" xml:space="preserve">
<value>Unexpected join predicate shape: {predicate}.</value>
<data name="UnknownExpressionType" xml:space="preserve">
<value>Unknown expression '{expression}' of type - '{expressionType}' encountered in '{visitor}'.</value>
</data>
<data name="NoTypeMappingFoundForSubquery" xml:space="preserve">
<value>The subquery '{subquery}' references type '{type}' for which no type mapping could be found.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public virtual IRelationalCommand GetRelationalCommand([NotNull] IReadOnlyDictio

try
{
var (selectExpression, canCache) =
_relationalParameterBasedQueryTranslationPostprocessor.Optimize(_selectExpression, parameters);
var selectExpression = _relationalParameterBasedQueryTranslationPostprocessor.Optimize(
_selectExpression, parameters, out var canCache);
relationalCommand = _querySqlGeneratorFactory.Create().GetCommand(selectExpression);

if (canCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,33 @@ public RelationalParameterBasedQueryTranslationPostprocessor(
/// </summary>
/// <param name="selectExpression"> A select expression to optimize. </param>
/// <param name="parametersValues"> A dictionary of parameter values to use. </param>
/// <returns> A tuple of optimized select expression and a bool value if it can be cached. </returns>
public virtual (SelectExpression, bool) Optimize(
/// <param name="canCache"> A bool value indicating if the select expression can be cached. </param>
/// <returns> An optimized select expression. </returns>
public virtual SelectExpression Optimize(
[NotNull] SelectExpression selectExpression,
[NotNull] IReadOnlyDictionary<string, object> parametersValues)
[NotNull] IReadOnlyDictionary<string, object> parametersValues,
out bool canCache)
{
Check.NotNull(selectExpression, nameof(selectExpression));
Check.NotNull(parametersValues, nameof(parametersValues));

var canCache = true;
var (sqlExpressionOptimized, optimizerCanCache) = new NullabilityBasedSqlProcessingExpressionVisitor(
selectExpression = new SqlNullabilityProcessor(
smitpatel marked this conversation as resolved.
Show resolved Hide resolved
Dependencies.SqlExpressionFactory,
parametersValues,
UseRelationalNulls).Process(selectExpression);

canCache &= optimizerCanCache;
UseRelationalNulls).Process(selectExpression, out canCache);

var fromSqlParameterOptimized = new FromSqlParameterApplyingExpressionVisitor(
Dependencies.SqlExpressionFactory,
Dependencies.TypeMappingSource,
Dependencies.ParameterNameGeneratorFactory.Create(),
parametersValues).Visit(sqlExpressionOptimized);
parametersValues).Visit(selectExpression);

if (!ReferenceEquals(sqlExpressionOptimized, fromSqlParameterOptimized))
if (!ReferenceEquals(selectExpression, fromSqlParameterOptimized))
{
canCache = false;
}

return ((SelectExpression)fromSqlParameterOptimized, canCache);
return (SelectExpression)fromSqlParameterOptimized;
}
}
}
Loading