You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Alexander Reshetov <al...@gmail.com> on 2015/11/06 10:50:20 UTC

EnumWindow with optimization regarding sorting

Hello,

For my data container it would be useful to add optimization in
EnumWindow to avoid reordering in cases when collations are matched.

Would be this optimization useful for others? While I'm going to
implement it, it would be helpful to know how this optimization
should be done.

It would be easier to add patch to EnumWindow.
Or should it be separate rule? Something like EnumWindowOpt and
EnumWindowRuleOpt.

Re: EnumWindow with optimization regarding sorting

Posted by Julian Hyde <jh...@apache.org>.
Alexander,

Nice idea!

I would create a list of booleans as a field in EnumerableWindow that
says whether each of the groups in an EnumerableWindow is already
sorted. If some or all of them are already sorted the cost model would
return a lower cost, and the code generator would generate code that
exploits the sorting. Remember that an EnumerableWindow is allowed to
have multiple groups.

The create method should set those booleans based on the collation of
the input. But in future you might want to add a rule to set them
explicitly.

The next place to go is to log a good jira case. Put in it some
motivating examples: (a) a simple query that would benefit from this
optimization. Also think of some more advanced queries with (b)
multiple windows sorted over the same as the input but with different
partition by or sorted over just a leading edge of the input sort key,
(c) multiple windows some of which are sorted on a different key
altogether.

Julian



On Fri, Nov 6, 2015 at 1:50 AM, Alexander Reshetov
<al...@gmail.com> wrote:
> Hello,
>
> For my data container it would be useful to add optimization in
> EnumWindow to avoid reordering in cases when collations are matched.
>
> Would be this optimization useful for others? While I'm going to
> implement it, it would be helpful to know how this optimization
> should be done.
>
> It would be easier to add patch to EnumWindow.
> Or should it be separate rule? Something like EnumWindowOpt and
> EnumWindowRuleOpt.

Re: EnumWindow with optimization regarding sorting

Posted by Vladimir Sitnikov <si...@gmail.com>.
Hi,

> EnumWindow to avoid reordering in cases when collations are matched.

This sounds interesting.
I wonder how that would trade execution time vs planning time.
The question is how to decide the best permutation of the window calculations.

Vladimir