Skip to content

Commit

Permalink
Do not fold NOT IN queries using an inner join to a left outer join
Browse files Browse the repository at this point in the history
Fixes #382
  • Loading branch information
MarkMpn committed Nov 3, 2023
1 parent 624e423 commit 749b9e5
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions MarkMpn.Sql4Cds.Engine/ExecutionPlan/FilterNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,11 @@ private bool FoldInExistsToFetchXml(NodeCompilationContext context, IList<Optimi
// We can fold NOT IN to a left outer join, using similar rules to IN on the primary key
else if (!nullFilter.IsNot && rightFetch.FetchXml.top == null)
{
// Can't add an outer join if the right side includes an inner join
// https://github.com/MarkMpn/Sql4Cds/issues/382
if (rightFetch.Entity.GetLinkEntities().Any(l => l.linktype == "inner"))
break;

// Replace the filter on the defined value name with a filter on the primary key column
nullFilter.Expression = (rightFetch.Alias + "." + context.DataSources[rightFetch.DataSource].Metadata[rightFetch.Entity.name].PrimaryIdAttribute).ToColumnReference();

Expand Down

0 comments on commit 749b9e5

Please sign in to comment.