Skip to content

[BUG] LEFT JOIN duplicate filter condition #759

Description

@mordio

Describe the bug
When a LEFT JOIN with multiple conditions is used and there are also multiple conditions in the WHERE clause, the filter in the FetchXML is duplicating a specific property but probably using different values so the result table is empty.

To Reproduce
Query to reproduce the behavior:

SELECT
  prd.mserp_dataareaid,
  prd.mserp_productnumber,
  prd.mserp_purchaseunitsymbol,
  prf.mserp_factor
FROM
  mserp_ecoresreleasedproductv2entity prd
  LEFT JOIN mserp_ecoresproductunitofmeasureconversionentity prf
    ON  prf.mserp_productnumber = prd.mserp_productnumber
    AND prf.mserp_fromunitsymbol = prd.mserp_purchaseunitsymbol
    AND prf.mserp_tounitsymbol = 'm2'
WHERE 1 = 1
  AND prd.mserp_dataareaid = 'usmf'
  AND prd.mserp_productnumber = 'testproduct'

produces this Execution Plan:

Image

and NULL in the Result:

Image

If I comment the dataareaid:

SELECT
  prd.mserp_dataareaid,
  prd.mserp_productnumber,
  prd.mserp_purchaseunitsymbol,
  prf.mserp_factor
FROM
  mserp_ecoresreleasedproductv2entity prd
  LEFT JOIN mserp_ecoresproductunitofmeasureconversionentity prf
    ON  prf.mserp_productnumber = prd.mserp_productnumber
    AND prf.mserp_fromunitsymbol = prd.mserp_purchaseunitsymbol
    AND prf.mserp_tounitsymbol = 'm2'
WHERE 1 = 1
--  AND prd.mserp_dataareaid = 'usmf'
  AND prd.mserp_productnumber = 'testproduct'

the Execution Plan fetches more or less all rows (which is better than filtering too much):

Image

and in the result the correct factor is shown:

Image

Expected behavior
The filter should be either correct or fetch all data and join local.

Screenshots
Same thing in the real world example:

Image

Again it works when I only leave 1 condition in the WHERE clause:

Image

Environment (please complete the following information):

  • SQL 4 CDS edition: XrmToolBox v1.2025.10.74, 10.3.0.0 & MarkMpn.Sql4Cds.Engine 10.3.0
  • Results of SELECT @@VERSION:
    Microsoft Dataverse - 9.2.26041.172
    SQL 4 CDS - 10.3.0.0
    Apr 10 2026 11:13:54
    Copyright © 2020 - 2025 Mark Carrington

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions