The first place I would recommend looking is how you are costing projects and filters. If the costing function for these relational operators does not take into account the complexity of the expressions contained, possibly by only considering the number of top level expressions, the reduced plan would not be exposing with a lower cost that it is preferable to the original plan.
You can see here that the default project Rel appears to only consider the number of expressions and the input size when computing costs [1]. You probably want to have some visitor that will walk each of the expressions to come up with a more accurate cost. I don't know if this functionality is provided somewhere else in calcite. [1] - https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/core/Project.java#L216 Jason Altekruse Software Engineer at Dremio Apache Drill Committer On Tue, Jun 14, 2016 at 9:58 PM, Jark Wu <[email protected]> wrote: > Hi all, > > I want to reduce the constant expression in sql, replacing them with a > corresponding constant. > > For instance I have a sql query : > > SELECT a, b, c+(2+3) as d FROM Orders WHERE b > (1+4) > > > I want some planner rules can optimize this query to reduce the constant > exprssions: > > SELECT a, b, c+5 as d FROM Orders WHERE b > 5 > > > It seems that ReduceExpressionsRule is what I need, and I tried it many > times but it didn’t work. > > Is the way I used wrong ? Or there is any exist rule to use, or I have to > implement one myself ? > > > > - Jark Wu > >
