mdashti commented on issue #20425: URL: https://github.com/apache/datafusion/issues/20425#issuecomment-3924138166
Closing this — the premise was wrong. The scenario described (ORDER BY = join key) is already handled efficiently by `LimitStream`'s lazy streaming. Since the output is already sorted by the ORDER BY column, `LimitStream` pulls exactly N rows and drops the stream. `SortMergeJoinExec` streams lazily too, so the scan nodes only produce as many rows as needed. A dynamic filter can't improve this — it would only be established after processing the first batch, at which point we already have the answer. For the case where ORDER BY differs from the join key (where dynamic filtering actually matters), `SortExec(TopK)` stays in the plan because the optimizer can't eliminate the sort. TopK creates and updates its `DynamicFilterPhysicalExpr` normally, and it successfully pushes down through `SortMergeJoinExec` to the leaf scan nodes. In short: the `LimitStream` short-circuit for sorted input is the correct behavior — there's no need for TopK to produce dynamic filters in that case, and the case that does need dynamic filters already works. Apologies for the noise. Our workaround (`StripOrderingExec`) was solving a non-problem; we're removing it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
