Search in sources :

Example 21 with INNER

use of io.trino.sql.planner.plan.JoinNode.Type.INNER in project trino by trinodb.

the class TestJoinStatsRule method testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction.

@Test
public void testStatsForInnerJoinWithTwoEquiClausesAndNonEqualityFunction() {
    // LEFT_JOIN_COLUMN_2 = RIGHT_JOIN_COLUMN_2 is the more selective clause
    double firstClauseSelectivity = 1.0 / LEFT_JOIN_COLUMN_2_NDV * LEFT_JOIN_COLUMN_2_NON_NULLS * RIGHT_JOIN_COLUMN_2_NON_NULLS;
    double secondClauseSelectivity = 1.0 / LEFT_JOIN_COLUMN_NDV * LEFT_JOIN_COLUMN_NON_NULLS * RIGHT_JOIN_COLUMN_NON_NULLS;
    double innerJoinRowCount = LEFT_ROWS_COUNT * RIGHT_ROWS_COUNT * firstClauseSelectivity * Math.pow(secondClauseSelectivity, 0.5) * // LEFT_JOIN_COLUMN < 10 non equality filter
    0.3333333333;
    PlanNodeStatsEstimate innerJoinStats = planNodeStats(innerJoinRowCount, symbolStatistics(LEFT_JOIN_COLUMN, 5.0, 10.0, 0.0, RIGHT_JOIN_COLUMN_NDV * 0.3333333333), symbolStatistics(RIGHT_JOIN_COLUMN, 5.0, 20.0, 0.0, RIGHT_JOIN_COLUMN_NDV), symbolStatistics(LEFT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV), symbolStatistics(RIGHT_JOIN_COLUMN_2, 100.0, 200.0, 0.0, RIGHT_JOIN_COLUMN_2_NDV));
    tester().assertStatsFor(testSessionBuilder().setSystemProperty(JOIN_MULTI_CLAUSE_INDEPENDENCE_FACTOR, "0.5").build(), pb -> {
        Symbol leftJoinColumnSymbol = pb.symbol(LEFT_JOIN_COLUMN, BIGINT);
        Symbol rightJoinColumnSymbol = pb.symbol(RIGHT_JOIN_COLUMN, DOUBLE);
        Symbol leftJoinColumnSymbol2 = pb.symbol(LEFT_JOIN_COLUMN_2, BIGINT);
        Symbol rightJoinColumnSymbol2 = pb.symbol(RIGHT_JOIN_COLUMN_2, DOUBLE);
        ComparisonExpression leftJoinColumnLessThanTen = new ComparisonExpression(ComparisonExpression.Operator.LESS_THAN, leftJoinColumnSymbol.toSymbolReference(), new LongLiteral("10"));
        return pb.join(INNER, pb.values(leftJoinColumnSymbol, leftJoinColumnSymbol2), pb.values(rightJoinColumnSymbol, rightJoinColumnSymbol2), ImmutableList.of(new EquiJoinClause(leftJoinColumnSymbol2, rightJoinColumnSymbol2), new EquiJoinClause(leftJoinColumnSymbol, rightJoinColumnSymbol)), ImmutableList.of(leftJoinColumnSymbol, leftJoinColumnSymbol2), ImmutableList.of(rightJoinColumnSymbol, rightJoinColumnSymbol2), Optional.of(leftJoinColumnLessThanTen));
    }).withSourceStats(0, planNodeStats(LEFT_ROWS_COUNT, LEFT_JOIN_COLUMN_STATS, LEFT_JOIN_COLUMN_2_STATS)).withSourceStats(1, planNodeStats(RIGHT_ROWS_COUNT, RIGHT_JOIN_COLUMN_STATS, RIGHT_JOIN_COLUMN_2_STATS)).check(stats -> stats.equalTo(innerJoinStats));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Type(io.trino.spi.type.Type) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) UNKNOWN_FILTER_COEFFICIENT(io.trino.cost.FilterStatsCalculator.UNKNOWN_FILTER_COEFFICIENT) Function(java.util.function.Function) PlanNode(io.trino.sql.planner.plan.PlanNode) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) ImmutableList(com.google.common.collect.ImmutableList) NaN(java.lang.Double.NaN) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) LongLiteral(io.trino.sql.tree.LongLiteral) JOIN_MULTI_CLAUSE_INDEPENDENCE_FACTOR(io.trino.SystemSessionProperties.JOIN_MULTI_CLAUSE_INDEPENDENCE_FACTOR) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) JoinNode(io.trino.sql.planner.plan.JoinNode) Symbol(io.trino.sql.planner.Symbol) ImmutableMap(com.google.common.collect.ImmutableMap) FULL(io.trino.sql.planner.plan.JoinNode.Type.FULL) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) DOUBLE(io.trino.spi.type.DoubleType.DOUBLE) PlanNodeStatsAssertion.assertThat(io.trino.cost.PlanNodeStatsAssertion.assertThat) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) BIGINT(io.trino.spi.type.BigintType.BIGINT) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) TypeProvider(io.trino.sql.planner.TypeProvider) Optional(java.util.Optional) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) LongLiteral(io.trino.sql.tree.LongLiteral) Symbol(io.trino.sql.planner.Symbol) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) Test(org.testng.annotations.Test)

Example 22 with INNER

use of io.trino.sql.planner.plan.JoinNode.Type.INNER in project trino by trinodb.

the class TestValidateAggregationsWithDefaultValues method testWithPartialAggregationBelowJoin.

@Test
public void testWithPartialAggregationBelowJoin() {
    Symbol symbol = new Symbol("symbol");
    PlanNode root = builder.aggregation(af -> af.step(FINAL).groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(builder.join(INNER, builder.exchange(e -> e.type(REPARTITION).scope(LOCAL).fixedHashDistributionParitioningScheme(ImmutableList.of(symbol), ImmutableList.of(symbol)).addInputsSet(symbol).addSource(builder.aggregation(ap -> ap.step(PARTIAL).groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(tableScanNode)))), builder.values())));
    validatePlan(root, true);
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) CatalogName(io.trino.connector.CatalogName) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PARTIAL(io.trino.sql.planner.plan.AggregationNode.Step.PARTIAL) Symbol(io.trino.sql.planner.Symbol) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) AggregationNode.groupingSets(io.trino.sql.planner.plan.AggregationNode.groupingSets) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.trino.execution.warnings.WarningCollector) TypeProvider(io.trino.sql.planner.TypeProvider) FINAL(io.trino.sql.planner.plan.AggregationNode.Step.FINAL) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlannerContext(io.trino.sql.PlannerContext) PlanNode(io.trino.sql.planner.plan.PlanNode) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 23 with INNER

use of io.trino.sql.planner.plan.JoinNode.Type.INNER in project trino by trinodb.

the class TestValidateAggregationsWithDefaultValues method testWithPartialAggregationBelowJoinWithoutSeparatingExchange.

@Test
public void testWithPartialAggregationBelowJoinWithoutSeparatingExchange() {
    Symbol symbol = new Symbol("symbol");
    PlanNode root = builder.aggregation(af -> af.step(FINAL).groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(builder.join(INNER, builder.aggregation(ap -> ap.step(PARTIAL).groupingSets(groupingSets(ImmutableList.of(symbol), 2, ImmutableSet.of(0))).source(tableScanNode)), builder.values())));
    assertThatThrownBy(() -> validatePlan(root, true)).isInstanceOf(IllegalArgumentException.class).hasMessage("Final aggregation with default value not separated from partial aggregation by local hash exchange");
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) CatalogName(io.trino.connector.CatalogName) ImmutableList(com.google.common.collect.ImmutableList) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TpchTableHandle(io.trino.plugin.tpch.TpchTableHandle) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) REPARTITION(io.trino.sql.planner.plan.ExchangeNode.Type.REPARTITION) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest) TableScanNode(io.trino.sql.planner.plan.TableScanNode) PARTIAL(io.trino.sql.planner.plan.AggregationNode.Step.PARTIAL) Symbol(io.trino.sql.planner.Symbol) TpchColumnHandle(io.trino.plugin.tpch.TpchColumnHandle) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) TestingTransactionHandle(io.trino.testing.TestingTransactionHandle) AggregationNode.groupingSets(io.trino.sql.planner.plan.AggregationNode.groupingSets) TableHandle(io.trino.metadata.TableHandle) BIGINT(io.trino.spi.type.BigintType.BIGINT) REMOTE(io.trino.sql.planner.plan.ExchangeNode.Scope.REMOTE) WarningCollector(io.trino.execution.warnings.WarningCollector) TypeProvider(io.trino.sql.planner.TypeProvider) FINAL(io.trino.sql.planner.plan.AggregationNode.Step.FINAL) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) PlannerContext(io.trino.sql.PlannerContext) PlanNode(io.trino.sql.planner.plan.PlanNode) Symbol(io.trino.sql.planner.Symbol) Test(org.testng.annotations.Test) BasePlanTest(io.trino.sql.planner.assertions.BasePlanTest)

Example 24 with INNER

use of io.trino.sql.planner.plan.JoinNode.Type.INNER in project trino by trinodb.

the class TestPushProjectionThroughJoin method testPushesProjectionThroughJoin.

@Test
public void testPushesProjectionThroughJoin() {
    PlanNodeIdAllocator idAllocator = new PlanNodeIdAllocator();
    PlanBuilder p = new PlanBuilder(idAllocator, dummyMetadata(), TEST_SESSION);
    Symbol a0 = p.symbol("a0");
    Symbol a1 = p.symbol("a1");
    Symbol a2 = p.symbol("a2");
    Symbol a3 = p.symbol("a3");
    Symbol b0 = p.symbol("b0");
    Symbol b1 = p.symbol("b1");
    Symbol b2 = p.symbol("b2");
    ProjectNode planNode = p.project(Assignments.of(a3, new ArithmeticUnaryExpression(MINUS, a2.toSymbolReference()), b2, new ArithmeticUnaryExpression(PLUS, b1.toSymbolReference())), p.join(INNER, // intermediate non-identity projections should be fully inlined
    p.project(Assignments.of(a2, new ArithmeticUnaryExpression(PLUS, a0.toSymbolReference()), a1, a1.toSymbolReference()), p.project(Assignments.builder().putIdentity(a0).putIdentity(a1).build(), p.values(a0, a1))), p.values(b0, b1), new JoinNode.EquiJoinClause(a1, b1)));
    Session session = testSessionBuilder().build();
    Optional<PlanNode> rewritten = pushProjectionThroughJoin(PLANNER_CONTEXT, planNode, noLookup(), idAllocator, session, createTestingTypeAnalyzer(PLANNER_CONTEXT), p.getTypes());
    assertTrue(rewritten.isPresent());
    assertPlan(session, dummyMetadata(), createTestingFunctionManager(), node -> unknown(), new Plan(rewritten.get(), p.getTypes(), empty()), noLookup(), join(INNER, ImmutableList.of(aliases -> new JoinNode.EquiJoinClause(new Symbol("a1"), new Symbol("b1"))), strictProject(ImmutableMap.of("a3", expression("-(+a0)"), "a1", expression("a1")), strictProject(ImmutableMap.of("a0", expression("a0"), "a1", expression("a1")), PlanMatchPattern.values("a0", "a1"))), strictProject(ImmutableMap.of("b2", expression("+b1"), "b1", expression("b1")), PlanMatchPattern.values("b0", "b1"))).withExactOutputs("a3", "b2"));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) PlanNode(io.trino.sql.planner.plan.PlanNode) Lookup.noLookup(io.trino.sql.planner.iterative.Lookup.noLookup) FunctionManager.createTestingFunctionManager(io.trino.metadata.FunctionManager.createTestingFunctionManager) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) ImmutableList(com.google.common.collect.ImmutableList) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) TEST_SESSION(io.trino.SessionTestUtils.TEST_SESSION) JoinNode(io.trino.sql.planner.plan.JoinNode) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticBinaryExpression(io.trino.sql.tree.ArithmeticBinaryExpression) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) PLUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.PLUS) Symbol(io.trino.sql.planner.Symbol) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) ImmutableMap(com.google.common.collect.ImmutableMap) Assignments(io.trino.sql.planner.plan.Assignments) AbstractMockMetadata.dummyMetadata(io.trino.metadata.AbstractMockMetadata.dummyMetadata) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) PushProjectionThroughJoin.pushProjectionThroughJoin(io.trino.sql.planner.iterative.rule.PushProjectionThroughJoin.pushProjectionThroughJoin) ADD(io.trino.sql.tree.ArithmeticBinaryExpression.Operator.ADD) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) PlanNodeStatsEstimate.unknown(io.trino.cost.PlanNodeStatsEstimate.unknown) StatsAndCosts.empty(io.trino.cost.StatsAndCosts.empty) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) Plan(io.trino.sql.planner.Plan) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Session(io.trino.Session) PlanNode(io.trino.sql.planner.plan.PlanNode) PlanNodeIdAllocator(io.trino.sql.planner.PlanNodeIdAllocator) Symbol(io.trino.sql.planner.Symbol) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanAssert.assertPlan(io.trino.sql.planner.assertions.PlanAssert.assertPlan) Plan(io.trino.sql.planner.Plan) PlanBuilder(io.trino.sql.planner.iterative.rule.test.PlanBuilder) Session(io.trino.Session) Test(org.testng.annotations.Test)

Aggregations

INNER (io.trino.sql.planner.plan.JoinNode.Type.INNER)24 ImmutableList (com.google.common.collect.ImmutableList)23 ImmutableMap (com.google.common.collect.ImmutableMap)23 Optional (java.util.Optional)22 Symbol (io.trino.sql.planner.Symbol)20 Test (org.testng.annotations.Test)20 PlanMatchPattern.join (io.trino.sql.planner.assertions.PlanMatchPattern.join)14 PlanMatchPattern.values (io.trino.sql.planner.assertions.PlanMatchPattern.values)14 BIGINT (io.trino.spi.type.BigintType.BIGINT)13 LEFT (io.trino.sql.planner.plan.JoinNode.Type.LEFT)13 PlanMatchPattern.equiJoinClause (io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause)12 AfterClass (org.testng.annotations.AfterClass)12 BeforeClass (org.testng.annotations.BeforeClass)12 PlanNodeIdAllocator (io.trino.sql.planner.PlanNodeIdAllocator)11 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)11 JOIN_DISTRIBUTION_TYPE (io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)10 JOIN_MAX_BROADCAST_TABLE_SIZE (io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE)10 CostComparator (io.trino.cost.CostComparator)10 PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)10 SymbolStatsEstimate (io.trino.cost.SymbolStatsEstimate)10