Search in sources :

Example 1 with JOIN_REORDERING_STRATEGY

use of io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY in project trino by trinodb.

the class AbstractTestJoinQueries method assertJoinOutputPositions.

private void assertJoinOutputPositions(@Language("SQL") String sql, int expectedJoinOutputPositions) {
    ResultWithQueryId<MaterializedResult> result = getDistributedQueryRunner().executeWithQueryId(Session.builder(getSession()).setSystemProperty(JOIN_REORDERING_STRATEGY, "NONE").build(), sql);
    assertEquals(result.getResult().getMaterializedRows().get(0).getField(0), 0L);
    QueryStats stats = getDistributedQueryRunner().getCoordinator().getQueryManager().getFullQueryInfo(result.getQueryId()).getQueryStats();
    int actualJoinOutputPositions = stats.getOperatorSummaries().stream().filter(summary -> summary.getOperatorType().equals("LookupJoinOperator")).map(OperatorStats::getOutputPositions).mapToInt(Math::toIntExact).sum();
    assertEquals(actualJoinOutputPositions, expectedJoinOutputPositions);
}
Also used : NATION(io.trino.tpch.TpchTable.NATION) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) ORDERS(io.trino.tpch.TpchTable.ORDERS) QueryTemplate.parameter(io.trino.tests.QueryTemplate.parameter) CUSTOMER(io.trino.tpch.TpchTable.CUSTOMER) QueryAssertions.assertEqualsIgnoreOrder(io.trino.testing.QueryAssertions.assertEqualsIgnoreOrder) ImmutableList(com.google.common.collect.ImmutableList) SystemSessionProperties(io.trino.SystemSessionProperties) JOIN_REORDERING_STRATEGY(io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY) TpchTable(io.trino.tpch.TpchTable) PART(io.trino.tpch.TpchTable.PART) QueryTemplate(io.trino.tests.QueryTemplate) OperatorStats(io.trino.operator.OperatorStats) Language(org.intellij.lang.annotations.Language) REGION(io.trino.tpch.TpchTable.REGION) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) QueryTemplate.queryTemplate(io.trino.tests.QueryTemplate.queryTemplate) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) String.format(java.lang.String.format) List(java.util.List) QueryStats(io.trino.execution.QueryStats) BIGINT(io.trino.spi.type.BigintType.BIGINT) Decimals(io.trino.spi.type.Decimals) Assert.assertTrue(org.testng.Assert.assertTrue) LINE_ITEM(io.trino.tpch.TpchTable.LINE_ITEM) Session(io.trino.Session) MaterializedResult.resultBuilder(io.trino.testing.MaterializedResult.resultBuilder) QueryStats(io.trino.execution.QueryStats) OperatorStats(io.trino.operator.OperatorStats)

Example 2 with JOIN_REORDERING_STRATEGY

use of io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY in project trino by trinodb.

the class TestReorderJoins method testReorderAndReplicate.

@Test
public void testReorderAndReplicate() {
    // variable width so that average row size is respected
    Type symbolType = createUnboundedVarcharType();
    int aRows = 10;
    int bRows = 10_000;
    PlanNodeStatsEstimate probeSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(aRows).addSymbolStatistics(ImmutableMap.of(new Symbol("A1"), new SymbolStatsEstimate(0, 100, 0, 640000, 10))).build();
    PlanNodeStatsEstimate buildSideStatsEstimate = PlanNodeStatsEstimate.builder().setOutputRowCount(bRows).addSymbolStatistics(ImmutableMap.of(new Symbol("B1"), new SymbolStatsEstimate(0, 100, 0, 640000, 10))).build();
    // A table is small enough to be replicated in AUTOMATIC_RESTRICTED mode
    assertReorderJoins().setSystemProperty(JOIN_DISTRIBUTION_TYPE, AUTOMATIC.name()).setSystemProperty(JOIN_REORDERING_STRATEGY, AUTOMATIC.name()).setSystemProperty(JOIN_MAX_BROADCAST_TABLE_SIZE, "10MB").on(p -> {
        Symbol a1 = p.symbol("A1", symbolType);
        Symbol b1 = p.symbol("B1", symbolType);
        return p.join(INNER, p.values(new PlanNodeId("valuesA"), aRows, a1), p.values(new PlanNodeId("valuesB"), bRows, b1), ImmutableList.of(new EquiJoinClause(a1, b1)), ImmutableList.of(a1), ImmutableList.of(b1), Optional.empty());
    }).overrideStats("valuesA", probeSideStatsEstimate).overrideStats("valuesB", buildSideStatsEstimate).matches(join(INNER, ImmutableList.of(equiJoinClause("B1", "A1")), Optional.empty(), Optional.of(REPLICATED), values(ImmutableMap.of("B1", 0)), values(ImmutableMap.of("A1", 0))));
}
Also used : TypeAnalyzer.createTestingTypeAnalyzer(io.trino.sql.planner.TypeAnalyzer.createTestingTypeAnalyzer) PARTITIONED(io.trino.sql.planner.plan.JoinNode.DistributionType.PARTITIONED) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) TestingFunctionResolution(io.trino.metadata.TestingFunctionResolution) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) PlanMatchPattern(io.trino.sql.planner.assertions.PlanMatchPattern) Test(org.testng.annotations.Test) REPLICATED(io.trino.sql.planner.plan.JoinNode.DistributionType.REPLICATED) BROADCAST(io.trino.sql.planner.OptimizerConfig.JoinDistributionType.BROADCAST) RuleAssert(io.trino.sql.planner.iterative.rule.test.RuleAssert) ImmutableList(com.google.common.collect.ImmutableList) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) JoinReorderingStrategy(io.trino.sql.planner.OptimizerConfig.JoinReorderingStrategy) ArithmeticUnaryExpression(io.trino.sql.tree.ArithmeticUnaryExpression) PlanMatchPattern.equiJoinClause(io.trino.sql.planner.assertions.PlanMatchPattern.equiJoinClause) AUTOMATIC(io.trino.sql.planner.OptimizerConfig.JoinDistributionType.AUTOMATIC) JOIN_REORDERING_STRATEGY(io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY) PlanMatchPattern.join(io.trino.sql.planner.assertions.PlanMatchPattern.join) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) JOIN_MAX_BROADCAST_TABLE_SIZE(io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE) Symbol(io.trino.sql.planner.Symbol) AfterClass(org.testng.annotations.AfterClass) PlanMatchPattern.expression(io.trino.sql.planner.assertions.PlanMatchPattern.expression) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) RuleTester.defaultRuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester.defaultRuleTester) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) Assignments(io.trino.sql.planner.plan.Assignments) RuleTester(io.trino.sql.planner.iterative.rule.test.RuleTester) PlanMatchPattern.values(io.trino.sql.planner.assertions.PlanMatchPattern.values) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) CostComparator(io.trino.cost.CostComparator) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) QualifiedName(io.trino.sql.tree.QualifiedName) EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.EQUAL) Closeables.closeAllRuntimeException(io.airlift.testing.Closeables.closeAllRuntimeException) PlanMatchPattern.strictProject(io.trino.sql.planner.assertions.PlanMatchPattern.strictProject) PLANNER_CONTEXT(io.trino.sql.planner.TestingPlannerContext.PLANNER_CONTEXT) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) Optional(java.util.Optional) MINUS(io.trino.sql.tree.ArithmeticUnaryExpression.Sign.MINUS) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) VarcharType.createUnboundedVarcharType(io.trino.spi.type.VarcharType.createUnboundedVarcharType) JoinDistributionType(io.trino.sql.planner.OptimizerConfig.JoinDistributionType) PlanNodeStatsEstimate(io.trino.cost.PlanNodeStatsEstimate) Symbol(io.trino.sql.planner.Symbol) EquiJoinClause(io.trino.sql.planner.plan.JoinNode.EquiJoinClause) SymbolStatsEstimate(io.trino.cost.SymbolStatsEstimate) Test(org.testng.annotations.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 JOIN_REORDERING_STRATEGY (io.trino.SystemSessionProperties.JOIN_REORDERING_STRATEGY)2 JoinDistributionType (io.trino.sql.planner.OptimizerConfig.JoinDistributionType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)1 Closeables.closeAllRuntimeException (io.airlift.testing.Closeables.closeAllRuntimeException)1 Session (io.trino.Session)1 SystemSessionProperties (io.trino.SystemSessionProperties)1 JOIN_DISTRIBUTION_TYPE (io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE)1 JOIN_MAX_BROADCAST_TABLE_SIZE (io.trino.SystemSessionProperties.JOIN_MAX_BROADCAST_TABLE_SIZE)1 CostComparator (io.trino.cost.CostComparator)1 PlanNodeStatsEstimate (io.trino.cost.PlanNodeStatsEstimate)1 SymbolStatsEstimate (io.trino.cost.SymbolStatsEstimate)1 QueryStats (io.trino.execution.QueryStats)1 TestingFunctionResolution (io.trino.metadata.TestingFunctionResolution)1 OperatorStats (io.trino.operator.OperatorStats)1 BIGINT (io.trino.spi.type.BigintType.BIGINT)1 Decimals (io.trino.spi.type.Decimals)1 Type (io.trino.spi.type.Type)1 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)1