I have this query:
SELECT 
    PE1.PRODUCT_EQUIPMENT_KEY, -- primary key
    PE1.Customer_Ban, 
    PE1.Subscriber_No, 
    PE1.Prod_Equip_Cd, 
    PE1.Prod_Equip_Txt, 
    PE1.Prod_Equip_Category_Txt--,
    -- PE2.ep_rnk ------------------ UNCOMMENT THIS LINE
FROM 
    INT_ADM.Product_Equipment_Dim PE1
    INNER JOIN 
    ( 
        SELECT 
            PRODUCT_EQUIPMENT_KEY,
            ROW_NUMBER() OVER (PARTITION BY Customer_Ban, Subscriber_No ORDER BY Start_Dt ASC) AS ep_rnk
            FROM INT_ADM.Product_Equipment_Dim PE2
    ) PE2
    ON PE2.PRODUCT_EQUIPMENT_KEY = PE1.PRODUCT_EQUIPMENT_KEY
WHERE 
    Line_Of_Business_Cd = 'M' 
    AND /*v_Date_Start*/ TO_DATE( '2022/01/12', 'yyyy/mm/dd' ) BETWEEN Start_Dt AND End_Dt 
    AND Current_Ind = 'Y' 
If I run it as you see it then it runs in under a second.
If I run it with -- PE2.ep_rnk ------------------ UNCOMMENT THIS LINE uncommented then the query takes up to 5 minutes to complete.
I know it's something to do with ROW_NUMBER() but after looking all over online I can't find a good explanation and solution. Does anyone know why uncommenting that line makes the query so slow, and what I can do about it so it runs fast?
Much appreciate your help in advance.
 
    