Skip to content

[multistage] Physical Optimizer Incorrect Results with Order-By in Window Operator #15955

Open
@ankitsultana

Description

@ankitsultana

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions