Skip to content

Commit

Permalink
Performance improvement for generating query plan with lots of joins
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Dec 27, 2021
1 parent 2e1991d commit 9482097
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion MarkMpn.Sql4Cds.Engine/ExecutionPlan/FetchXmlScan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public void SetValue(object value, IQueryExecutionOptions options)
private Dictionary<string, ParameterizedCondition> _parameterizedConditions;
private HashSet<string> _entityNameGroupings;
private Dictionary<string, string> _primaryKeyColumns;
private string _lastSchemaFetchXml;
private NodeSchema _lastSchema;

public FetchXmlScan()
{
Expand Down Expand Up @@ -446,6 +448,10 @@ public override NodeSchema GetSchema(IDictionary<string, DataSource> dataSources
if (!dataSources.TryGetValue(DataSource, out var dataSource))
throw new NotSupportedQueryFragmentException("Missing datasource " + DataSource);

var fetchXmlString = FetchXmlString;
if (_lastSchema != null && fetchXmlString == _lastSchemaFetchXml)
return _lastSchema;

_primaryKeyColumns = new Dictionary<string, string>();
var schema = new NodeSchema();

Expand All @@ -457,7 +463,9 @@ public override NodeSchema GetSchema(IDictionary<string, DataSource> dataSources
schema.PrimaryKey = $"{Alias}.{meta.PrimaryIdAttribute}";

AddSchemaAttributes(schema, dataSource.Metadata, entity.name, Alias, entity.Items);


_lastSchema = schema;
_lastSchemaFetchXml = fetchXmlString;
return schema;
}

Expand Down

0 comments on commit 9482097

Please sign in to comment.