forked from prestodb/presto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transformations of Existential Subqueries using Early-out Joins
Adds three optimizer rules: TransformUncorrelatedInPredicateSubqueryToDistinctInnerJoin - converts an in-predicate subquery into an inner join with distinct aggregation (logically equivalent to a semijoin) TransformDistinctInnerJoinToRightEarlyOutJoin - pushes aggregation into the left input of an inner join where applicable TransformDistinctInnerJoinToLeftEarlyOutJoin - converts an inner join with distinct aggregation into a semijoin Benchmarked on TPCDS(100G) data set. Queries impacted (9/100). Wallclock time performance improvement 10% for the impacted queries.
- Loading branch information
1 parent
d21bbc2
commit 5b1f2dd
Showing
25 changed files
with
1,820 additions
and
38 deletions.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
presto-benchmark/src/main/java/com/facebook/presto/benchmark/SqlEarlyOutJoinsBenchmarks.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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.benchmark; | ||
|
||
import com.facebook.airlift.log.Logger; | ||
import com.facebook.presto.testing.LocalQueryRunner; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.intellij.lang.annotations.Language; | ||
|
||
import java.util.Map; | ||
|
||
import static com.facebook.presto.SystemSessionProperties.EXPLOIT_CONSTRAINTS; | ||
import static com.facebook.presto.SystemSessionProperties.IN_PREDICATES_AS_INNER_JOINS_ENABLED; | ||
import static com.facebook.presto.SystemSessionProperties.PUSH_AGGREGATION_BELOW_JOIN_BYTE_REDUCTION_THRESHOLD; | ||
|
||
public class SqlEarlyOutJoinsBenchmarks | ||
extends AbstractSqlBenchmark | ||
{ | ||
private static final Logger LOGGER = Logger.get(SqlEarlyOutJoinsBenchmarks.class); | ||
|
||
private static Map<String, String> disableOptimization = ImmutableMap.of(IN_PREDICATES_AS_INNER_JOINS_ENABLED, Boolean.toString(false), | ||
EXPLOIT_CONSTRAINTS, Boolean.toString(true)); | ||
private static Map<String, String> enableOptimization = ImmutableMap.of(IN_PREDICATES_AS_INNER_JOINS_ENABLED, Boolean.toString(true), | ||
EXPLOIT_CONSTRAINTS, Boolean.toString(true)); | ||
|
||
public SqlEarlyOutJoinsBenchmarks(LocalQueryRunner localQueryRunner, @Language("SQL") String sql) | ||
{ | ||
super(localQueryRunner, "early_out_joins", 10, 10, sql); | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
benchmarkTransformDistinctInnerJoinToLeftEarlyOutJoin(); | ||
benchmarkTransformDistinctInnerJoinToRightEarlyOutJoin(); | ||
benchmarkRewriteOfInPredicateToDistinctInnerJoin(); | ||
} | ||
|
||
private static void benchmarkTransformDistinctInnerJoinToLeftEarlyOutJoin() | ||
{ | ||
LOGGER.info("benchmarkTransformDistinctInnerJoinToLeftEarlyOutJoin"); | ||
String sql = "select distinct orderkey from lineitem, nation where orderkey=nationkey"; | ||
LOGGER.info("Without optimization"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(disableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
LOGGER.info("With optimization"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(enableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
} | ||
|
||
private static void benchmarkTransformDistinctInnerJoinToRightEarlyOutJoin() | ||
{ | ||
LOGGER.info("benchmarkTransformDistinctInnerJoinToRightEarlyOutJoin"); | ||
String sql = "select distinct l.orderkey, l.comment from lineitem l, orders o where l.orderkey = o.orderkey"; | ||
LOGGER.info("Without optimization"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(disableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
LOGGER.info("With optimization"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(enableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
} | ||
|
||
private static void benchmarkRewriteOfInPredicateToDistinctInnerJoin() | ||
{ | ||
LOGGER.info("benchmarkInPredicateToDistinctInnerJoin"); | ||
LOGGER.info("Case 1: Rewrite IN predicate to distinct + inner join"); | ||
String sql = " explain select * from region where regionkey in (select orderkey from lineitem)"; | ||
LOGGER.info("Without optimization"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(disableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
LOGGER.info("With optimization: case 1"); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(enableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
|
||
LOGGER.info("Case 2: Rewrite IN predicate to distinct + inner join and then push aggregation down into the probe of the join"); | ||
//Use same query as previous and change the byte reduction threshold | ||
LOGGER.info("With optimization: case 2"); | ||
Map<String, String> alteredByteReductionThreshold = ImmutableMap.<String, String>builder() | ||
.putAll(enableOptimization) | ||
.put(PUSH_AGGREGATION_BELOW_JOIN_BYTE_REDUCTION_THRESHOLD, "0.001") | ||
.build(); | ||
new SqlEarlyOutJoinsBenchmarks(BenchmarkQueryRunner.createLocalQueryRunner(enableOptimization), sql).runBenchmark(new SimpleLineBenchmarkResultWriter(System.out)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.