You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Michael Alexeev <mi...@gmail.com> on 2017/07/06 22:23:11 UTC

Multiple transformations from a single match

Hi All,

Is it possible to generate multiple transformations from a single rule
match by calling RelOptRuleCall.transformTo multiple times with
different RelNode from withing the onMatch call?

My use case is that I have a table with multiple indexes defined and
depending on a filter expression I need to pick the best index available
based on an index scan cost. I have a custom FilterScanMergeRule that
should transform an original Filter/LogicalScan pair into multiple
IndexScan RelNodes but I am not sure whether this is the right way to go.

Thanks,
Mike

Re: Multiple transformations from a single match

Posted by Michael Alexeev <mi...@gmail.com>.
Julian,

We use the VolcanoPlanner so should be fine there.

I am still facing an issue here most likely because I am doing something
wrong but can't figure it out.

Let say I have a table with a couple indexes defined and a select with
ORDER BY clause with the sort order that matches the order guaranteed by
one of the indexes but not the other one.

My initial tree is something like that
LogicalScan->LogicalFilter->LogicalSort

and I have a rule that matches LogicalFilter->LogicalSort and converts it
into multiple IndexScan nodes (one per suitable index). The second rule
matches the IndexScan-> LogicalScan pair only if sort and index collations
are compatible and transforms it into a single IndexScan RelNode.

And I can see that the first rule creates two IndexScan nodes and the
second rule fires only once for the  IndexScan node with the correct index
and my final tree is reduced to a single IndexScan node as expected but it
is the IndexScan node that happens to be created by the last transformTo
call within the first rule and not necessarily the one that was matched by
the IndexScan-> LogicalScan rule.

Any ideas what might be the culprit?

Mike



On Thu, Jul 6, 2017 at 6:36 PM, Julian Hyde <jh...@apache.org> wrote:

> Yes, you can call call.transformTo 0, 1 or more times from within
> RelOptRule.onMatch.
>
> All of the successors are deemed to be equivalent to the top RelNode
> matched by the rule, and VolcanoPlanner will use cost to pick the best.
>
> I’m not quite sure what happens if you call such a rule from within
> HepPlanner.
>
> > On Jul 6, 2017, at 3:23 PM, Michael Alexeev <mi...@gmail.com>
> wrote:
> >
> > Hi All,
> >
> > Is it possible to generate multiple transformations from a single rule
> > match by calling RelOptRuleCall.transformTo multiple times with
> > different RelNode from withing the onMatch call?
> >
> > My use case is that I have a table with multiple indexes defined and
> > depending on a filter expression I need to pick the best index available
> > based on an index scan cost. I have a custom FilterScanMergeRule that
> > should transform an original Filter/LogicalScan pair into multiple
> > IndexScan RelNodes but I am not sure whether this is the right way to go.
> >
> > Thanks,
> > Mike
>
>

Re: Multiple transformations from a single match

Posted by Julian Hyde <jh...@apache.org>.
Yes, you can call call.transformTo 0, 1 or more times from within RelOptRule.onMatch.

All of the successors are deemed to be equivalent to the top RelNode matched by the rule, and VolcanoPlanner will use cost to pick the best.

I’m not quite sure what happens if you call such a rule from within HepPlanner.

> On Jul 6, 2017, at 3:23 PM, Michael Alexeev <mi...@gmail.com> wrote:
> 
> Hi All,
> 
> Is it possible to generate multiple transformations from a single rule
> match by calling RelOptRuleCall.transformTo multiple times with
> different RelNode from withing the onMatch call?
> 
> My use case is that I have a table with multiple indexes defined and
> depending on a filter expression I need to pick the best index available
> based on an index scan cost. I have a custom FilterScanMergeRule that
> should transform an original Filter/LogicalScan pair into multiple
> IndexScan RelNodes but I am not sure whether this is the right way to go.
> 
> Thanks,
> Mike