From 58fe455621f57ed3d19c4afdee6b46905c9b048a Mon Sep 17 00:00:00 2001 From: Tpt Date: Fri, 25 Oct 2019 12:06:35 +0200 Subject: [PATCH] Tweaks the join reordering algorithm to prefer using bound variables --- bench/bsbm.explore.svg | 300 ++++++++++++++++----------------- lib/src/sparql/plan_builder.rs | 16 +- 2 files changed, 161 insertions(+), 155 deletions(-) diff --git a/bench/bsbm.explore.svg b/bench/bsbm.explore.svg index a46d17a7..4bef93e5 100644 --- a/bench/bsbm.explore.svg +++ b/bench/bsbm.explore.svg @@ -27,354 +27,354 @@ z " style="fill:#ffffff;"/> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -384,10 +384,10 @@ z +" id="m77ec045e3d" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -426,7 +426,7 @@ z - + @@ -458,7 +458,7 @@ z - + @@ -503,7 +503,7 @@ z - + @@ -557,7 +557,7 @@ z - + @@ -607,7 +607,7 @@ z - + @@ -780,10 +780,10 @@ z +" id="mdd0da8bc57" style="stroke:#000000;stroke-width:0.8;"/> - + @@ -807,12 +807,12 @@ z - + - + @@ -823,12 +823,12 @@ z - + - + @@ -839,12 +839,12 @@ z - + - + @@ -855,12 +855,12 @@ z - + - + @@ -1492,7 +1492,7 @@ z - + diff --git a/lib/src/sparql/plan_builder.rs b/lib/src/sparql/plan_builder.rs index 041e8ecc..0f107b06 100644 --- a/lib/src/sparql/plan_builder.rs +++ b/lib/src/sparql/plan_builder.rs @@ -934,25 +934,31 @@ fn count_pattern_binds( pattern: &TripleOrPathPattern, assigned_variables: &HashSet<&Variable>, ) -> u8 { - let mut count = 3; + let mut count = 12; if let TermOrVariable::Variable(v) = pattern.subject() { if !assigned_variables.contains(v) { - count -= 1; + count -= 4; } + } else { + count -= 1; } if let TripleOrPathPattern::Triple(t) = pattern { if let NamedNodeOrVariable::Variable(v) = &t.predicate { if !assigned_variables.contains(v) { - count -= 1; + count -= 4; } + } else { + count -= 1; } } else { - count -= 1; + count -= 3; } if let TermOrVariable::Variable(v) = pattern.object() { if !assigned_variables.contains(v) { - count -= 1; + count -= 4; } + } else { + count -= 1; } count }