mustafasrepo opened a new pull request, #4989:
URL: https://github.com/apache/arrow-datafusion/pull/4989

   # 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.
   -->
   
   Closes #4979
   
   # 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.  
   -->
   During range calculation for window frames, we can use linear search instead 
of bisect. Since we know that table is already sorted and we would progress 
only in one direction. Linear search is amortized constant (When window frame 
boundaries are static). Hence this version is more optimal than current bisect 
implementation (where search complexity is log(n)). This change decreases 
overall window range calculation complexity from `O(n*log(n))` to `O(n)`.
   
   # 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)?
   -->
   Existing tests verify window range calculation correctness. Unit tests for 
`linear_search` is also added. We also compared time elapsed during Window 
result calculation for the query
   ```sql
   SELECT SUM(a) OVER(ORDER BY a RANGE BETWEEN 10 PRECEDING AND 10 FOLLOWING) 
FROM t1;
   ```
   . Time comparison between linear and bisect version for different conditions 
can be seen in table below. 
   
   
   
   
   n_row | distinct | linear(mean) | linear(median) | bisect(mean) | 
bisect(median)
   -- | -- | -- | -- | -- | --
   100 | 10 | 1.199524ms | 772.125µs | 2.065253ms | 1.501125ms
   100 | 100_000_000 | 1.614941ms | 1.599208ms | 2.30337ms | 2.346416ms
   1000 | 10 | 4.521795ms | 4.417125ms | 10.986941ms | 10.994333ms
   1000 | 100_000_000 | 11.82327ms | 11.8265ms | 23.83402ms | 23.641541ms
   100_000 | 10 | 428.01742ms | 428.022791ms | 1.661792712s | 1.666531666s
   100_000 | 100_000_000 | 1.190898003s | 1.18136925s | 3.446534628s | 
3.446675916s
   
   
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   -->
   
   No.
   
   <!--
   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]

Reply via email to