Uses Reduced everywhere cardinality is not important

Allows avoiding dumb downstream duplicated work and should hopefully unlock optimizations in the future.
pull/171/head
Tpt 3 years ago
parent 505980f026
commit 6d4bb36425
  1. 8
      lib/src/sparql/mod.rs
  2. 11
      lib/src/sparql/plan_builder.rs
  3. 2
      lib/src/sparql/update.rs

@ -48,7 +48,7 @@ pub(crate) fn evaluate_query(
spargebra::Query::Select { spargebra::Query::Select {
pattern, base_iri, .. pattern, base_iri, ..
} => { } => {
let (plan, variables) = PlanBuilder::build(&dataset, &pattern)?; let (plan, variables) = PlanBuilder::build(&dataset, &pattern, true)?;
Ok(SimpleEvaluator::new( Ok(SimpleEvaluator::new(
Rc::new(dataset), Rc::new(dataset),
base_iri.map(Rc::new), base_iri.map(Rc::new),
@ -67,7 +67,7 @@ pub(crate) fn evaluate_query(
spargebra::Query::Ask { spargebra::Query::Ask {
pattern, base_iri, .. pattern, base_iri, ..
} => { } => {
let (plan, _) = PlanBuilder::build(&dataset, &pattern)?; let (plan, _) = PlanBuilder::build(&dataset, &pattern, false)?;
SimpleEvaluator::new( SimpleEvaluator::new(
Rc::new(dataset), Rc::new(dataset),
base_iri.map(Rc::new), base_iri.map(Rc::new),
@ -81,7 +81,7 @@ pub(crate) fn evaluate_query(
base_iri, base_iri,
.. ..
} => { } => {
let (plan, variables) = PlanBuilder::build(&dataset, &pattern)?; let (plan, variables) = PlanBuilder::build(&dataset, &pattern, false)?;
let construct = PlanBuilder::build_graph_template(&dataset, &template, variables); let construct = PlanBuilder::build_graph_template(&dataset, &template, variables);
Ok(SimpleEvaluator::new( Ok(SimpleEvaluator::new(
Rc::new(dataset), Rc::new(dataset),
@ -93,7 +93,7 @@ pub(crate) fn evaluate_query(
spargebra::Query::Describe { spargebra::Query::Describe {
pattern, base_iri, .. pattern, base_iri, ..
} => { } => {
let (plan, _) = PlanBuilder::build(&dataset, &pattern)?; let (plan, _) = PlanBuilder::build(&dataset, &pattern, false)?;
Ok(SimpleEvaluator::new( Ok(SimpleEvaluator::new(
Rc::new(dataset), Rc::new(dataset),
base_iri.map(Rc::new), base_iri.map(Rc::new),

@ -19,6 +19,7 @@ impl<'a> PlanBuilder<'a> {
pub fn build( pub fn build(
dataset: &'a DatasetView, dataset: &'a DatasetView,
pattern: &GraphPattern, pattern: &GraphPattern,
is_cardinality_meaningful: bool,
) -> Result<(PlanNode, Vec<Variable>), EvaluationError> { ) -> Result<(PlanNode, Vec<Variable>), EvaluationError> {
let mut variables = Vec::default(); let mut variables = Vec::default();
let plan = PlanBuilder { dataset }.build_for_graph_pattern( let plan = PlanBuilder { dataset }.build_for_graph_pattern(
@ -26,6 +27,15 @@ impl<'a> PlanBuilder<'a> {
&mut variables, &mut variables,
&PatternValue::Constant(EncodedTerm::DefaultGraph), &PatternValue::Constant(EncodedTerm::DefaultGraph),
)?; )?;
let plan = if is_cardinality_meaningful {
plan
} else {
// let's reduce downstream task.
// TODO: avoid if already REDUCED or DISTINCT
PlanNode::Reduced {
child: Box::new(plan),
}
};
Ok((plan, variables)) Ok((plan, variables))
} }
@ -1253,6 +1263,7 @@ impl<'a> PlanBuilder<'a> {
expression, expression,
position, position,
} => { } => {
//TODO: handle the case where the filter generates an expression variable
if filter_variables.iter().all(|v| child.is_variable_bound(*v)) { if filter_variables.iter().all(|v| child.is_variable_bound(*v)) {
PlanNode::Extend { PlanNode::Extend {
child: Box::new(Self::push_filter(child, filter)), child: Box::new(Self::push_filter(child, filter)),

@ -120,7 +120,7 @@ impl<'a> SimpleUpdateEvaluator<'a> {
algebra: &GraphPattern, algebra: &GraphPattern,
) -> Result<(), EvaluationError> { ) -> Result<(), EvaluationError> {
let dataset = Rc::new(DatasetView::new(self.storage.clone(), using)); let dataset = Rc::new(DatasetView::new(self.storage.clone(), using));
let (plan, variables) = PlanBuilder::build(dataset.as_ref(), algebra)?; let (plan, variables) = PlanBuilder::build(dataset.as_ref(), algebra, false)?;
let evaluator = SimpleEvaluator::new( let evaluator = SimpleEvaluator::new(
dataset.clone(), dataset.clone(),
self.base_iri.clone(), self.base_iri.clone(),

Loading…
Cancel
Save