|
|
@ -1,4 +1,9 @@
|
|
|
|
use crate::algebra::op::{build_from_clause, AssocOp, CartesianJoin, Insertion, LimitOp, RelationFromValues, RelationalAlgebra, SelectOp, TableScan, TaggedInsertion, WhereFilter, NAME_FROM, NAME_INSERTION, NAME_RELATION_FROM_VALUES, NAME_SELECT, NAME_SKIP, NAME_TAGGED_INSERTION, NAME_TAGGED_UPSERT, NAME_TAKE, NAME_UPSERT, NAME_WHERE, NestedLoopLeft, NestedLoopRight, NestedLoopOuter};
|
|
|
|
use crate::algebra::op::{
|
|
|
|
|
|
|
|
build_from_clause, AssocOp, CartesianJoin, Insertion, LimitOp, NestedLoopLeft,
|
|
|
|
|
|
|
|
RelationFromValues, RelationalAlgebra, SelectOp, TableScan, TaggedInsertion, WhereFilter,
|
|
|
|
|
|
|
|
NAME_FROM, NAME_INSERTION, NAME_RELATION_FROM_VALUES, NAME_SELECT, NAME_SKIP,
|
|
|
|
|
|
|
|
NAME_TAGGED_INSERTION, NAME_TAGGED_UPSERT, NAME_TAKE, NAME_UPSERT, NAME_WHERE,
|
|
|
|
|
|
|
|
};
|
|
|
|
use crate::context::TempDbContext;
|
|
|
|
use crate::context::TempDbContext;
|
|
|
|
use crate::data::tuple::OwnTuple;
|
|
|
|
use crate::data::tuple::OwnTuple;
|
|
|
|
use crate::data::tuple_set::{BindingMap, TableId, TupleSet};
|
|
|
|
use crate::data::tuple_set::{BindingMap, TableId, TupleSet};
|
|
|
@ -70,8 +75,6 @@ pub(crate) enum RaBox<'a> {
|
|
|
|
LimitOp(Box<LimitOp<'a>>),
|
|
|
|
LimitOp(Box<LimitOp<'a>>),
|
|
|
|
Cartesian(Box<CartesianJoin<'a>>),
|
|
|
|
Cartesian(Box<CartesianJoin<'a>>),
|
|
|
|
NestedLoopLeft(Box<NestedLoopLeft<'a>>),
|
|
|
|
NestedLoopLeft(Box<NestedLoopLeft<'a>>),
|
|
|
|
NestedLoopRight(Box<NestedLoopRight<'a>>),
|
|
|
|
|
|
|
|
NestedLoopOuter(Box<NestedLoopOuter<'a>>)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a> RaBox<'a> {
|
|
|
|
impl<'a> RaBox<'a> {
|
|
|
@ -87,8 +90,6 @@ impl<'a> RaBox<'a> {
|
|
|
|
RaBox::LimitOp(inner) => vec![&inner.source],
|
|
|
|
RaBox::LimitOp(inner) => vec![&inner.source],
|
|
|
|
RaBox::Cartesian(inner) => vec![&inner.left, &inner.right],
|
|
|
|
RaBox::Cartesian(inner) => vec![&inner.left, &inner.right],
|
|
|
|
RaBox::NestedLoopLeft(inner) => vec![&inner.left],
|
|
|
|
RaBox::NestedLoopLeft(inner) => vec![&inner.left],
|
|
|
|
RaBox::NestedLoopRight(inner) => vec![&inner.left],
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => vec![&inner.left],
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -116,8 +117,6 @@ impl<'b> RelationalAlgebra for RaBox<'b> {
|
|
|
|
RaBox::LimitOp(inner) => inner.name(),
|
|
|
|
RaBox::LimitOp(inner) => inner.name(),
|
|
|
|
RaBox::Cartesian(inner) => inner.name(),
|
|
|
|
RaBox::Cartesian(inner) => inner.name(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.name(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.name(),
|
|
|
|
RaBox::NestedLoopRight(inner) => inner.name(),
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => inner.name(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -133,8 +132,6 @@ impl<'b> RelationalAlgebra for RaBox<'b> {
|
|
|
|
RaBox::LimitOp(inner) => inner.bindings(),
|
|
|
|
RaBox::LimitOp(inner) => inner.bindings(),
|
|
|
|
RaBox::Cartesian(inner) => inner.bindings(),
|
|
|
|
RaBox::Cartesian(inner) => inner.bindings(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.bindings(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.bindings(),
|
|
|
|
RaBox::NestedLoopRight(inner) => inner.bindings(),
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => inner.bindings(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -150,8 +147,6 @@ impl<'b> RelationalAlgebra for RaBox<'b> {
|
|
|
|
RaBox::LimitOp(inner) => inner.binding_map(),
|
|
|
|
RaBox::LimitOp(inner) => inner.binding_map(),
|
|
|
|
RaBox::Cartesian(inner) => inner.binding_map(),
|
|
|
|
RaBox::Cartesian(inner) => inner.binding_map(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.binding_map(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.binding_map(),
|
|
|
|
RaBox::NestedLoopRight(inner) => inner.binding_map(),
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => inner.binding_map(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -167,8 +162,6 @@ impl<'b> RelationalAlgebra for RaBox<'b> {
|
|
|
|
RaBox::LimitOp(inner) => inner.iter(),
|
|
|
|
RaBox::LimitOp(inner) => inner.iter(),
|
|
|
|
RaBox::Cartesian(inner) => inner.iter(),
|
|
|
|
RaBox::Cartesian(inner) => inner.iter(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.iter(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.iter(),
|
|
|
|
RaBox::NestedLoopRight(inner) => inner.iter(),
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => inner.iter(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -184,8 +177,6 @@ impl<'b> RelationalAlgebra for RaBox<'b> {
|
|
|
|
RaBox::LimitOp(inner) => inner.identity(),
|
|
|
|
RaBox::LimitOp(inner) => inner.identity(),
|
|
|
|
RaBox::Cartesian(inner) => inner.identity(),
|
|
|
|
RaBox::Cartesian(inner) => inner.identity(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.identity(),
|
|
|
|
RaBox::NestedLoopLeft(inner) => inner.identity(),
|
|
|
|
RaBox::NestedLoopRight(inner) => inner.identity(),
|
|
|
|
|
|
|
|
RaBox::NestedLoopOuter(inner) => inner.identity(),
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -304,7 +295,7 @@ pub(crate) mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
ctx.txn.commit().unwrap();
|
|
|
|
ctx.txn.commit().unwrap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let duration = start.elapsed();
|
|
|
|
let duration_insert = start.elapsed();
|
|
|
|
let start = Instant::now();
|
|
|
|
let start = Instant::now();
|
|
|
|
{
|
|
|
|
{
|
|
|
|
let ctx = sess.temp_ctx(true);
|
|
|
|
let ctx = sess.temp_ctx(true);
|
|
|
@ -326,7 +317,47 @@ pub(crate) mod tests {
|
|
|
|
dbg!(&ra);
|
|
|
|
dbg!(&ra);
|
|
|
|
dbg!(ra.get_values()?);
|
|
|
|
dbg!(ra.get_values()?);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let duration2 = start.elapsed();
|
|
|
|
let duration_scan = start.elapsed();
|
|
|
|
|
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let ctx = sess.temp_ctx(true);
|
|
|
|
|
|
|
|
let s = r#"
|
|
|
|
|
|
|
|
From(e:Employee-[hj:HasJob]->?j:Job)
|
|
|
|
|
|
|
|
.Where(e.id >= 122, e.id < 130)
|
|
|
|
|
|
|
|
.Select({...e, title: j.title, salary: hj.salary})
|
|
|
|
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let ra = build_relational_expr(
|
|
|
|
|
|
|
|
&ctx,
|
|
|
|
|
|
|
|
CozoParser::parse(Rule::ra_expr_all, s)
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
|
|
.next()
|
|
|
|
|
|
|
|
.unwrap(),
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
dbg!(&ra);
|
|
|
|
|
|
|
|
dbg!(ra.get_values()?);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let duration_join = start.elapsed();
|
|
|
|
|
|
|
|
let start = Instant::now();
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let ctx = sess.temp_ctx(true);
|
|
|
|
|
|
|
|
let s = r#"
|
|
|
|
|
|
|
|
From(j:Job<-[hj:HasJob]-?e:Employee)
|
|
|
|
|
|
|
|
.Where(e.id >= 122, e.id < 130)
|
|
|
|
|
|
|
|
.Select({...e, title: j.title, salary: hj.salary})
|
|
|
|
|
|
|
|
"#;
|
|
|
|
|
|
|
|
let ra = build_relational_expr(
|
|
|
|
|
|
|
|
&ctx,
|
|
|
|
|
|
|
|
CozoParser::parse(Rule::ra_expr_all, s)
|
|
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
|
|
.into_iter()
|
|
|
|
|
|
|
|
.next()
|
|
|
|
|
|
|
|
.unwrap(),
|
|
|
|
|
|
|
|
)?;
|
|
|
|
|
|
|
|
dbg!(&ra);
|
|
|
|
|
|
|
|
dbg!(ra.get_values()?);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let duration_join_back = start.elapsed();
|
|
|
|
let start = Instant::now();
|
|
|
|
let start = Instant::now();
|
|
|
|
let mut r_opts = default_read_options();
|
|
|
|
let mut r_opts = default_read_options();
|
|
|
|
r_opts.set_total_order_seek(true);
|
|
|
|
r_opts.set_total_order_seek(true);
|
|
|
@ -343,8 +374,15 @@ pub(crate) mod tests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it.next();
|
|
|
|
it.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let duration3 = start.elapsed();
|
|
|
|
let duration_list = start.elapsed();
|
|
|
|
dbg!(duration, duration2, duration3, n);
|
|
|
|
dbg!(
|
|
|
|
|
|
|
|
duration_insert,
|
|
|
|
|
|
|
|
duration_scan,
|
|
|
|
|
|
|
|
duration_join,
|
|
|
|
|
|
|
|
duration_join_back,
|
|
|
|
|
|
|
|
duration_list,
|
|
|
|
|
|
|
|
n
|
|
|
|
|
|
|
|
);
|
|
|
|
Ok(())
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|