org.modeshape.jcr.query.optimize

## Class PushSelectCriteria

- java.lang.Object
- - org.modeshape.jcr.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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static PushSelectCriteria` | `INSTANCE`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `PushSelectCriteria()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected boolean` | `atBoundary(PlanNode criteriaNode, PlanNode originatingNode)` Determine whether all of the nodes between the criteria node and its originating node are criteria (SELECT) nodes.
    `PlanNode` | `execute(QueryContext context, PlanNode plan, LinkedList<OptimizerRule> ruleStack)` Optimize the supplied plan using the supplied context, hints, and yet-to-be-run rules.
    `protected PlanNode` | `findBestChildForCriteria(PlanNode criteriaNode, PlanNode originatingNode)`
    `protected PlanNode` | `findOriginatingNode(PlanNode criteriaNode, List<PlanNode> originatingNodes)` Find the first node that has all of the same `selectors` as the supplied criteria.
    `protected boolean` | `pushDownJoinCriteria(PlanNode criteriaNode, PlanNode joinNode)` Attempt to push down criteria that applies to the JOIN as additional constraints on the JOIN itself.
    `protected boolean` | `pushTowardsOriginatingNode(PlanNode criteriaNode, PlanNode originatingNode)` Push the criteria node as close to the originating node as possible.
    `String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, 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)

      Description copied from interface: `OptimizerRule`
      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

    - #### pushDownJoinCriteria

          protected boolean pushDownJoinCriteria(PlanNode criteriaNode,
                                     PlanNode joinNode)

      Attempt to push down criteria that applies to the JOIN as additional constraints on the JOIN itself.
      Parameters:
        `criteriaNode` - the SELECT node; may not be null
        `joinNode` - the JOIN node; may not be null
      Returns:
        true if the criteria was pushed down, or false otherwise

    - #### findOriginatingNode

          protected PlanNode findOriginatingNode(PlanNode criteriaNode,
                                     List<PlanNode> originatingNodes)

      Find the first node that has all of the same `selectors` as the supplied criteria.
      Parameters:
        `criteriaNode` - the criteria
        `originatingNodes` - the list of nodes to search
      Returns:
        the first (highest) node that is uses all of the same selectors as the criteria, or null if no such node could be found

    - #### pushTowardsOriginatingNode

          protected boolean pushTowardsOriginatingNode(PlanNode criteriaNode,
                                           PlanNode originatingNode)

      Push the criteria node as close to the originating node as possible. In general, the criteria node usually ends up being moved to be a parent of the supplied originating node, except in a couple of cases:
      - There are already criteria nodes immediately above the originating node; in this case, the supplied criteria node is placed above all these existing criteria nodes.
      - The originating node is below a JOIN node that is itself below an ACCESS node; in this case, the criteria node is placed immediately above the JOIN node.
      - The originating node is below a LIMIT with a single SORT child node; in this case, the criteria node is placed immediately above the LIMIT node.
      Parameters:
        `criteriaNode` - the criteria node that is to be pushed down; may not be null
        `originatingNode` - the target node that represents the node above which the criteria node should be inserted; may not be null
      Returns:
        true if the criteria node was pushed down, or false if the criteria node could not be pushed down

    - #### findBestChildForCriteria

          protected PlanNode findBestChildForCriteria(PlanNode criteriaNode,
                                          PlanNode originatingNode)

    - #### atBoundary

          protected boolean atBoundary(PlanNode criteriaNode,
                           PlanNode originatingNode)

      Determine whether all of the nodes between the criteria node and its originating node are criteria (SELECT) nodes.
      Parameters:
        `criteriaNode` - the criteria node; may not be null
        `originatingNode` - the originating node
      Returns:
        true if all nodes between the criteria and originating nodes are SELECT nodes

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

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