You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 99e723d
Browse filesBrowse the repository at this point in the historyBrowse files
fix: retain only valid orderings after order-preserving repartition (#26747)
## Which issue does this PR close?
Closes#26745.
Closes#26036.
## Rationale for this change
An order-preserving repartition can incorrectly retain independent input
orderings that do not hold after merging partitions. This lets the
planner remove a necessary sort, causing `ORDER BY` to return rows in
the wrong order.
## What changes are included in this PR?
- Retain only the merge key ordering when repartitioning merges multiple
input partitions.
- Preserve projected cast relationships so valid cast-derived orderings
can still be inferred after the merge.
- Extend ordering checks to use equivalent expressions without assuming
that equality implies a strictly order-preserving transformation.
- Update affected expected plans.
## What is the testing strategy for this PR?
- Add the issue’s reproduction to `order.slt`, verifying exact row
order.
- Add safety cases in `equivalence_properties.slt` and
`monotonic_projection_test.slt`.
- Verify the existing unbounded-stream cast-ordering test continues to
pass.
## Are there any user-facing changes?
Only that queries affected by #26745 now return rows in the requested
order.
06)----------StreamingTableExec: partition_sizes=1, projection=[a, b, c], infinite_source=true, output_ordering=[a@0 ASC NULLS LAST, b@1 ASC NULLS LAST, c@2 ASC NULLS LAST]
237
364
365
+
# Strictly increasing functions also retain their derived ordering after merging.
366
+
query TT
367
+
EXPLAIN SELECT a, x, SUM(c) OVER (PARTITION BY x ORDER BY b) s
368
+
FROM (SELECT to_unixtime(a) x, a, b, c FROM t_inf);
369
+
----
370
+
physical_plan
371
+
01)ProjectionExec: expr=[a@1 as a, x@0 as x, sum(t_inf.c) PARTITION BY [x] ORDER BY [t_inf.b ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW@4 as s]
372
+
02)--BoundedWindowAggExec: wdw=[sum(t_inf.c) PARTITION BY [x] ORDER BY [t_inf.b ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW: Field { "sum(t_inf.c) PARTITION BY [x] ORDER BY [t_inf.b ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW": nullable Int64 }, frame: RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW], mode=[Sorted]
373
+
03)----RepartitionExec: partitioning=Hash([x@0], 2), input_partitions=2, preserve_order=true, sort_exprs=a@1 ASC NULLS LAST, b@2 ASC NULLS LAST, c@3 ASC NULLS LAST, x@0 ASC NULLS LAST
374
+
04)------ProjectionExec: expr=[to_unixtime(a@0) as x, a@0 as a, b@1 as b, c@2 as c]
0 commit comments