Skip to content

Commit c3d1a7a

Browse files
committed
Add benchmark for ReorderJoins rule
Results run on my development vm BenchmarkReorderJoinsConnectedGraph: BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins ELIMINATE_CROSS_JOINS 2 avgt 30 54.610 ± 4.236 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins ELIMINATE_CROSS_JOINS 4 avgt 30 153.794 ± 9.075 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins ELIMINATE_CROSS_JOINS 6 avgt 30 326.410 ± 19.912 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins ELIMINATE_CROSS_JOINS 8 avgt 30 578.028 ± 33.308 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins ELIMINATE_CROSS_JOINS 10 avgt 30 955.494 ± 44.523 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins COST_BASED 2 avgt 30 54.844 ± 4.256 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins COST_BASED 4 avgt 30 161.164 ± 11.008 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins COST_BASED 6 avgt 30 440.007 ± 28.903 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins COST_BASED 8 avgt 30 2491.240 ± 72.341 ms/op BenchmarkReorderJoinsConnectedGraph.benchmarkReorderJoins COST_BASED 10 avgt 30 24026.603 ± 886.696 ms/opa BencharkReorderJoinsLinearGraph: BenchmarkReorderJoinsLinearQuery.benchmarkReorderJoins ELIMINATE_CROSS_JOINS avgt 30 944.179 ± 42.406 ms/op BenchmarkReorderJoinsLinearQuery.benchmarkReorderJoins COST_BASED avgt 30 1329.194 ± 71.704 ms/op
1 parent 6549cf1 commit c3d1a7a

File tree

2 files changed

+226
-0
lines changed

2 files changed

+226
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.sql.planner.iterative.rule;
15+
16+
import com.facebook.presto.Session;
17+
import com.facebook.presto.testing.LocalQueryRunner;
18+
import com.facebook.presto.testing.MaterializedResult;
19+
import com.facebook.presto.testing.QueryRunner;
20+
import com.facebook.presto.tpch.TpchConnectorFactory;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.openjdk.jmh.annotations.Benchmark;
23+
import org.openjdk.jmh.annotations.BenchmarkMode;
24+
import org.openjdk.jmh.annotations.Fork;
25+
import org.openjdk.jmh.annotations.Measurement;
26+
import org.openjdk.jmh.annotations.OutputTimeUnit;
27+
import org.openjdk.jmh.annotations.Param;
28+
import org.openjdk.jmh.annotations.Setup;
29+
import org.openjdk.jmh.annotations.State;
30+
import org.openjdk.jmh.annotations.TearDown;
31+
import org.openjdk.jmh.annotations.Warmup;
32+
import org.openjdk.jmh.runner.Runner;
33+
import org.openjdk.jmh.runner.RunnerException;
34+
import org.openjdk.jmh.runner.options.Options;
35+
import org.openjdk.jmh.runner.options.OptionsBuilder;
36+
import org.openjdk.jmh.runner.options.VerboseMode;
37+
38+
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
39+
import static com.google.common.base.Preconditions.checkState;
40+
import static java.lang.String.format;
41+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
42+
import static org.openjdk.jmh.annotations.Mode.AverageTime;
43+
import static org.openjdk.jmh.annotations.Scope.Thread;
44+
45+
@State(Thread)
46+
@OutputTimeUnit(MILLISECONDS)
47+
@BenchmarkMode(AverageTime)
48+
@Fork(3)
49+
@Warmup(iterations = 10)
50+
@Measurement(iterations = 10)
51+
public class BenchmarkReorderJoinsConnectedGraph
52+
{
53+
@Benchmark
54+
public MaterializedResult benchmarkReorderJoins(BenchmarkInfo benchmarkInfo)
55+
{
56+
return benchmarkInfo.getQueryRunner().execute(benchmarkInfo.getQuery());
57+
}
58+
59+
@State(Thread)
60+
public static class BenchmarkInfo
61+
{
62+
@Param({"ELIMINATE_CROSS_JOINS", "COST_BASED"})
63+
private String joinReorderingStrategy;
64+
65+
@Param({"2", "4", "6", "8", "10"})
66+
private int numberOfTables;
67+
68+
private String query;
69+
private LocalQueryRunner queryRunner;
70+
71+
@Setup
72+
public void setup()
73+
{
74+
checkState(numberOfTables >= 2, "numberOfTables must be >= 2");
75+
Session session = testSessionBuilder()
76+
.setSystemProperty("join_reordering_strategy", joinReorderingStrategy)
77+
.setSystemProperty("join_distribution_type", "AUTOMATIC")
78+
.setCatalog("tpch")
79+
.setSchema("tiny")
80+
.build();
81+
queryRunner = new LocalQueryRunner(session);
82+
queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
83+
StringBuilder stringBuilder = new StringBuilder();
84+
stringBuilder.append("EXPLAIN SELECT * FROM NATION n1");
85+
for (int i = 2; i <= numberOfTables; i++) {
86+
stringBuilder.append(format(" JOIN nation n%s on n%s.nationkey = n%s.nationkey", i, i - 1, i));
87+
}
88+
query = stringBuilder.toString();
89+
}
90+
91+
public String getQuery()
92+
{
93+
return query;
94+
}
95+
96+
public QueryRunner getQueryRunner()
97+
{
98+
return queryRunner;
99+
}
100+
101+
@TearDown
102+
public void tearDown()
103+
{
104+
queryRunner.close();
105+
}
106+
}
107+
108+
public static void main(String[] args)
109+
throws RunnerException
110+
{
111+
Options options = new OptionsBuilder()
112+
.verbosity(VerboseMode.NORMAL)
113+
.include(".*" + BenchmarkReorderJoinsConnectedGraph.class.getSimpleName() + ".*")
114+
.build();
115+
116+
new Runner(options).run();
117+
}
118+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.sql.planner.iterative.rule;
15+
16+
import com.facebook.presto.Session;
17+
import com.facebook.presto.testing.LocalQueryRunner;
18+
import com.facebook.presto.testing.MaterializedResult;
19+
import com.facebook.presto.testing.QueryRunner;
20+
import com.facebook.presto.tpch.TpchConnectorFactory;
21+
import com.google.common.collect.ImmutableMap;
22+
import org.openjdk.jmh.annotations.Benchmark;
23+
import org.openjdk.jmh.annotations.BenchmarkMode;
24+
import org.openjdk.jmh.annotations.Fork;
25+
import org.openjdk.jmh.annotations.Measurement;
26+
import org.openjdk.jmh.annotations.OutputTimeUnit;
27+
import org.openjdk.jmh.annotations.Param;
28+
import org.openjdk.jmh.annotations.Setup;
29+
import org.openjdk.jmh.annotations.State;
30+
import org.openjdk.jmh.annotations.TearDown;
31+
import org.openjdk.jmh.annotations.Warmup;
32+
import org.openjdk.jmh.runner.Runner;
33+
import org.openjdk.jmh.runner.RunnerException;
34+
import org.openjdk.jmh.runner.options.Options;
35+
import org.openjdk.jmh.runner.options.OptionsBuilder;
36+
import org.openjdk.jmh.runner.options.VerboseMode;
37+
38+
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
39+
import static java.util.concurrent.TimeUnit.MILLISECONDS;
40+
import static org.openjdk.jmh.annotations.Mode.AverageTime;
41+
import static org.openjdk.jmh.annotations.Scope.Thread;
42+
43+
@State(Thread)
44+
@OutputTimeUnit(MILLISECONDS)
45+
@BenchmarkMode(AverageTime)
46+
@Fork(3)
47+
@Warmup(iterations = 10)
48+
@Measurement(iterations = 10)
49+
public class BenchmarkReorderJoinsLinearGraph
50+
{
51+
@Benchmark
52+
public MaterializedResult benchmarkReorderJoins(BenchmarkInfo benchmarkInfo)
53+
{
54+
return benchmarkInfo.getQueryRunner().execute(
55+
"EXPLAIN SELECT * FROM " +
56+
"nation n1 JOIN nation n2 ON n1.nationkey = n2.nationkey " +
57+
"JOIN nation n3 on n2.comment = n3.comment " +
58+
"JOIN nation n4 on n3.name = n4.name " +
59+
"JOIN region r1 on n4.regionkey = r1.regionkey " +
60+
"JOIN region r2 on r2.name = r2.name " +
61+
"JOIN region r3 on r3.comment = r2.comment " +
62+
"join region r4 on r4.regionkey = r3.regionkey");
63+
}
64+
65+
@State(Thread)
66+
public static class BenchmarkInfo
67+
{
68+
@Param({"ELIMINATE_CROSS_JOINS", "COST_BASED"})
69+
private String joinReorderingStrategy;
70+
71+
private LocalQueryRunner queryRunner;
72+
73+
@Setup
74+
public void setup()
75+
{
76+
Session session = testSessionBuilder()
77+
.setSystemProperty("join_reordering_strategy", joinReorderingStrategy)
78+
.setSystemProperty("join_distribution_type", "AUTOMATIC")
79+
.setCatalog("tpch")
80+
.setSchema("tiny")
81+
.build();
82+
queryRunner = new LocalQueryRunner(session);
83+
queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of());
84+
}
85+
86+
public QueryRunner getQueryRunner()
87+
{
88+
return queryRunner;
89+
}
90+
91+
@TearDown
92+
public void tearDown()
93+
{
94+
queryRunner.close();
95+
}
96+
}
97+
98+
public static void main(String[] args)
99+
throws RunnerException
100+
{
101+
Options options = new OptionsBuilder()
102+
.verbosity(VerboseMode.NORMAL)
103+
.include(".*" + BenchmarkReorderJoinsLinearGraph.class.getSimpleName() + ".*")
104+
.build();
105+
106+
new Runner(options).run();
107+
}
108+
}

0 commit comments

Comments
 (0)