Skip to content

Commit 5956aca

Browse files
authored
do not apply constant operations to factors (#752)
2 parents 9de82e2 + f8ae947 commit 5956aca

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

nemo/src/execution/planning/operations/join_cartesian.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::{
2121
/// The rule body is divided into multiple independent factors.
2222
/// Those can either be [BodyAtom]s
2323
/// or [Operation]s assigning constants to a variable.
24+
#[derive(Debug)]
2425
enum Factor {
2526
/// Factor consisting of body atoms
2627
Atoms(Vec<BodyAtom>),
@@ -107,7 +108,7 @@ impl GeneratorJoinCartesian {
107108
/// atoms: [a(x, y), b(y, z), c(z), r(w), t(w)]
108109
/// operations: [q = 3, s = 7]
109110
/// result: [[a(x, y), b(y, z), c(z)], [r(w), t(w)], [q = 3, s = 7]]
110-
fn partition_atoms(atoms: &[BodyAtom], operations: &[Operation]) -> Vec<Factor> {
111+
fn partition_atoms(atoms: &[BodyAtom], operations: &mut Vec<Operation>) -> Vec<Factor> {
111112
#[derive(Clone)]
112113
struct Partition {
113114
pub variables: HashSet<Variable>,
@@ -207,26 +208,26 @@ impl GeneratorJoinCartesian {
207208
.flat_map(|atom| atom.terms())
208209
.collect::<HashSet<_>>();
209210

210-
let mut constant_operations = HashSet::<usize>::default();
211+
let mut constant_operations = Vec::<Operation>::default();
211212
let mut constant_operations_len = constant_operations.len();
212213
let mut constant_operations_variables = HashSet::<Variable>::default();
213214

214215
loop {
215-
for (index, operation) in operations.iter().enumerate() {
216-
if constant_operations.contains(&index) {
217-
continue;
218-
}
219-
216+
operations.retain(|operation| {
220217
if let Some((left, right)) = operation.variable_assignment()
221218
&& !body_variables.contains(left)
222219
&& right
223220
.variables()
224221
.all(|variable| constant_operations_variables.contains(variable))
225222
{
226-
constant_operations.insert(index);
223+
constant_operations.push(operation.clone());
227224
constant_operations_variables.insert(left.clone());
225+
226+
return false;
228227
}
229-
}
228+
229+
true
230+
});
230231

231232
if constant_operations_len == constant_operations.len() {
232233
break;
@@ -235,11 +236,6 @@ impl GeneratorJoinCartesian {
235236
constant_operations_len = constant_operations.len();
236237
}
237238

238-
let constant_operations = constant_operations
239-
.iter()
240-
.map(|&index| operations[index].clone())
241-
.collect::<Vec<_>>();
242-
243239
if !constant_operations.is_empty() {
244240
result.push(Factor::Operations(constant_operations));
245241
}

nemo/src/execution/planning/strategy/forward/body.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,14 @@ impl StrategyBody {
6060

6161
Self::Plain { join, filter }
6262
} else {
63-
let mut merge_operations = &mut operations.clone();
63+
let merge_operations = &mut operations.clone();
6464
let mut merge_negative = negative.clone();
6565

6666
let join = GeneratorJoinCartesian::new(&order, &positive, operations, &mut negative);
6767
let variables_join = join.output_variables();
68-
let single_factor = join.is_single_join();
6968

7069
let import = GeneratorImport::new(variables_join, &imports);
7170

72-
if single_factor {
73-
merge_operations = operations;
74-
merge_negative = negative;
75-
}
76-
7771
let merge = GeneratorJoinImports::new(
7872
&order,
7973
positive,

0 commit comments

Comments
 (0)