Tim, What you are describing is intended behavior. The whole point of a genuine cost-based optimizer is that rather than having to choose whether to take road A or road B, it can take both routes, and see which is the shortest.
The Volcano planning algorithm does not consider cost when it has identified that it can apply a rule; it just fires the rule. Rules don’t modify relational expressions - they create new ones, perhaps sharing some of the same inputs as the old expression - so it all works out. So, Zain is correct. You *do* want the planner to produce both ProjectA and ProjectB. You just need to adjust your cost model so that it chooses the right one. Turning on tracing[1] may help. Julian [1] https://calcite.apache.org/docs/howto.html#tracing <https://calcite.apache.org/docs/howto.html#tracing> > On Aug 14, 2017, at 2:54 PM, Timothy Farkas <[email protected]> wrote: > > > Thanks Zain, > > I'll take a look at setting the cost. > > > ________________________________ > From: Zain Humayun <[email protected]> > Sent: Monday, August 14, 2017 12:45:17 PM > To: [email protected] > Subject: Re: Multiple Rules Matching LogicalProject > > I'm not too sure how the planner deals with tie breakers between two plans, > but if you prefer ProjectB to ProjectA, then giving ProjectB a lower cost > than ProjectA should result in the planner choosing ProjectB. > > Zain. > > On Mon, Aug 14, 2017 at 12:39 PM, Timothy Farkas <[email protected]> wrote: > >> Hi All, >> >> I'm new to Calcite, so this may be a silly question. How can I control the >> behavior of the VolcanoPlanner when two rules match the same relation node >> and transform it? I am seeing an issue where I have two Rules (RuleA and >> RuleB) which match a LogicalProject relation node. When RuleA matches it >> transforms the relational node to a ProjectA node, and when RuleB matches >> it transforms the relational node to a ProjectB node. However, the output >> of the planner always has ProjectA nodes and never has ProjectB nodes. How >> can I tell the planner than I prefer ProjectB nodes over ProjectA nodes? >> >> I am using the Apache Drill version of Calcite which is based on Calcite >> 1.4 >> >> Thanks, >> Tim >>
