Question

I have a merge join in azure data warehouse. My estimated execution plan currently shows it as a many to many join. I'd like to know if it is possible to achieve a many to one join. Currently I'm struggling to think of a way to do this as primary keys and unique constraints are unsupported. Is there anything available that would allow me to tell it that one of the tables will always contain unique values.

Was it helpful?

Solution

Are you getting this info from an EXPLAIN plan or the new SSMS plan functionality for Azure SQL Data Warehouse? Please provide.

In the "box product" engine (SQL Server 2017 14.0.3008.27), I can reproduce converting a many-to-many MERGE join to a one-to-many using the DISTINCT keyword against a columnstore table. I can't guarantee this would behave the same in Azure SQL Data Warehouse however and it won't apply to all queries:

SELECT *
FROM dbo.Numbers a
    INNER JOIN 
        (
        SELECT TOP 10 Number
        FROM dbo.Numbers 
        ) b ON a.Number = b.Number
OPTION ( MERGE JOIN );
GO

SELECT *
FROM dbo.Numbers a
    INNER JOIN 
        (
        SELECT DISTINCT TOP 10 Number
        FROM dbo.Numbers 
        ) b ON a.Number = b.Number
OPTION ( MERGE JOIN );

Full script available here. My results:

one-to-many

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top