Beispiel #1
0
def decomposition_to_plan(decomposition):

    access_plans = []
    for tp in decomposition:
        access_plans.append(LogicalPlan(tp))

    todo = sorted(access_plans, key=lambda x: x.cardinality)
    plan = todo[0]
    todo.remove(plan)

    while len(todo):
        for i in range(len(todo)):
            if len(plan.variables.intersection(todo[i].variables)) > 0:
                plan = LogicalPlan(plan, todo[i],
                                   get_physical_operator(plan, todo[i]))
                plan.compute_cardinality(cardinality_estimation)
                todo.remove(todo[i])
                break
        else:
            # In case we cannot find another join able triple pattern
            next_tp = todo[0]
            plan = LogicalPlan(plan, next_tp,
                               get_physical_operator(plan, next_tp))
            plan.compute_cardinality(cardinality_estimation)
            todo.remove(next_tp)
    return plan
Beispiel #2
0
    def optimize_subquery(self, subquery, filters):

        plans = []
        for tp_combination in product(*subquery):

            access_plans = []
            for tp in tp_combination:
                access_plans.append(LogicalPlan(tp))

            todo = sorted(access_plans, key=lambda x: x.cardinality)
            plan = todo[0]
            todo.remove(plan)

            while len(todo):
                for i in range(len(todo)):
                    if len(plan.variables.intersection(todo[i].variables)) > 0:
                        plan = LogicalPlan(
                            plan, todo[i],
                            self.get_physical_join_operator(plan, todo[i]))
                        plan.compute_cardinality(self.cardinality_estimation)
                        todo.remove(todo[i])
                        break
                else:
                    # In case we cannot find another join able triple pattern
                    next_tp = todo[0]
                    plan = LogicalPlan(
                        plan, next_tp,
                        self.get_physical_join_operator(plan, next_tp))
                    plan.compute_cardinality(self.cardinality_estimation)
                    todo.remove(next_tp)

            plan.filters = filters
            plans.append(plan)
        if len(plans) == 0:
            return None
        plan = self.union_subplans(plans)
        return plan
Beispiel #3
0
def decomposition_to_plan(decomposition):

    leafs = {}

    for subquery, source, cardinality in decomposition:

        if isinstance(subquery, TriplePattern):
            if subquery in leafs.keys():
                leafs[subquery].sources[source] = cardinality
                leafs[subquery].cardinality += cardinality
            else:
                new_triple_pattern = TriplePattern(
                    subquery[0],
                    subquery[1],
                    subquery[2],
                    sources={source: cardinality})
                new_triple_pattern.cardinality = cardinality
                leafs[subquery] = new_triple_pattern
        elif isinstance(subquery, BGP):
            if subquery in leafs.keys():
                for tp in leafs[subquery]:
                    for bgp_tp in subquery:
                        if tp == bgp_tp:
                            tp.sources[source] = bgp_tp.cardinality
                leafs[subquery].cardinality += cardinality

            else:
                new_tps = []
                for triple_pattern in subquery:
                    new_triple_pattern = TriplePattern(
                        triple_pattern[0],
                        triple_pattern[1],
                        triple_pattern[2],
                        sources={source: cardinality})
                    new_tps.append(new_triple_pattern)
                new_bgp = BGP(new_tps)
                new_bgp.cardinality = cardinality
                leafs[subquery] = new_bgp

    access_plans = []

    for tp in leafs.values():
        access_plans.append(LogicalPlan(tp))

    todo = sorted(access_plans, key=lambda x: x.cardinality)
    plan = todo[0]
    todo.remove(plan)

    while len(todo):
        for i in range(len(todo)):
            if len(plan.variables.intersection(todo[i].variables)) > 0:
                plan = LogicalPlan(plan, todo[i],
                                   get_physical_operator(plan, todo[i]))
                plan.compute_cardinality(cardinality_estimation)
                todo.remove(todo[i])
                break
        else:
            # In case we cannot find another join able triple pattern
            next_tp = todo[0]
            plan = LogicalPlan(plan, next_tp,
                               get_physical_operator(plan, next_tp))
            plan.compute_cardinality(cardinality_estimation)
            todo.remove(next_tp)

    return plan