use relate_core::Value;
use crate::exec::kernels::with_kernels_disabled;
use crate::exec::test_support::{build, exec_cypher};
use crate::row::interned_schema_calls;
fn fan(people: usize) -> crate::exec::test_support::Built {
let labels: Vec<&[&str]> = (0..people)
.map(|_| &["P"][..])
.chain((0..people).map(|_| &["Q"][..]))
.collect();
let rels: Vec<(usize, usize, &str)> = (0..people).map(|i| (i, people + i, "R")).collect();
build(&labels, &rels)
}
const STATEMENT: &str = "MATCH (p:P) WITH p MATCH (p)-[:R]->(q:Q) RETURN p, q";
const DRIVER_ONLY: &str = "MATCH (p:P) WITH p RETURN p";
fn interned_for(cypher: &str, people: usize) -> (usize, usize) {
let built = fan(people);
with_kernels_disabled(|| {
let before = interned_schema_calls();
let rows = exec_cypher(&built.graph, cypher).rows.len();
(interned_schema_calls() - before, rows)
})
}
#[test]
fn the_second_match_adds_no_per_row_interning_over_the_driving_clause() {
let growth = |cypher: &str| {
let (few, few_rows) = interned_for(cypher, 8);
let (many, many_rows) = interned_for(cypher, 80);
assert_eq!((few_rows, many_rows), (8, 80), "{cypher}");
many - few
};
assert_eq!(growth(STATEMENT), growth(DRIVER_ONLY));
}
#[test]
fn the_memoized_walk_pairs_each_p_with_its_own_q() {
const PEOPLE: usize = 20;
let built = fan(PEOPLE);
let rows = with_kernels_disabled(|| exec_cypher(&built.graph, STATEMENT).rows);
assert_eq!(rows.len(), PEOPLE);
for row in &rows {
let (Value::Node(p), Value::Node(q)) = (&row[0], &row[1]) else {
panic!("p and q are nodes: {row:?}");
};
assert_eq!(q.id, p.id + PEOPLE as i64, "{row:?}");
}
}