Skip to content

Commit 4108884

Browse files
committed
bench: cover residual semi/anti sort-merge join witnesses and latest versions
1 parent c8265b6 commit 4108884

4 files changed

Lines changed: 304 additions & 43 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name Q27
2+
group smj
3+
4+
init
5+
set datafusion.optimizer.prefer_hash_join=false;
6+
7+
expect_plan SortMergeJoinExec
8+
expect_plan Anti
9+
10+
run sql_benchmarks/smj/queries/q27.sql
11+
12+
cleanup
13+
reset datafusion.optimizer.prefer_hash_join;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- Keep the newest of 128 versions of each of 1024 documents.
2+
WITH documents AS (
3+
SELECT value / 128 AS document_id, value % 128 AS version
4+
FROM range(131072)
5+
)
6+
SELECT d.document_id, d.version
7+
FROM documents d
8+
WHERE NOT EXISTS (
9+
SELECT 1 FROM documents newer
10+
WHERE newer.document_id = d.document_id AND newer.version > d.version
11+
)

‎benchmarks/src/smj.rs‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use futures::StreamExt;
2626
#[derive(Debug, Args, Clone)]
2727
#[command(verbatim_doc_comment)]
2828
pub struct RunOpt {
29-
/// Query number (between 1 and 26). If not specified, runs all queries
29+
/// One-based query number. If not specified, runs all queries
3030
#[arg(short, long)]
3131
query: Option<usize>,
3232

@@ -509,6 +509,8 @@ const SMJ_QUERIES: &[&str] = &[
509509
AND t2_sorted.data % 10 <> 0
510510
)
511511
"#,
512+
// Q27: LEFT ANTI | 1024 documents × 128 versions | one latest version per key
513+
include_str!("../sql_benchmarks/smj/queries/q27.sql"),
512514
];
513515

514516
impl RunOpt {
@@ -543,10 +545,7 @@ impl RunOpt {
543545

544546
let sql = SMJ_QUERIES[query_index];
545547
benchmark_run.start_new_case(&format!("Query {query_id}"));
546-
let expect_mark = query_id >= 24;
547-
let query_run = self
548-
.benchmark_query(sql, &query_id.to_string(), expect_mark, &ctx)
549-
.await;
548+
let query_run = self.benchmark_query(sql, query_id, &ctx).await;
550549
match query_run {
551550
Ok(query_results) => {
552551
for iter in query_results {
@@ -569,8 +568,7 @@ impl RunOpt {
569568
async fn benchmark_query(
570569
&self,
571570
sql: &str,
572-
query_name: &str,
573-
expect_mark: bool,
571+
query_id: usize,
574572
ctx: &SessionContext,
575573
) -> Result<Vec<QueryResult>> {
576574
let mut query_results = vec![];
@@ -582,13 +580,13 @@ impl RunOpt {
582580

583581
if !plan_string.contains("SortMergeJoinExec") {
584582
return Err(exec_datafusion_err!(
585-
"Query {query_name} does not use Sort Merge Join. Physical plan: {plan_string}"
583+
"Query {query_id} does not use Sort Merge Join. Physical plan: {plan_string}"
586584
));
587585
}
588586

589-
if expect_mark && !plan_string.contains("LeftMark") {
587+
if (24..=26).contains(&query_id) && !plan_string.contains("LeftMark") {
590588
return Err(exec_datafusion_err!(
591-
"Query {query_name} expected LeftMark join. Physical plan: {plan_string}"
589+
"Query {query_id} expected LeftMark join. Physical plan: {plan_string}"
592590
));
593591
}
594592

@@ -598,9 +596,14 @@ impl RunOpt {
598596
let row_count = Self::execute_sql_without_result_buffering(sql, ctx).await?;
599597

600598
let elapsed = start.elapsed();
599+
if query_id == 27 && row_count != 1024 {
600+
return exec_err!(
601+
"Query {query_id} returned {row_count} latest versions, expected 1024"
602+
);
603+
}
601604

602605
println!(
603-
"Query {query_name} iteration {i} returned {row_count} rows in {elapsed:?}"
606+
"Query {query_id} iteration {i} returned {row_count} rows in {elapsed:?}"
604607
);
605608

606609
query_results.push(QueryResult { elapsed, row_count });

0 commit comments

Comments
 (0)