2010YOUY01 opened a new pull request, #22356: URL: https://github.com/apache/datafusion/pull/22356
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> POC for https://github.com/apache/datafusion/issues/22355 ## Rationale for this change <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> This optimization only targets a specific type of window functions: - Fixed `ROWS` window frame - Regular aggregate function See https://github.com/apache/datafusion/issues/22355 for the idea. ### Benchmark In datafusion-cli: ```sql create external table lineitem stored as parquet location '/Users/yongting/Code/datafusion/benchmarks/data/tpch_sf10/lineitem' with order (l_orderkey asc); -- PR only config set datafusion.optimizer.prefer_window_agg_exec=true; -- Q1: Single global partition, no sort, low scanning overhead SELECT v1, avg(v1) OVER ( ORDER BY v1 ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING ) AS moving_avg FROM generate_series(1000000000) AS t1(v1); -- Q2: Single global partition, window expr matches parquet existing order SELECT l_orderkey, avg(l_partkey) OVER ( ORDER BY l_orderkey ROWS BETWEEN 1000 PRECEDING AND 1000 FOLLOWING ) AS moving_avg FROM lineitem; -- Q3: 3 partitions SELECT l_orderkey, avg(l_partkey) OVER ( PARTITION BY l_returnflag ORDER BY l_orderkey ROWS BETWEEN 100 PRECEDING AND CURRENT ROW ) AS moving_avg FROM lineitem; -- Q4: 100k partitions SELECT l_orderkey, avg(l_partkey) OVER ( PARTITION BY l_suppkey ORDER BY l_orderkey ROWS BETWEEN 3 PRECEDING AND 3 FOLLOWING ) AS moving_avg FROM lineitem; ``` Result ``` | Query | PR | Main | Speedup | |-------|------|------|----------| | Q1 | 1.40 | 79 | 56.43x | | Q2 | 0.99 | 5.44 | 5.49x | | Q3 | 2.66 | 5.15 | 1.94x | | Q4 | 1.08 | 1.55 | 1.44x | ``` ## What changes are included in this PR? <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> ## Are these changes tested? <!-- We typically require tests for all PRs in order to: 1. Prevent the code from being accidentally broken by subsequent changes 2. Serve as another way to document the expected behavior of the code If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? --> ## Are there any user-facing changes? <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!-- If there are any breaking changes to public APIs, please add the `api change` label. --> -- 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]
