Removes unused Rc in PlanNode

pull/171/head
Tpt 3 years ago
parent 57123ed42c
commit 4453235b90
  1. 40
      lib/src/sparql/plan.rs
  2. 52
      lib/src/sparql/plan_builder.rs

@ -14,7 +14,7 @@ pub enum PlanNode {
Service { Service {
service_name: PatternValue, service_name: PatternValue,
variables: Rc<Vec<Variable>>, variables: Rc<Vec<Variable>>,
child: Rc<Self>, child: Box<Self>,
graph_pattern: Rc<GraphPattern>, graph_pattern: Rc<GraphPattern>,
silent: bool, silent: bool,
}, },
@ -32,59 +32,59 @@ pub enum PlanNode {
}, },
/// Streams left and materializes right join /// Streams left and materializes right join
HashJoin { HashJoin {
left: Rc<Self>, left: Box<Self>,
right: Rc<Self>, right: Box<Self>,
}, },
/// Right nested in left loop /// Right nested in left loop
ForLoopJoin { ForLoopJoin {
left: Rc<Self>, left: Box<Self>,
right: Rc<Self>, right: Box<Self>,
}, },
/// Streams left and materializes right anti join /// Streams left and materializes right anti join
AntiJoin { AntiJoin {
left: Rc<Self>, left: Box<Self>,
right: Rc<Self>, right: Box<Self>,
}, },
Filter { Filter {
child: Rc<Self>, child: Box<Self>,
expression: Rc<PlanExpression>, expression: Box<PlanExpression>,
}, },
Union { Union {
children: Vec<Rc<Self>>, children: Vec<Self>,
}, },
/// right nested in left loop /// right nested in left loop
LeftJoin { LeftJoin {
left: Rc<Self>, left: Box<Self>,
right: Rc<Self>, right: Box<Self>,
possible_problem_vars: Rc<Vec<usize>>, //Variables that should not be part of the entry of the left join possible_problem_vars: Rc<Vec<usize>>, //Variables that should not be part of the entry of the left join
}, },
Extend { Extend {
child: Rc<Self>, child: Box<Self>,
position: usize, position: usize,
expression: Rc<PlanExpression>, expression: Box<PlanExpression>,
}, },
Sort { Sort {
child: Rc<Self>, child: Box<Self>,
by: Vec<Comparator>, by: Vec<Comparator>,
}, },
HashDeduplicate { HashDeduplicate {
child: Rc<Self>, child: Box<Self>,
}, },
Skip { Skip {
child: Rc<Self>, child: Box<Self>,
count: usize, count: usize,
}, },
Limit { Limit {
child: Rc<Self>, child: Box<Self>,
count: usize, count: usize,
}, },
Project { Project {
child: Rc<Self>, child: Box<Self>,
mapping: Rc<Vec<(usize, usize)>>, // pairs of (variable key in child, variable key in output) mapping: Rc<Vec<(usize, usize)>>, // pairs of (variable key in child, variable key in output)
}, },
Aggregate { Aggregate {
// By definition the group by key are the range 0..key_mapping.len() // By definition the group by key are the range 0..key_mapping.len()
child: Rc<Self>, child: Box<Self>,
key_mapping: Rc<Vec<(usize, usize)>>, // aggregate key pairs of (variable key in child, variable key in output) key_mapping: Rc<Vec<(usize, usize)>>, // aggregate key pairs of (variable key in child, variable key in output)
aggregates: Rc<Vec<(PlanAggregation, usize)>>, aggregates: Rc<Vec<(PlanAggregation, usize)>>,
}, },

@ -53,8 +53,8 @@ impl<'a> PlanBuilder<'a> {
graph_name: graph_name.clone(), graph_name: graph_name.clone(),
}) })
.reduce(|left, right| PlanNode::ForLoopJoin { .reduce(|left, right| PlanNode::ForLoopJoin {
left: Rc::new(left), left: Box::new(left),
right: Rc::new(right), right: Box::new(right),
}) })
.unwrap_or_else(|| PlanNode::StaticBindings { .unwrap_or_else(|| PlanNode::StaticBindings {
tuples: vec![EncodedTuple::with_capacity(variables.len())], tuples: vec![EncodedTuple::with_capacity(variables.len())],
@ -81,13 +81,13 @@ impl<'a> PlanBuilder<'a> {
.is_some() .is_some()
{ {
PlanNode::ForLoopJoin { PlanNode::ForLoopJoin {
left: Rc::new(left), left: Box::new(left),
right: Rc::new(right), right: Box::new(right),
} }
} else { } else {
PlanNode::HashJoin { PlanNode::HashJoin {
left: Rc::new(left), left: Box::new(left),
right: Rc::new(right), right: Box::new(right),
} }
} }
} }
@ -105,8 +105,8 @@ impl<'a> PlanBuilder<'a> {
//We add the extra filter if needed //We add the extra filter if needed
let right = if let Some(expr) = expression { let right = if let Some(expr) = expression {
PlanNode::Filter { PlanNode::Filter {
child: Rc::new(right), child: Box::new(right),
expression: Rc::new( expression: Box::new(
self.build_for_expression(expr, variables, graph_name)?, self.build_for_expression(expr, variables, graph_name)?,
), ),
} }
@ -115,14 +115,14 @@ impl<'a> PlanBuilder<'a> {
}; };
PlanNode::LeftJoin { PlanNode::LeftJoin {
left: Rc::new(left), left: Box::new(left),
right: Rc::new(right), right: Box::new(right),
possible_problem_vars: Rc::new(possible_problem_vars.into_iter().collect()), possible_problem_vars: Rc::new(possible_problem_vars.into_iter().collect()),
} }
} }
GraphPattern::Filter { expr, inner } => PlanNode::Filter { GraphPattern::Filter { expr, inner } => PlanNode::Filter {
child: Rc::new(self.build_for_graph_pattern(inner, variables, graph_name)?), child: Box::new(self.build_for_graph_pattern(inner, variables, graph_name)?),
expression: Rc::new(self.build_for_expression(expr, variables, graph_name)?), expression: Box::new(self.build_for_expression(expr, variables, graph_name)?),
}, },
GraphPattern::Union { left, right } => { GraphPattern::Union { left, right } => {
//We flatten the UNIONs //We flatten the UNIONs
@ -135,9 +135,9 @@ impl<'a> PlanBuilder<'a> {
stack.push(left); stack.push(left);
stack.push(right); stack.push(right);
} }
Some(p) => children.push(Rc::new( Some(p) => {
self.build_for_graph_pattern(p, variables, graph_name)?, children.push(self.build_for_graph_pattern(p, variables, graph_name)?)
)), }
} }
} }
PlanNode::Union { children } PlanNode::Union { children }
@ -151,13 +151,13 @@ impl<'a> PlanBuilder<'a> {
variable, variable,
expression, expression,
} => PlanNode::Extend { } => PlanNode::Extend {
child: Rc::new(self.build_for_graph_pattern(inner, variables, graph_name)?), child: Box::new(self.build_for_graph_pattern(inner, variables, graph_name)?),
position: variable_key(variables, variable), position: variable_key(variables, variable),
expression: Rc::new(self.build_for_expression(expression, variables, graph_name)?), expression: Box::new(self.build_for_expression(expression, variables, graph_name)?),
}, },
GraphPattern::Minus { left, right } => PlanNode::AntiJoin { GraphPattern::Minus { left, right } => PlanNode::AntiJoin {
left: Rc::new(self.build_for_graph_pattern(left, variables, graph_name)?), left: Box::new(self.build_for_graph_pattern(left, variables, graph_name)?),
right: Rc::new(self.build_for_graph_pattern(right, variables, graph_name)?), right: Box::new(self.build_for_graph_pattern(right, variables, graph_name)?),
}, },
GraphPattern::Service { GraphPattern::Service {
name, name,
@ -175,7 +175,7 @@ impl<'a> PlanBuilder<'a> {
.map(|v| OxVariable::new_unchecked(v.name.clone())) .map(|v| OxVariable::new_unchecked(v.name.clone()))
.collect(), .collect(),
), ),
child: Rc::new(child), child: Box::new(child),
graph_pattern: Rc::new(inner.as_ref().clone()), graph_pattern: Rc::new(inner.as_ref().clone()),
silent: *silent, silent: *silent,
} }
@ -190,7 +190,7 @@ impl<'a> PlanBuilder<'a> {
self.convert_pattern_value_id(graph_name, variables, &mut inner_variables); self.convert_pattern_value_id(graph_name, variables, &mut inner_variables);
PlanNode::Aggregate { PlanNode::Aggregate {
child: Rc::new(self.build_for_graph_pattern( child: Box::new(self.build_for_graph_pattern(
inner, inner,
&mut inner_variables, &mut inner_variables,
&inner_graph_name, &inner_graph_name,
@ -237,7 +237,7 @@ impl<'a> PlanBuilder<'a> {
}) })
.collect(); .collect();
PlanNode::Sort { PlanNode::Sort {
child: Rc::new(self.build_for_graph_pattern(inner, variables, graph_name)?), child: Box::new(self.build_for_graph_pattern(inner, variables, graph_name)?),
by: condition?, by: condition?,
} }
} }
@ -249,7 +249,7 @@ impl<'a> PlanBuilder<'a> {
let inner_graph_name = let inner_graph_name =
self.convert_pattern_value_id(graph_name, variables, &mut inner_variables); self.convert_pattern_value_id(graph_name, variables, &mut inner_variables);
PlanNode::Project { PlanNode::Project {
child: Rc::new(self.build_for_graph_pattern( child: Box::new(self.build_for_graph_pattern(
inner, inner,
&mut inner_variables, &mut inner_variables,
&inner_graph_name, &inner_graph_name,
@ -266,7 +266,7 @@ impl<'a> PlanBuilder<'a> {
} }
} }
GraphPattern::Distinct { inner } => PlanNode::HashDeduplicate { GraphPattern::Distinct { inner } => PlanNode::HashDeduplicate {
child: Rc::new(self.build_for_graph_pattern(inner, variables, graph_name)?), child: Box::new(self.build_for_graph_pattern(inner, variables, graph_name)?),
}, },
GraphPattern::Reduced { inner } => { GraphPattern::Reduced { inner } => {
self.build_for_graph_pattern(inner, variables, graph_name)? self.build_for_graph_pattern(inner, variables, graph_name)?
@ -279,13 +279,13 @@ impl<'a> PlanBuilder<'a> {
let mut plan = self.build_for_graph_pattern(inner, variables, graph_name)?; let mut plan = self.build_for_graph_pattern(inner, variables, graph_name)?;
if *start > 0 { if *start > 0 {
plan = PlanNode::Skip { plan = PlanNode::Skip {
child: Rc::new(plan), child: Box::new(plan),
count: *start, count: *start,
}; };
} }
if let Some(length) = length { if let Some(length) = length {
plan = PlanNode::Limit { plan = PlanNode::Limit {
child: Rc::new(plan), child: Box::new(plan),
count: *length, count: *length,
}; };
} }

Loading…
Cancel
Save