org.modeshape.graph.query.optimize
Class PushSelectCriteria

java.lang.Object
  extended by org.modeshape.graph.query.optimize.PushSelectCriteria
All Implemented Interfaces:
OptimizerRule

@Immutable
public class PushSelectCriteria
extends Object
implements OptimizerRule

An optimizer rule that attempts to push the criteria nodes in a canonical plan down as far as possible.

For example, here is a single-access plan before:

          ...
           |
        PROJECT      with the list of columns being SELECTed
           |
        SELECT1
           |         One or more SELECT plan nodes that each have
        SELECT2      a single non-join constraint that are then all AND-ed
           |         together
        SELECTn
           |
        ACCESS
           |
        SOURCE
 
And after:
          ...
           |
        ACCESS
           |
        PROJECT      with the list of columns being SELECTed
           |
        SELECT1
           |         One or more SELECT plan nodes that each have
        SELECT2      a single non-join constraint that are then all AND-ed
           |         together
        SELECTn
           |
        SOURCE
 
Here is another case, where multiple SELECT nodes above a simple JOIN and where each SELECT node applies to one or more of the SOURCE nodes (via the named selectors). Each SELECT node that applies to a single selector will get pushed toward that source, but will have the same order relative to other SELECT nodes also pushed toward that SOURCE. However, this rules does not push SELECT nodes that apply to multiple selectors.

Before:

          ...
           |
        PROJECT ('s1','s2')      with the list of columns being SELECTed (from 's1' and 's2' selectors)
           |
        SELECT1 ('s1')
           |                     One or more SELECT plan nodes that each have
        SELECT2 ('s2')           a single non-join constraint that are then all AND-ed
           |                     together, and that each have the selector(s) they apply to
        SELECT3 ('s1','s2')
           |
        SELECT4 ('s1')
           |
         JOIN ('s1','s2')
        /     \
       /       \
   ACCESS     ACCESS
    ('s1')    ('s2')
     |           |
   PROJECT    PROJECT
    ('s1')    ('s2')
     |           |
   SOURCE     SOURCE
    ('s1')    ('s2')
 
And after:
          ...
           |
        PROJECT ('s1','s2')      with the list of columns being SELECTed (from 's1' and 's2' selectors)
           |
        SELECT3 ('s1','s2')      Any SELECT plan nodes that apply to multiple selectors are left above
           |                     the ACCESS nodes.
         JOIN ('s1','s2')
        /     \
       /       \
   ACCESS     ACCESS
   ('s1')     ('s2')
     |           |
  PROJECT     PROJECT
   ('s1')     ('s2')
     |           |
  SELECT1     SELECT2
   ('s1')     ('s2')
     |           |
  SELECT4     SOURCE
   ('s1')     ('s2')
     |
   SOURCE
   ('s1')
 

Also, any SELECT that applies to one side of an equi-join will be applied to both sides of the JOIN.


Field Summary
static PushSelectCriteria INSTANCE
           
 
Constructor Summary
PushSelectCriteria()
           
 
Method Summary
 PlanNode execute(QueryContext context, PlanNode plan, LinkedList<OptimizerRule> ruleStack)
          Optimize the supplied plan using the supplied context, hints, and yet-to-be-run rules.
 String toString()
          
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INSTANCE

public static final PushSelectCriteria INSTANCE
Constructor Detail

PushSelectCriteria

public PushSelectCriteria()
Method Detail

execute

public PlanNode execute(QueryContext context,
                        PlanNode plan,
                        LinkedList<OptimizerRule> ruleStack)
Optimize the supplied plan using the supplied context, hints, and yet-to-be-run rules.

Specified by:
execute in interface OptimizerRule
Parameters:
context - the context in which the query is being optimized; never null
plan - the plan to be optimized; never null
ruleStack - the stack of rules that will be run after this rule; never null
Returns:
the optimized plan; never null
See Also:
OptimizerRule.execute(org.modeshape.graph.query.QueryContext, org.modeshape.graph.query.plan.PlanNode, java.util.LinkedList)

toString

public String toString()

Overrides:
toString in class Object
See Also:
Object.toString()


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.