Exemplo n.º 1
0
def includePhysicalOperatorsOptional(left, rightList, a):

    l = left

    for right in rightList:
        
        all_variables  = left.vars | right.vars
        
        if a:
            lowSelectivityLeft = l.allTriplesLowSelectivity()
            lowSelectivityRight = right.allTriplesLowSelectivity()
            join_variables = l.vars & right.vars

            dependent_op = False
            # Case 1: left operator is highly selective and right operator is low selective
            if not(lowSelectivityLeft) and lowSelectivityRight and not(isinstance(right, TreePlan)):
                l = TreePlan(NestedHashOptional(left.vars, right.vars), all_variables, l, right)
                dependent_op = True
                #print "Planner CASE 1: nested optional"

            # Case 2: left operator is low selective and right operator is highly selective
            elif lowSelectivityLeft and not(lowSelectivityRight) and not(isinstance(right, TreePlan)):
                l = TreePlan(NestedHashOptional(left.vars, right.vars), all_variables, right, l)
                dependent_op = True
                #print "Planner CASE 2: nested loop optional swapping plan"
            elif not(lowSelectivityLeft) and lowSelectivityRight  and not(isinstance(left, TreePlan) and (left.operator.__class__.__name__ == "NestedHashJoin" or left.operator.__class__.__name__ == "Xgjoin")) and not(isinstance(right,IndependentOperator)) and not(right.operator.__class__.__name__ == "NestedHashJoin" or right.operator.__class__.__name__ == "Xgjoin") and  (right.operator.__class__.__name__ == "Xunion"):
                l = TreePlan(NestedHashOptional(left.vars, right.vars), all_variables, l, right)
                dependent_op = True
            # Case 3: both operators are low selective
            else:
                 l =  TreePlan(Xgoptional(left.vars, right.vars), all_variables, l, right)
                 #print "Planner CASE 3: xgoptional"

            
            if isinstance(l.left, IndependentOperator) and isinstance(l.left.tree, Leaf) and not(l.left.tree.service.allTriplesGeneral()):
                if (l.left.constantPercentage() <= 0.5):
                    l.left.tree.service.limit = 10000 # Fixed value, this can be learnt in the future 
                    #print "modifying limit optional left ..."

            if isinstance(l.right, IndependentOperator) and isinstance(l.right.tree, Leaf):
                if not(dependent_op):
                    if (l.right.constantPercentage() <= 0.5) and not(l.right.tree.service.allTriplesGeneral()):
                        l.right.tree.service.limit = 10000 # Fixed value, this can be learnt in the future 
                        #print "modifying limit optional right ..."
                else:
                    new_constants = 0
                    for v in join_variables:
                        new_constants = new_constants + l.right.query.show().count(v)
                    if ((l.right.constantNumber() + new_constants)/l.right.places() <= 0.5) and not(l.right.tree.service.allTriplesGeneral()):
                        l.right.tree.service.limit = 10000 # Fixed value, this can be learnt in the future
                        #print "modifying limit optional right ..."

        else:
            l = TreePlan(HashOptional(left.vars, right.vars),
                         all_variables, l, right)
    return l
Exemplo n.º 2
0
def includePhysicalOperatorsOptional(left, rightList, a):

    l = left

    for right in rightList:
        all_variables = left.vars | right.vars
        if a:
            l = TreePlan(Xgoptional(left.vars, right.vars), all_variables, l,
                         right)
        else:
            l = TreePlan(HashOptional(left.vars, right.vars), all_variables, l,
                         right)
    return l