Class HepPlanner

    • Field Detail

      • mainProgram

        private final HepProgram mainProgram
      • currentProgram

        private HepProgram currentProgram
      • requestedRootTraits

        private RelTraitSet requestedRootTraits
      • allRules

        private final java.util.Set<RelOptRule> allRules
      • nTransformations

        private int nTransformations
      • graphSizeLastGC

        private int graphSizeLastGC
      • nTransformationsLastGC

        private int nTransformationsLastGC
      • noDag

        private final boolean noDag
      • graph

        private final DirectedGraph<HepRelVertex,​DefaultEdge> graph
        Query graph, with edges directed from parent to child. This is a single-rooted DAG, possibly with additional roots corresponding to discarded plan fragments which remain to be garbage-collected.
    • Constructor Detail

      • HepPlanner

        public HepPlanner​(HepProgram program)
        Creates a new HepPlanner that allows DAG.
        Parameters:
        program - program controlling rule application
      • HepPlanner

        public HepPlanner​(HepProgram program,
                          Context context)
        Creates a new HepPlanner that allows DAG.
        Parameters:
        program - program controlling rule application
        context - to carry while planning
      • HepPlanner

        public HepPlanner​(HepProgram program,
                          Context context,
                          boolean noDag,
                          Function2<RelNode,​RelNode,​java.lang.Void> onCopyHook,
                          RelOptCostFactory costFactory)
        Creates a new HepPlanner with the option to keep the graph a tree (noDag = true) or allow DAG (noDag = false).
        Parameters:
        noDag - If false, create shared nodes if expressions are identical
        program - Program controlling rule application
        onCopyHook - Function to call when a node is copied
    • Method Detail

      • setRoot

        public void setRoot​(RelNode rel)
        Description copied from interface: RelOptPlanner
        Sets the root node of this query.
        Parameters:
        rel - Relational expression
      • getRoot

        public RelNode getRoot()
        Description copied from interface: RelOptPlanner
        Returns the root node of this query.
        Returns:
        Root node
      • getRules

        public java.util.List<RelOptRule> getRules()
        Description copied from interface: RelOptPlanner
        Returns the list of all registered rules.
      • addRule

        public boolean addRule​(RelOptRule rule)
        Description copied from interface: RelOptPlanner
        Registers a rule.

        If the rule has already been registered, does nothing. This method determines if the given rule is a ConverterRule and pass the ConverterRule to all registered RelTraitDef instances.

        Returns:
        whether the rule was added, as per Collection.add(E)
      • removeRule

        public boolean removeRule​(RelOptRule rule)
        Description copied from interface: RelOptPlanner
        Removes a rule.
        Returns:
        true if the rule was present, as per Collection.remove(Object)
      • changeTraits

        public RelNode changeTraits​(RelNode rel,
                                    RelTraitSet toTraits)
        Description copied from interface: RelOptPlanner
        Changes a relational expression to an equivalent one with a different set of traits.
        Parameters:
        rel - Relational expression (may or may not have been registered; must not have the desired traits)
        toTraits - Trait set to convert the relational expression to
        Returns:
        Relational expression with desired traits. Never null, but may be abstract
      • findBestExp

        public RelNode findBestExp()
        Description copied from interface: RelOptPlanner
        Finds the most efficient expression to implement this query.
      • executeProgram

        private void executeProgram​(HepProgram program)
      • skippingGroup

        private boolean skippingGroup()
      • depthFirstApply

        private int depthFirstApply​(java.util.Iterator<HepRelVertex> iter,
                                    java.util.Collection<RelOptRule> rules,
                                    boolean forceConversions,
                                    int nMatches)
      • applyRules

        private void applyRules​(java.util.Collection<RelOptRule> rules,
                                boolean forceConversions)
      • belongsToDag

        private boolean belongsToDag​(HepRelVertex vertex)
        Returns whether the vertex is valid.
      • getVertexParents

        private java.util.List<HepRelVertex> getVertexParents​(HepRelVertex vertex)
        Retrieves the parent vertices of a vertex. If a vertex appears multiple times as an input into a parent, then that counts as multiple parents, one per input reference.
        Parameters:
        vertex - the vertex
        Returns:
        the list of parents for the vertex
      • register

        public RelNode register​(RelNode rel,
                                RelNode equivRel)
        Description copied from interface: RelOptPlanner
        Registers a relational expression in the expression bank.

        After it has been registered, you may not modify it.

        The expression must not already have been registered. If you are not sure whether it has been registered, call RelOptPlanner.ensureRegistered(RelNode, RelNode).

        Parameters:
        rel - Relational expression to register (must not already be registered)
        equivRel - Relational expression it is equivalent to (may be null)
        Returns:
        the same expression, or an equivalent existing expression
      • ensureRegistered

        public RelNode ensureRegistered​(RelNode rel,
                                        RelNode equivRel)
        Description copied from interface: RelOptPlanner
        Registers a relational expression if it is not already registered.

        If equivRel is specified, rel is placed in the same equivalence set. It is OK if equivRel has different traits; rel will end up in a different subset of the same set.

        It is OK if rel is a subset.

        Parameters:
        rel - Relational expression to register
        equivRel - Relational expression it is equivalent to (may be null)
        Returns:
        Registered relational expression
      • isRegistered

        public boolean isRegistered​(RelNode rel)
        Description copied from interface: RelOptPlanner
        Determines whether a relational expression has been registered.
        Parameters:
        rel - expression to test
        Returns:
        whether rel has been registered
      • collectGarbage

        private void collectGarbage()
      • assertNoCycles

        private void assertNoCycles()
      • dumpGraph

        private void dumpGraph()
      • registerMetadataProviders

        public void registerMetadataProviders​(java.util.List<RelMetadataProvider> list)
        Description copied from interface: RelOptPlanner
        Gives this planner a chance to register one or more RelMetadataProviders in the chain which will be used to answer metadata queries.

        Planners which use their own relational expressions internally to represent concepts such as equivalence classes will generally need to supply corresponding metadata providers.

        Specified by:
        registerMetadataProviders in interface RelOptPlanner
        Overrides:
        registerMetadataProviders in class AbstractRelOptPlanner
        Parameters:
        list - receives planner's custom providers, if any
      • addMaterialization

        public void addMaterialization​(RelOptMaterialization materialization)
        Description copied from interface: RelOptPlanner
        Defines a pair of relational expressions that are equivalent.

        Typically tableRel is a LogicalTableScan representing a table that is a materialized view and queryRel is the SQL expression that populates that view. The intention is that tableRel is cheaper to evaluate and therefore if the query being optimized uses (or can be rewritten to use) queryRel as a sub-expression then it can be optimized by using tableRel instead.

        Specified by:
        addMaterialization in interface RelOptPlanner
        Overrides:
        addMaterialization in class AbstractRelOptPlanner