zhuqi-lucas commented on PR #18817: URL: https://github.com/apache/datafusion/pull/18817#issuecomment-3569112079
> I haven't looked into all of this discussion and code (I just got tagged). I've been looking into optimizing sorted scanning in DataFusion and IMO where we should land is: > > 1. Via metadata (`FileScanConfig` / `ORDERED BY ...` in SQL) users declare a known sort order of their files. > 2. The planner uses statistics from the files + any `ORDER BY` clauses in the query to arrange file ordering to best match the query. The `FileSource` implementation can also receive the `ORDER BY` information and optimize scan order within a file (e.g. reversing the order of reads which is what I think this PR is doing). > 3. If the planner is able to deduce from file level stats that the files can be ordered and the `FileSource` reports that it is able to produce batches in sorted order then the optimizer can optimize away the sort completely. > > I hope that is helpful. Thank you @adriangb , it's helpful for future optimization. My current implementation focuses on a specific optimization case: when data is already sorted and we need the reverse order, we can flip the scan direction instead of reading everything and sorting. The reverse_scan in FileSource handles the within-file ordering reversal. I think these approaches are complementary - my PR handles the reverse scan optimization, while your vision provides a framework for broader sorted-scan optimizations using file-level statistics and metadata. Would be great to build toward that architecture incrementally. -- 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]
