Skip to content

Commit d778faa

Browse files
committed
Add tpcds planning benchmark
1 parent 3a9a6e2 commit d778faa

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

datafusion/core/benches/sql_planner.rs

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use arrow::datatypes::{DataType, Field, Fields, Schema};
2626
use datafusion::datasource::MemTable;
2727
use datafusion::execution::context::SessionContext;
2828
use std::sync::Arc;
29+
use test_utils::tpcds::tpcds_schemas;
2930
use test_utils::tpch::tpch_schemas;
3031
use test_utils::TableDef;
3132
use tokio::runtime::Runtime;
@@ -72,15 +73,19 @@ fn create_context() -> SessionContext {
7273
.unwrap();
7374
ctx.register_table("t1000", create_table_provider("d", 1000))
7475
.unwrap();
76+
ctx
77+
}
7578

76-
tpch_schemas().iter().for_each(|TableDef { name, schema }| {
79+
/// Register the table definitions as a MemTable with the context and return the
80+
/// context
81+
fn register_defs(ctx: SessionContext, defs: Vec<TableDef>) -> SessionContext {
82+
defs.iter().for_each(|TableDef { name, schema }| {
7783
ctx.register_table(
7884
name,
7985
Arc::new(MemTable::try_new(Arc::new(schema.clone()), vec![]).unwrap()),
8086
)
8187
.unwrap();
8288
});
83-
8489
ctx
8590
}
8691

@@ -139,40 +144,79 @@ fn criterion_benchmark(c: &mut Criterion) {
139144
})
140145
});
141146

147+
// --- TPC-H ---
148+
149+
let tpch_ctx = register_defs(SessionContext::new(), tpch_schemas());
150+
142151
let tpch_queries = [
143152
"q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11", "q12", "q13",
144153
"q14", // "q15", q15 has multiple SQL statements which is not supported
145154
"q16", "q17", "q18", "q19", "q20", "q21", "q22",
146155
];
147156

148157
for q in tpch_queries {
149-
let sql = std::fs::read_to_string(format!("../../benchmarks/queries/{}.sql", q))
150-
.unwrap();
158+
let sql =
159+
std::fs::read_to_string(format!("../../benchmarks/queries/{q}.sql")).unwrap();
151160
c.bench_function(&format!("physical_plan_tpch_{}", q), |b| {
152-
b.iter(|| physical_plan(&ctx, &sql))
161+
b.iter(|| physical_plan(&tpch_ctx, &sql))
153162
});
154163
}
155164

156165
let all_tpch_sql_queries = tpch_queries
157166
.iter()
158167
.map(|q| {
159-
std::fs::read_to_string(format!("../../benchmarks/queries/{}.sql", q))
160-
.unwrap()
168+
std::fs::read_to_string(format!("../../benchmarks/queries/{q}.sql")).unwrap()
161169
})
162170
.collect::<Vec<_>>();
163171

164172
c.bench_function("physical_plan_tpch_all", |b| {
165173
b.iter(|| {
166174
for sql in &all_tpch_sql_queries {
167-
physical_plan(&ctx, sql)
175+
physical_plan(&tpch_ctx, sql)
168176
}
169177
})
170178
});
171179

172180
c.bench_function("logical_plan_tpch_all", |b| {
173181
b.iter(|| {
174182
for sql in &all_tpch_sql_queries {
175-
logical_plan(&ctx, sql)
183+
logical_plan(&tpch_ctx, sql)
184+
}
185+
})
186+
});
187+
188+
// --- TPC-DS ---
189+
190+
let tpcds_ctx = register_defs(SessionContext::new(), tpcds_schemas());
191+
192+
// 10, 35: Physical plan does not support logical expression Exists(<subquery>)
193+
// 45: Physical plan does not support logical expression (<subquery>)
194+
// 41: Optimizing disjunctions not supported
195+
let ignored = [10, 35, 41, 45];
196+
197+
let raw_tpcds_sql_queries = (1..100)
198+
.filter(|q| !ignored.contains(q))
199+
.map(|q| std::fs::read_to_string(format!("./tests/tpc-ds/{q}.sql")).unwrap())
200+
.collect::<Vec<_>>();
201+
202+
// some queries have multiple statements
203+
let all_tpcds_sql_queries = raw_tpcds_sql_queries
204+
.iter()
205+
.flat_map(|sql| sql.split(';').filter(|s| !s.trim().is_empty()))
206+
.collect::<Vec<_>>();
207+
208+
c.bench_function("physical_plan_tpcds_all", |b| {
209+
b.iter(|| {
210+
for sql in &all_tpcds_sql_queries {
211+
physical_plan(&tpcds_ctx, sql)
212+
}
213+
})
214+
});
215+
216+
c.bench_function("logical_plan_tpcds_all", |b| {
217+
b.iter(|| {
218+
for sql in &all_tpcds_sql_queries {
219+
logical_plan(&tpcds_ctx, sql)
176220
}
177221
})
178222
});

0 commit comments

Comments
 (0)