Michael Braun created CALCITE-7794:
--------------------------------------

             Summary: Reduce the work HepPlanner does per rule application 
attempt
                 Key: CALCITE-7794
                 URL: https://issues.apache.org/jira/browse/CALCITE-7794
             Project: Calcite
          Issue Type: Improvement
            Reporter: Michael Braun


HepPlanner tries every rule in a collection against every vertex, so missed 
attempts
can greatly outnumber matches.

On every attempt, {{applyRule}} tests {{graph.vertexSet().contains(vertex)}}. 
Both
call sites try every rule against the same vertex in a loop that only exits 
early on
a match, so membership cannot change within it: 100 rules means 100 set lookups
where one would do.

On attempts that cannot match -- the large majority -- {{applyRule}} also 
allocates
{{bindings}} and {{nodeChildren}} before calling {{matchOperands}}, which 
rejects on
its first statement, and runs the {{ConverterRule}} and {{CommonRelSubExprRule}}
branches, traversing a vertex's parents, before the operand is tested.

Proposed: move the membership test to the two callers, which need it once per 
vertex;
return early for an empty rule collection; and test the operand first in
{{applyRule}}, splitting {{matchOperands}} into a thin entry point making that 
test
and a body assuming it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to