[MDEV-9848] Window functions: reuse sorting and/or scanning Created: 2016-03-31  Updated: 2016-04-14

Status: Open
Project: MariaDB Server
Component/s: Optimizer - Window functions
Fix Version/s: None

Type: Task Priority: Major
Reporter: Sergei Petrunia Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None

Issue Links:
PartOf
is part of MDEV-6115 window functions as in the SQL standard Closed

 Description   

The standard says this:

In general, two <window function>s are computed independently, each one
performing its own sort of its data, even if they use the same data and the same <sort specification list>
...
Nevertheless, the user may desire that two <window function>s be computed using the same ordering
...
Two <window function>s are computed using the same (possibly non-deterministic) window ordering of the
rows if any of the following are true:

  • (3 long clauses)

This is a good reason to implement an optimization:

if window functions W1 and W2 use compatible sortings, 
  they must share the filesort() call

Let's call the above *filesort sharing*.

The second step would be to share the "scan through the filesort result and compute the window function" step. Sharing the scan between window functions ought to give a speedup, because

  • we can compute values of all window functions and call h->update_row once (instead of many times)
  • It is more cache-friendly to do things in one pass, not in many.

A question: should the scan be shared across all window functions or only those that have identical PARTITION BY clause?



 Comments   
Comment by Sergei Petrunia [ 2016-04-06 ]

filesort sharing is supposed to work now, except that there is a known bug: MDEV-9877

Generated at Thu Feb 08 07:37:47 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.