/** * Disjunctions (OR) are the union of candidates across all subexpressions * so we add all the counts of the child nodes. Notice that we annotate the * child node with a recursive call. * * @param node the OR branch node * @return the scan count on the OR node * @throws NamingException if there is an error */ private BigInteger getDisjunctionScan( BranchNode node ) throws NamingException { ArrayList children = node.getChildren(); BigInteger total = BigInteger.ZERO; for ( int ii = 0; ii < children.size(); ii++ ) { ExprNode child = ( ExprNode ) children.get( ii ); annotate( child ); total = total.add( ( BigInteger ) child.get( "count" ) ); } // we don't want values bigger than Integer.MAX_VALUE if ( total.compareTo( MAX ) > 0 ) { total = MAX; } return total; }
/** * ANDs or Conjunctions take the count of the smallest child as their count. * This is the best that a conjunction can do and should be used rather than * the worst case. Notice that we annotate the child node with a recursive * call before accessing its count parameter making the chain recursion * depth first. * * @param node a AND (Conjunction) BranchNode * @return the calculated scan count * @throws NamingException if there is an error */ private BigInteger getConjunctionScan( BranchNode node ) throws NamingException { BigInteger count = MAX; ArrayList children = node.getChildren(); for ( int ii = 0; ii < children.size(); ii++ ) { ExprNode child = ( ExprNode ) children.get( ii ); annotate( child ); count = ( ( BigInteger ) child.get( "count" ) ).min( count ); } return count; }
value = ( ( BigInteger ) child.get( "count" ) ).intValue(); minValue = Math.min( minValue, value );