Skip to content

Commit

Permalink
Fix to #19023 - Query: Log query plan
Browse files Browse the repository at this point in the history
Making RelationalCommandCache printable and printing it's SelectExpression.
Example query plan output:

queryContext => new QueryingEnumerable<int>(
    (RelationalQueryContext)queryContext,
    RelationalCommandCache.SelectExpression(
        (Projection Mapping:
            EmptyProjectionMember -> 0
        SELECT ((COUNT((*))))
        FROM (Customers AS c)
        WHERE ((c.CustomerID) == (N'ALFKI')))),
    null,
    ReaderColumn[] { ReaderColumn<int>, },
    Func<QueryContext, DbDataReader, ResultContext, int[], ResultCoordinator, int>,
    TestModels.Northwind.NorthwindRelationalContext,
    DiagnosticsLogger<Query>)
    .Single()

Fixes #19023
  • Loading branch information
maumar committed Feb 10, 2020
1 parent ab4c8aa commit d751472
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/EFCore.Relational/Query/Internal/RelationalCommandCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public class RelationalCommandCache
public class RelationalCommandCache : IPrintableExpression
{
private static readonly ConcurrentDictionary<object, object> _syncObjects
= new ConcurrentDictionary<object, object>();
Expand Down Expand Up @@ -73,6 +73,16 @@ public virtual IRelationalCommand GetRelationalCommand([NotNull] IReadOnlyDictio
return relationalCommand;
}

public virtual void Print(ExpressionPrinter expressionPrinter)
{
expressionPrinter.AppendLine("RelationalCommandCache.SelectExpression(");
using (expressionPrinter.Indent())
{
expressionPrinter.Visit(_selectExpression);
expressionPrinter.Append(")");
}
}

private readonly struct CommandCacheKey
{
private readonly SelectExpression _selectExpression;
Expand Down

0 comments on commit d751472

Please sign in to comment.