Open
Description
We should set sortOnReceiver
to true in PlanFragmentAndMailboxAssignment
if there's a collation in the PhysicalExchange
.
That should fix the issue. I had intentionally left this in the first iteration because I wanted to think through whether sortOnSender ever makes sense.
I think we don't need to overthink here and simply always choose sortOnReceiver. AFAIR the existing query optimizer also does the same.
Repro query with Colocated Join Quickstart (for each deviceOS, 101 should have been returned):
SET useMultistageEngine = true;
SET usePhysicalOptimizer = true;
EXPLAIN PLAN FOR WITH tmp AS (
SELECT deviceOS, totalTrips, daysSinceFirstTrip from userAttributes_OFFLINE
WHERE daysSinceFirstTrip > 100
)
SELECT
daysSinceFirstTrip,
deviceOS
FROM
(
SELECT
deviceOS,
daysSinceFirstTrip,
ROW_NUMBER() OVER (
PARTITION BY deviceOS
ORDER BY daysSinceFirstTrip
) AS rnk
FROM
tmp
) tmp2
WHERE
rnk = 1
ORDER BY deviceOS