def includePhysicalOperatorJoin(a, l, r): join_variables = l.vars & r.vars all_variables = l.vars | r.vars if a: if l.allTriplesLowSelectivity() or (len(join_variables) == 0): c = False else: lsc = l.getCardinality() c = (lsc <= 30) if c and not r.allTriplesLowSelectivity(): c = c and (lsc <= 0.3 * r.getCardinality()) if (l.constantPercentage() >= 0.5) and (len(join_variables) > 0) and c: n = TreePlan(NestedHashJoin(join_variables), all_variables, l, r) else: n = TreePlan(Xgjoin(join_variables), all_variables, l, r) else: n = TreePlan(HashJoin(join_variables), all_variables, l, r) return n
def includePhysicalOperatorJoin(a, wc, l, r): join_variables = l.vars & r.vars all_variables = l.vars | r.vars noInstantiatedLeftStar = False noInstantiatedRightStar = False lowSelectivityLeft = l.allTriplesLowSelectivity() lowSelectivityRight = r.allTriplesLowSelectivity() #print wc #print join_variables #print l.allTriplesLowSelectivity() if a: #if lowSelectivityLeft or (len(join_variables) == 0): # c = False #elif wc: # c = True #else: # lsc = l.getCardinality() # c = (lsc <= 30) # if c and not lowSelectivityRight: # c = c and (lsc <= 0.3*r.getCardinality()) dependent_join = False #if (noInstantiatedRightStar) or ((not wc) and (l.constantPercentage() >= 0.5) and (len(join_variables) > 0) and c): # Case 1: left operator is highly selective and right operator is low selective if not(lowSelectivityLeft) and lowSelectivityRight and not(isinstance(r, TreePlan)): n = TreePlan(NestedHashJoin(join_variables), all_variables, l, r) dependent_join = True #print "Planner CASE 1: nested loop", type(r) # Case 2: left operator is low selective and right operator is highly selective elif lowSelectivityLeft and not(lowSelectivityRight) and not(isinstance(l, TreePlan)): n = TreePlan(NestedHashJoin(join_variables), all_variables, r, l) dependent_join = True #print "Planner CASE 2: nested loop swapping plan", type(r) elif not(lowSelectivityLeft) and lowSelectivityRight and (not(isinstance(l, TreePlan)) or not(l.operator.__class__.__name__ == "NestedHashJoinFilter" )) and (not(isinstance(r,TreePlan)) or not(r.operator.__class__.__name__ == "Xgjoin" or r.operator.__class__.__name__ == "NestedHashJoinFilter")): if (isinstance(r,TreePlan) and (set(l.vars) & set(r.operator.vars_left) !=set([])) and (set(l.vars) & set(r.operator.vars_right) !=set([]))): n = TreePlan(NestedHashJoin(join_variables), all_variables, l, r) dependent_join = True elif (isinstance(l,TreePlan) and (set(r.vars)& set(l.operator.vars_left) !=set([])) and (set(r.vars)& set(l.operator.vars_right) !=set([]))): n = TreePlan(NestedHashJoin(join_variables), all_variables, l, r) dependent_join = True else: n = TreePlan(Xgjoin(join_variables), all_variables, l, r) #print "Planner case 2.5", type(r) # Case 3: both operators are low selective else: n = TreePlan(Xgjoin(join_variables), all_variables, l, r) #print "Planner CASE 3: xgjoin" if isinstance(n.left, IndependentOperator) and isinstance(n.left.tree, Leaf): if (n.left.constantPercentage() <= 0.5) and not(n.left.tree.service.allTriplesGeneral()): n.left.tree.service.limit = 10000 # Fixed value, this can be learnt in the future #print "modifying limit left ..." else: n = TreePlan(HashJoin(join_variables), all_variables, l, r) if isinstance(n.right, IndependentOperator) and isinstance(n.right.tree, Leaf): if not(dependent_join): if (n.right.constantPercentage() <= 0.5) and not(n.right.tree.service.allTriplesGeneral()): n.right.tree.service.limit = 10000 # Fixed value, this can be learnt in the future #print "modifying limit right ..." else: new_constants = 0 for v in join_variables: new_constants = new_constants + n.right.query.show().count(v) if ((n.right.constantNumber() + new_constants)/n.right.places() <= 0.5) and not(n.right.tree.service.allTriplesGeneral()): n.right.tree.service.limit = 10000 # Fixed value, this can be learnt in the future #print "modifying limit right ..." return n