Skip to content

Commit 23fcd0e

Browse files
authored
planner: add tpch q1,q2,q3 benchmark (pingcap#61898)
1 parent a3cba16 commit 23fcd0e

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

pkg/planner/core/casetest/tpch/tpch_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,60 @@ func TestQ22(t *testing.T) {
346346
}
347347
}
348348

349+
func BenchmarkTPCHQ1(b *testing.B) {
350+
store, dom := testkit.CreateMockStoreAndDomain(b)
351+
tk := testkit.NewTestKit(b, store)
352+
tk.MustExec("use test")
353+
createLineItem(b, tk, dom)
354+
tk.MustExec("set @@session.tidb_broadcast_join_threshold_size = 0")
355+
tk.MustExec("set @@session.tidb_broadcast_join_threshold_count = 0")
356+
testkit.LoadTableStats("test.lineitem.json", dom)
357+
b.ResetTimer()
358+
b.ReportAllocs()
359+
for i := 0; i < b.N; i++ {
360+
tk.MustQuery("explain format='brief' SELECT l_returnflag, l_linestatus, SUM(l_quantity) AS sum_qty, SUM(l_extendedprice) AS sum_base_price, SUM(l_extendedprice * (1 - l_discount)) AS sum_disc_price, SUM(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, AVG(l_quantity) AS avg_qty, AVG(l_extendedprice) AS avg_price, AVG(l_discount) AS avg_disc, COUNT(*) AS count_order FROM lineitem WHERE l_shipdate <= DATE_SUB('1998-12-01', INTERVAL 108 DAY) GROUP BY l_returnflag, l_linestatus ORDER BY l_returnflag, l_linestatus;")
361+
}
362+
}
363+
364+
func BenchmarkTPCHQ2(b *testing.B) {
365+
store, dom := testkit.CreateMockStoreAndDomain(b)
366+
tk := testkit.NewTestKit(b, store)
367+
tk.MustExec("use test")
368+
createPart(b, tk, dom)
369+
createSupplier(b, tk, dom)
370+
createPartsupp(b, tk, dom)
371+
createNation(b, tk, dom)
372+
createRegion(b, tk, dom)
373+
testkit.LoadTableStats("test.part.json", dom)
374+
testkit.LoadTableStats("test.supplier.json", dom)
375+
testkit.LoadTableStats("test.partsupp.json", dom)
376+
testkit.LoadTableStats("test.region.json", dom)
377+
testkit.LoadTableStats("test.nation.json", dom)
378+
b.ResetTimer()
379+
b.ReportAllocs()
380+
for i := 0; i < b.N; i++ {
381+
tk.MustQuery("SELECT s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment FROM part, supplier, partsupp, nation, region WHERE p_partkey = ps_partkey AND s_suppkey = ps_suppkey AND p_size = 30 AND p_type LIKE '%STEEL' AND s_nationkey = n_nationkey AND n_regionkey = r_regionkey AND r_name = 'ASIA' AND ps_supplycost = (SELECT MIN(ps_supplycost) FROM partsupp, supplier, nation, region WHERE p_partkey = ps_partkey AND s_suppkey = ps_suppkey AND s_nationkey = n_nationkey AND n_regionkey = r_regionkey AND r_name = 'ASIA') ORDER BY s_acctbal DESC, n_name, s_name, p_partkey LIMIT 100;")
382+
}
383+
}
384+
385+
func BenchmarkTPCHQ3(b *testing.B) {
386+
store, dom := testkit.CreateMockStoreAndDomain(b)
387+
tk := testkit.NewTestKit(b, store)
388+
tk.MustExec("use test")
389+
createCustomer(b, tk, dom)
390+
createOrders(b, tk, dom)
391+
createLineItem(b, tk, dom)
392+
tk.MustExec("set @@session.tidb_broadcast_join_threshold_size = 0")
393+
tk.MustExec("set @@session.tidb_broadcast_join_threshold_count = 0")
394+
b.ResetTimer()
395+
b.ReportAllocs()
396+
for i := 0; i < b.N; i++ {
397+
tk.MustQuery("explain format='brief' select /*+ HASH_JOIN(orders, lineitem, customer) */ l_orderkey, sum(l_extendedprice * (1 - l_discount)) as revenue, o_orderdate, o_shippriority from customer, orders, lineitem where c_mktsegment = 'AUTOMOBILE' and c_custkey = o_custkey and l_orderkey = o_orderkey and o_orderdate < '1995-03-13' and l_shipdate > '1995-03-13' group by l_orderkey, o_orderdate, o_shippriority order by revenue desc, o_orderdate limit 10;")
398+
tk.MustQuery("explain format='brief' SELECT /*+ HASH_JOIN(orders, lineitem, customer) */ l_orderkey, SUM(l_extendedprice * (1 - l_discount)) AS revenue, o_orderdate, o_shippriority FROM customer AS c LEFT JOIN orders AS o ON c.c_custkey = o.o_custkey LEFT JOIN lineitem AS l ON l.l_orderkey = o.o_orderkey WHERE c.c_mktsegment = 'AUTOMOBILE' AND o.o_orderdate < '1995-03-13' AND l.l_shipdate > '1995-03-13' GROUP BY l_orderkey, o_orderdate, o_shippriority ORDER BY revenue DESC, o_orderdate LIMIT 10;")
399+
tk.MustQuery("explain format='brief' SELECT /*+ SHUFFLE_JOIN(orders, lineitem) */ o.o_orderdate, SUM(l.l_extendedprice * (1 - l.l_discount)) AS revenue FROM orders AS o JOIN lineitem AS l ON o.o_orderkey = l.l_orderkey WHERE o.o_orderdate BETWEEN '1994-01-01' AND '1994-12-31' GROUP BY o.o_orderdate ORDER BY revenue DESC LIMIT 10;")
400+
}
401+
}
402+
349403
func BenchmarkTPCHQ4(b *testing.B) {
350404
store, dom := testkit.CreateMockStoreAndDomain(b)
351405
tk := testkit.NewTestKit(b, store)
@@ -384,6 +438,9 @@ func BenchmarkTPCHQ21(b *testing.B) {
384438

385439
func TestBenchDaily(t *testing.T) {
386440
benchdaily.Run(
441+
BenchmarkTPCHQ1,
442+
BenchmarkTPCHQ2,
443+
BenchmarkTPCHQ3,
387444
BenchmarkTPCHQ4,
388445
BenchmarkTPCHQ21,
389446
)

0 commit comments

Comments
 (0)