From 844fe2d2504058460aa5a40e65ff1b7a3bdbe37a Mon Sep 17 00:00:00 2001 From: Rebecca Schlussel Date: Thu, 29 Jun 2017 14:03:47 -0400 Subject: [PATCH] Add benchmark for ReorderJoins rule MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../BenchmarkReorderJoinsConnectedGraph.java | 118 ++++++++++++++++++ .../BenchmarkReorderJoinsLinearGraph.java | 108 ++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsConnectedGraph.java create mode 100644 presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsLinearGraph.java diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsConnectedGraph.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsConnectedGraph.java new file mode 100644 index 000000000000..d6fb0ea483d0 --- /dev/null +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsConnectedGraph.java @@ -0,0 +1,118 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.sql.planner.iterative.rule; + +import com.facebook.presto.Session; +import com.facebook.presto.testing.LocalQueryRunner; +import com.facebook.presto.testing.MaterializedResult; +import com.facebook.presto.testing.QueryRunner; +import com.facebook.presto.tpch.TpchConnectorFactory; +import com.google.common.collect.ImmutableMap; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.VerboseMode; + +import static com.facebook.presto.testing.TestingSession.testSessionBuilder; +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.openjdk.jmh.annotations.Mode.AverageTime; +import static org.openjdk.jmh.annotations.Scope.Thread; + +@State(Thread) +@OutputTimeUnit(MILLISECONDS) +@BenchmarkMode(AverageTime) +@Fork(3) +@Warmup(iterations = 10) +@Measurement(iterations = 10) +public class BenchmarkReorderJoinsConnectedGraph +{ + @Benchmark + public MaterializedResult benchmarkReorderJoins(BenchmarkInfo benchmarkInfo) + { + return benchmarkInfo.getQueryRunner().execute(benchmarkInfo.getQuery()); + } + + @State(Thread) + public static class BenchmarkInfo + { + @Param({"ELIMINATE_CROSS_JOINS", "COST_BASED"}) + private String joinReorderingStrategy; + + @Param({"2", "4", "6", "8", "10"}) + private int numberOfTables; + + private String query; + private LocalQueryRunner queryRunner; + + @Setup + public void setup() + { + checkState(numberOfTables >= 2, "numberOfTables must be >= 2"); + Session session = testSessionBuilder() + .setSystemProperty("join_reordering_strategy", joinReorderingStrategy) + .setSystemProperty("join_distribution_type", "AUTOMATIC") + .setCatalog("tpch") + .setSchema("tiny") + .build(); + queryRunner = new LocalQueryRunner(session); + queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of()); + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("EXPLAIN SELECT * FROM NATION n1"); + for (int i = 2; i <= numberOfTables; i++) { + stringBuilder.append(format(" JOIN nation n%s on n%s.nationkey = n%s.nationkey", i, i - 1, i)); + } + query = stringBuilder.toString(); + } + + public String getQuery() + { + return query; + } + + public QueryRunner getQueryRunner() + { + return queryRunner; + } + + @TearDown + public void tearDown() + { + queryRunner.close(); + } + } + + public static void main(String[] args) + throws RunnerException + { + Options options = new OptionsBuilder() + .verbosity(VerboseMode.NORMAL) + .include(".*" + BenchmarkReorderJoinsConnectedGraph.class.getSimpleName() + ".*") + .build(); + + new Runner(options).run(); + } +} diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsLinearGraph.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsLinearGraph.java new file mode 100644 index 000000000000..13c1644c1785 --- /dev/null +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/iterative/rule/BenchmarkReorderJoinsLinearGraph.java @@ -0,0 +1,108 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.sql.planner.iterative.rule; + +import com.facebook.presto.Session; +import com.facebook.presto.testing.LocalQueryRunner; +import com.facebook.presto.testing.MaterializedResult; +import com.facebook.presto.testing.QueryRunner; +import com.facebook.presto.tpch.TpchConnectorFactory; +import com.google.common.collect.ImmutableMap; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; +import org.openjdk.jmh.runner.options.VerboseMode; + +import static com.facebook.presto.testing.TestingSession.testSessionBuilder; +import static java.util.concurrent.TimeUnit.MILLISECONDS; +import static org.openjdk.jmh.annotations.Mode.AverageTime; +import static org.openjdk.jmh.annotations.Scope.Thread; + +@State(Thread) +@OutputTimeUnit(MILLISECONDS) +@BenchmarkMode(AverageTime) +@Fork(3) +@Warmup(iterations = 10) +@Measurement(iterations = 10) +public class BenchmarkReorderJoinsLinearGraph +{ + @Benchmark + public MaterializedResult benchmarkReorderJoins(BenchmarkInfo benchmarkInfo) + { + return benchmarkInfo.getQueryRunner().execute( + "EXPLAIN SELECT * FROM " + + "nation n1 JOIN nation n2 ON n1.nationkey = n2.nationkey " + + "JOIN nation n3 on n2.comment = n3.comment " + + "JOIN nation n4 on n3.name = n4.name " + + "JOIN region r1 on n4.regionkey = r1.regionkey " + + "JOIN region r2 on r2.name = r2.name " + + "JOIN region r3 on r3.comment = r2.comment " + + "join region r4 on r4.regionkey = r3.regionkey"); + } + + @State(Thread) + public static class BenchmarkInfo + { + @Param({"ELIMINATE_CROSS_JOINS", "COST_BASED"}) + private String joinReorderingStrategy; + + private LocalQueryRunner queryRunner; + + @Setup + public void setup() + { + Session session = testSessionBuilder() + .setSystemProperty("join_reordering_strategy", joinReorderingStrategy) + .setSystemProperty("join_distribution_type", "AUTOMATIC") + .setCatalog("tpch") + .setSchema("tiny") + .build(); + queryRunner = new LocalQueryRunner(session); + queryRunner.createCatalog("tpch", new TpchConnectorFactory(1), ImmutableMap.of()); + } + + public QueryRunner getQueryRunner() + { + return queryRunner; + } + + @TearDown + public void tearDown() + { + queryRunner.close(); + } + } + + public static void main(String[] args) + throws RunnerException + { + Options options = new OptionsBuilder() + .verbosity(VerboseMode.NORMAL) + .include(".*" + BenchmarkReorderJoinsLinearGraph.class.getSimpleName() + ".*") + .build(); + + new Runner(options).run(); + } +}