diff --git a/cozo-core/src/query/ra.rs b/cozo-core/src/query/ra.rs
index 3b62e59d..d1fc5ece 100644
--- a/cozo-core/src/query/ra.rs
+++ b/cozo-core/src/query/ra.rs
@@ -6,12 +6,9 @@
* You can obtain one at https://mozilla.org/MPL/2.0/.
*/
-use std::cell::RefCell;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::{Debug, Formatter};
use std::iter;
-use std::rc::Rc;
-use std::sync::atomic::{AtomicBool, Ordering};
use either::{Left, Right};
use itertools::Itertools;
@@ -474,8 +471,6 @@ impl RelAlgebra {
joiner,
to_eliminate,
span,
- mat_right_cache: RefCell::new(Default::default()),
- cached: Default::default(),
}));
if !remaining.is_empty() {
joined = RelAlgebra::Filter(FilteredRA {
@@ -521,8 +516,6 @@ impl RelAlgebra {
},
to_eliminate: Default::default(),
span,
- mat_right_cache: RefCell::new(Default::default()),
- cached: Default::default(),
}))
}
pub(crate) fn neg_join(
@@ -1531,8 +1524,6 @@ pub(crate) struct InnerJoin {
pub(crate) joiner: Joiner,
pub(crate) to_eliminate: BTreeSet,
pub(crate) span: SourceSpan,
- mat_right_cache: RefCell>>,
- cached: AtomicBool,
}
impl InnerJoin {
@@ -1689,6 +1680,7 @@ impl InnerJoin {
delta_rule: Option<&MagicSymbol>,
stores: &'a BTreeMap,
) -> Result> {
+ debug!("using materialized join");
let right_bindings = self.right.bindings_after_eliminate();
let (left_join_indices, right_join_indices) = self
.joiner
@@ -1716,9 +1708,7 @@ impl InnerJoin {
.sorted_by_key(|(_, b)| **b)
.map(|(a, _)| a)
.collect_vec();
- let cached_data = if self.cached.load(Ordering::Relaxed) {
- self.mat_right_cache.borrow().clone()
- } else {
+ let cached_data = {
let mut cache = BTreeSet::new();
for item in self.right.iter(tx, delta_rule, stores)? {
match item {
@@ -1732,10 +1722,7 @@ impl InnerJoin {
Err(e) => return Err(e),
}
}
- let cache = cache.into_iter().collect_vec();
- *self.mat_right_cache.borrow_mut() = Rc::new(cache);
- self.cached.store(true, Ordering::Relaxed);
- self.mat_right_cache.borrow().clone()
+ cache.into_iter().collect_vec()
};
let (prefix, right_idx) =
@@ -1756,7 +1743,7 @@ impl InnerJoin {
}
struct CachedMaterializedIterator<'a> {
- materialized: Rc>,
+ materialized: Vec,
eliminate_indices: BTreeSet,
left_join_indices: Vec,
right_invert_indices: Vec,
diff --git a/cozo-core/src/runtime/db.rs b/cozo-core/src/runtime/db.rs
index 12c235f3..834b6891 100644
--- a/cozo-core/src/runtime/db.rs
+++ b/cozo-core/src/runtime/db.rs
@@ -1293,4 +1293,18 @@ mod tests {
.rows;
assert_eq!(res[0][0], json!(1.1))
}
+ #[test]
+ fn test_classical() {
+ let _ = env_logger::builder().is_test(true).try_init();
+ let db = new_cozo_mem().unwrap();
+ let res = db.run_script(r#"
+parent[] <- [['joseph', 'jakob'],
+ ['jakob', 'issac'],
+ ['issac', 'abraham']]
+grandparent[gcld, gp] := parent[gcld, p], parent[p, gp]
+?[who] := grandparent[who, 'abraham']
+ "#, Default::default()).unwrap().rows;
+ println!("{:?}", res);
+ assert_eq!(res[0][0], json!("jakob"))
+ }
}
diff --git a/cozo-lib-wasm/wasm-react-demo/src/App.js b/cozo-lib-wasm/wasm-react-demo/src/App.js
index fde0ef02..c418c0ff 100644
--- a/cozo-lib-wasm/wasm-react-demo/src/App.js
+++ b/cozo-lib-wasm/wasm-react-demo/src/App.js
@@ -224,19 +224,15 @@ function App() {
Please refer to the project homepage for
more information about the Cozo database.
-
+ Not sure what to run?
- ... and run the script, to compute the transitive closure of
- a hypothetical love triangle.
+ {
+ setQueryText(`parent[] <- [['joseph', 'jakob'],
+ ['jakob', 'issac'],
+ ['issac', 'abraham']]
+grandparent[gcld, gp] := parent[gcld, p], parent[p, gp]
+?[who] := grandparent[who, 'abraham']`)
+ }}>Here is a classical example recursive example.
The tutorial contains many more examples.