Skip to content

Commit

Permalink
Avoid errors when viewing naive execution plan with DEBUG_BYPASS_OPTI…
Browse files Browse the repository at this point in the history
…MIZATION hint
  • Loading branch information
MarkMpn committed Oct 8, 2023
1 parent 9f3f173 commit c99e071
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlanOptimizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ public IRootExecutionPlanNodeInternal[] Optimize(IRootExecutionPlanNodeInternal
var context = new NodeCompilationContext(DataSources, Options, ParameterTypes);

// Move any additional operators down to the FetchXml
var nodes =
hints != null && hints.OfType<UseHintList>().Any(list => list.Hints.Any(h => h.Value.Equals("DEBUG_BYPASS_OPTIMIZATION", StringComparison.OrdinalIgnoreCase)))
? new[] { node }
: node.FoldQuery(context, hints);
var bypassOptimization = hints != null && hints.OfType<UseHintList>().Any(list => list.Hints.Any(h => h.Value.Equals("DEBUG_BYPASS_OPTIMIZATION", StringComparison.OrdinalIgnoreCase)));
var nodes = bypassOptimization ? new[] { node } : node.FoldQuery(context, hints);

foreach (var n in nodes)
{
Expand All @@ -66,7 +64,8 @@ public IRootExecutionPlanNodeInternal[] Optimize(IRootExecutionPlanNodeInternal
SortFetchXmlElements(n);

// Let the nodes know that folding is now finished so they can do any internal tidy-up
MarkComplete(n);
if (!bypassOptimization)
MarkComplete(n);
}

return nodes;
Expand Down

0 comments on commit c99e071

Please sign in to comment.