Removes the not used input parameter from PlanBuilder.build_for_graph_pattern

pull/10/head
Tpt 5 years ago
parent 3888f7ccdd
commit 2d9d33c8be
  1. 35
      lib/src/sparql/eval.rs
  2. 6
      lib/src/sparql/plan.rs
  3. 64
      lib/src/sparql/plan_builder.rs

@ -308,13 +308,12 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
}
}))
}
PlanNode::Union { entry, children } => Box::new(UnionIterator {
PlanNode::Union { children } => Box::new(UnionIterator {
eval: self,
children_plan: &children,
input_iter: self.eval_plan(&*entry, from),
current_input: Vec::default(),
plans: &children,
input: from,
current_iterator: Box::new(empty()),
current_child: children.len(),
current_plan: 0,
}),
PlanNode::Extend {
child,
@ -2206,11 +2205,10 @@ impl<'a, S: StoreConnection> Iterator for BadLeftJoinIterator<'a, S> {
struct UnionIterator<'a, S: StoreConnection + 'a> {
eval: &'a SimpleEvaluator<S>,
children_plan: &'a [PlanNode],
input_iter: EncodedTuplesIterator<'a>,
current_input: EncodedTuple,
plans: &'a [PlanNode],
input: EncodedTuple,
current_iterator: EncodedTuplesIterator<'a>,
current_child: usize,
current_plan: usize,
}
impl<'a, S: StoreConnection> Iterator for UnionIterator<'a, S> {
@ -2221,20 +2219,13 @@ impl<'a, S: StoreConnection> Iterator for UnionIterator<'a, S> {
if let Some(tuple) = self.current_iterator.next() {
return Some(tuple);
}
if self.current_child == self.children_plan.len() {
match self.input_iter.next()? {
Ok(input_tuple) => {
self.current_input = input_tuple;
self.current_child = 0;
}
Err(error) => return Some(Err(error)),
}
if self.current_plan >= self.plans.len() {
return None;
}
self.current_iterator = self.eval.eval_plan(
&self.children_plan[self.current_child],
self.current_input.clone(),
);
self.current_child += 1;
self.current_iterator = self
.eval
.eval_plan(&self.plans[self.current_plan], self.input.clone());
self.current_plan += 1;
}
}
}

@ -36,7 +36,6 @@ pub enum PlanNode {
expression: PlanExpression,
},
Union {
entry: Box<PlanNode>,
children: Vec<PlanNode>,
},
LeftJoin {
@ -137,9 +136,8 @@ impl PlanNode {
PlanNode::Filter { child, expression } => {
child.add_variables(set);
expression.add_variables(set);
} //TODO: condition vars
PlanNode::Union { entry, children } => {
entry.add_variables(set);
}
PlanNode::Union { children } => {
for child in children {
child.add_variables(set);
}

@ -19,7 +19,6 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
let mut variables = Vec::default();
let plan = PlanBuilder { store }.build_for_graph_pattern(
pattern,
PlanNode::Init,
&mut variables,
PatternValue::Constant(ENCODED_DEFAULT_GRAPH),
)?;
@ -37,25 +36,18 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
fn build_for_graph_pattern(
&self,
pattern: &GraphPattern,
input: PlanNode, //TODO: is this parameter really useful?
variables: &mut Vec<Variable>,
graph_name: PatternValue,
) -> Result<PlanNode> {
Ok(match pattern {
GraphPattern::BGP(p) => self.build_for_bgp(p, input, variables, graph_name)?,
GraphPattern::BGP(p) => self.build_for_bgp(p, variables, graph_name)?,
GraphPattern::Join(a, b) => PlanNode::Join {
left: Box::new(self.build_for_graph_pattern(
a,
input.clone(),
variables,
graph_name,
)?),
right: Box::new(self.build_for_graph_pattern(b, input, variables, graph_name)?),
left: Box::new(self.build_for_graph_pattern(a, variables, graph_name)?),
right: Box::new(self.build_for_graph_pattern(b, variables, graph_name)?),
},
GraphPattern::LeftJoin(a, b, e) => {
let left = self.build_for_graph_pattern(a, input, variables, graph_name)?;
let right =
self.build_for_graph_pattern(b, PlanNode::Init, variables, graph_name)?;
let left = self.build_for_graph_pattern(a, variables, graph_name)?;
let right = self.build_for_graph_pattern(b, variables, graph_name)?;
//We add the extra filter if needed
let right = if *e == Expression::from(Literal::from(true)) {
right
@ -78,7 +70,7 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
}
}
GraphPattern::Filter(e, p) => PlanNode::Filter {
child: Box::new(self.build_for_graph_pattern(p, input, variables, graph_name)?),
child: Box::new(self.build_for_graph_pattern(p, variables, graph_name)?),
expression: self.build_for_expression(e, variables, graph_name)?,
},
GraphPattern::Union(a, b) => {
@ -92,36 +84,25 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
stack.push(a);
stack.push(b);
}
Some(p) => children.push(self.build_for_graph_pattern(
p,
PlanNode::Init,
variables,
graph_name,
)?),
Some(p) => {
children.push(self.build_for_graph_pattern(p, variables, graph_name)?)
}
}
}
PlanNode::Union {
entry: Box::new(input),
children,
}
PlanNode::Union { children }
}
GraphPattern::Graph(g, p) => {
let graph_name = self.pattern_value_from_named_node_or_variable(g, variables)?;
self.build_for_graph_pattern(p, input, variables, graph_name)?
self.build_for_graph_pattern(p, variables, graph_name)?
}
GraphPattern::Extend(p, v, e) => PlanNode::Extend {
child: Box::new(self.build_for_graph_pattern(p, input, variables, graph_name)?),
child: Box::new(self.build_for_graph_pattern(p, variables, graph_name)?),
position: variable_key(variables, &v),
expression: self.build_for_expression(e, variables, graph_name)?,
},
GraphPattern::Minus(a, b) => PlanNode::AntiJoin {
left: Box::new(self.build_for_graph_pattern(
a,
input.clone(),
variables,
graph_name,
)?),
right: Box::new(self.build_for_graph_pattern(b, input, variables, graph_name)?),
left: Box::new(self.build_for_graph_pattern(a, variables, graph_name)?),
right: Box::new(self.build_for_graph_pattern(b, variables, graph_name)?),
},
GraphPattern::Service(_n, _p, _s) => {
return Err(format_err!(
@ -136,7 +117,6 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
PlanNode::Aggregate {
child: Box::new(self.build_for_graph_pattern(
p,
input,
&mut inner_variables,
inner_graph_name,
)?),
@ -171,7 +151,7 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
})
.collect();
PlanNode::Sort {
child: Box::new(self.build_for_graph_pattern(l, input, variables, graph_name)?),
child: Box::new(self.build_for_graph_pattern(l, variables, graph_name)?),
by: by?,
}
}
@ -182,7 +162,6 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
PlanNode::Project {
child: Box::new(self.build_for_graph_pattern(
l,
input,
&mut inner_variables,
inner_graph_name,
)?),
@ -196,13 +175,11 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
}
}
GraphPattern::Distinct(l) => PlanNode::HashDeduplicate {
child: Box::new(self.build_for_graph_pattern(l, input, variables, graph_name)?),
child: Box::new(self.build_for_graph_pattern(l, variables, graph_name)?),
},
GraphPattern::Reduced(l) => {
self.build_for_graph_pattern(l, input, variables, graph_name)?
}
GraphPattern::Reduced(l) => self.build_for_graph_pattern(l, variables, graph_name)?,
GraphPattern::Slice(l, start, length) => {
let mut plan = self.build_for_graph_pattern(l, input, variables, graph_name)?;
let mut plan = self.build_for_graph_pattern(l, variables, graph_name)?;
if *start > 0 {
plan = PlanNode::Skip {
child: Box::new(plan),
@ -223,11 +200,10 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
fn build_for_bgp(
&self,
p: &[TripleOrPathPattern],
input: PlanNode,
variables: &mut Vec<Variable>,
graph_name: PatternValue,
) -> Result<PlanNode> {
let mut plan = input;
let mut plan = PlanNode::Init;
for pattern in sort_bgp(p) {
plan = match pattern {
TripleOrPathPattern::Triple(pattern) => PlanNode::QuadPatternJoin {
@ -671,7 +647,7 @@ impl<'a, S: StoreConnection> PlanBuilder<'a, S> {
},
Expression::Bound(v) => PlanExpression::Bound(variable_key(variables, v)),
Expression::Exists(n) => PlanExpression::Exists(Box::new(
self.build_for_graph_pattern(n, PlanNode::Init, variables, graph_name)?,
self.build_for_graph_pattern(n, variables, graph_name)?,
)),
})
}

Loading…
Cancel
Save