protected long computeJoinCardinality(IJoinDimension d1,IJoinDimension d2){
  if (d1.isOptional() && d2.isOptional()) {
    return BOTH_OPTIONAL;
  }
  if (d1.isOptional() || d2.isOptional()) {
    return ONE_OPTIONAL;
  }
  final boolean sharedVars=hasSharedVars(d1,d2);
  final boolean unsharedVars=hasUnsharedVars(d1,d2);
  final long joinCardinality;
  if (sharedVars == false) {
    joinCardinality=NO_SHARED_VARS;
  }
 else {
    if (unsharedVars == false) {
      joinCardinality=Math.min(d1.getCardinality(),d2.getCardinality());
    }
 else {
      joinCardinality=Math.min(d1.getCardinality(),d2.getCardinality());
    }
  }
  return joinCardinality;
}

protected long computeJoinCardinality ( IJoinDimension d1 , IJoinDimension d2 ) { if ( d1 . isOptional ( ) && d2 . isOptional ( ) ) { return BOTH_OPTIONAL ; } if ( d1 . isOptional ( ) || d2 . isOptional ( ) ) { return ONE_OPTIONAL ; } final boolean sharedVars = hasSharedVars ( d1 , d2 ) ; final boolean unsharedVars = hasUnsharedVars ( d1 , d2 ) ; final long joinCardinality ; if ( sharedVars == false ) { joinCardinality = NO_SHARED_VARS ; } else { if ( unsharedVars == false ) { joinCardinality = Math . min ( d1 . getCardinality ( ) , d2 . getCardinality ( ) ) ; } else { joinCardinality = Math . min ( d1 . getCardinality ( ) , d2 . getCardinality ( ) ) ; } } return joinCardinality ; }
this is the secret sauce . there are three possibilities for computing the join cardinality , which we are defining as the upper - bound for solutions for a particular join . first , if there are no shared variables then the cardinality will just be the simple sum of the cardinality of each join dimension . if there are shared variables but no unshared variables , then the cardinality will be the minimum cardinality from the join dimensions . if there are shared variables but also some unshared variables , then the join cardinality will be the maximum cardinality from each join dimension . < p > any join involving an optional will have infinite cardinality , so that optionals get placed at the end .
