New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eliminate unnecessary cross joins #6395

Closed
wants to merge 12 commits into
base: master
from

Add tests for cross joins elimination

  • Loading branch information...
pnowojski committed Oct 14, 2016
commit 8b26e4dbec1101a5b721fc76004f08d8fcd1e39f
@@ -0,0 +1,64 @@
/*
* 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.optimizations;
import com.facebook.presto.SystemSessionProperties;
import com.facebook.presto.sql.planner.assertions.BasePlanTest;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import org.testng.annotations.Test;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.anyTree;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.equiJoinClause;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.join;
import static com.facebook.presto.sql.planner.assertions.PlanMatchPattern.tableScan;
import static com.facebook.presto.sql.planner.plan.JoinNode.Type.INNER;
public class TestReorderJoins
extends BasePlanTest
{
public TestReorderJoins()
{
super(ImmutableMap.of(SystemSessionProperties.REORDER_JOINS, "true"));
}
@Test
public void testEliminateSimpleCrossJoin()
{
assertPlan("SELECT o.orderkey FROM part p, orders o, lineitem l WHERE p.partkey = l.partkey AND l.orderkey = o.orderkey",
anyTree(
join(INNER, ImmutableList.of(equiJoinClause("L_ORDERKEY", "O_ORDERKEY")),
anyTree(
join(INNER, ImmutableList.of(equiJoinClause("P_PARTKEY", "L_PARTKEY")),
anyTree(tableScan("part", ImmutableMap.of("P_PARTKEY", "partkey"))),
anyTree(tableScan("lineitem", ImmutableMap.of(
"L_PARTKEY", "partkey",
"L_ORDERKEY", "orderkey"))))),
anyTree(tableScan("orders", ImmutableMap.of("O_ORDERKEY", "orderkey"))))));
}
@Test
public void testGiveUpOnCrossJoin()
{
assertPlan("SELECT o.orderkey FROM part p, orders o, lineitem l WHERE l.orderkey = o.orderkey",
anyTree(
join(INNER, ImmutableList.of(equiJoinClause("O_ORDERKEY", "L_ORDERKEY")),
anyTree(
join(INNER, ImmutableList.of(),
tableScan("part"),
anyTree(tableScan("orders", ImmutableMap.of("O_ORDERKEY", "orderkey"))))),
anyTree(tableScan("lineitem", ImmutableMap.of("L_ORDERKEY", "orderkey"))))));
}
}
@@ -20,6 +20,7 @@
import com.facebook.presto.tpch.TpchConnectorFactory;
import com.google.common.collect.ImmutableMap;
import static com.facebook.presto.SystemSessionProperties.REORDER_JOINS;
import static com.facebook.presto.testing.TestingSession.TESTING_CATALOG;
import static com.facebook.presto.testing.TestingSession.testSessionBuilder;
import static com.facebook.presto.tpch.TpchMetadata.TINY_SCHEMA_NAME;
@@ -37,6 +38,7 @@ public static LocalQueryRunner createLocalQueryRunner()
Session defaultSession = testSessionBuilder()
.setCatalog("local")
.setSchema(TINY_SCHEMA_NAME)
.setSystemProperty(REORDER_JOINS, "true")
.build();
LocalQueryRunner localQueryRunner = new LocalQueryRunner(defaultSession);
ProTip! Use n and p to navigate between commits in a pull request.