Skip to content

Commit

Permalink
Add large IN predicate test in planner benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
lzeiming authored and sopel39 committed Apr 16, 2021
1 parent 7cc154c commit ca64719
Showing 1 changed file with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.trino.plugin.tpch.TpchConnectorFactory;
import io.trino.testing.LocalQueryRunner;
import io.trino.tpch.Customer;
import org.intellij.lang.annotations.Language;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
Expand Down Expand Up @@ -53,7 +54,9 @@
import static io.trino.testing.TestingSession.testSessionBuilder;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
import static java.util.stream.Collectors.joining;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

@SuppressWarnings("MethodMayBeStatic")
@State(Scope.Benchmark)
Expand All @@ -73,6 +76,8 @@ public static class BenchmarkData

private LocalQueryRunner queryRunner;
private List<String> queries;
@Language("SQL")
private String largeInQuery;
private Session session;

@Setup
Expand All @@ -93,6 +98,11 @@ public void setup()
.filter(i -> i != 15) // q15 has two queries in it
.map(i -> readResource(format("/io/trino/tpch/queries/q%d.sql", i)))
.collect(toImmutableList());

largeInQuery = "SELECT * from orders where o_orderkey in " +
IntStream.range(0, 5000)
.mapToObj(Integer::toString)
.collect(joining(", ", "(", ")"));
}

@TearDown
Expand Down Expand Up @@ -125,13 +135,24 @@ public List<Plan> planQueries(BenchmarkData benchmarkData)
});
}

@Benchmark
public Plan planLargeInQuery(BenchmarkData benchmarkData)
{
return benchmarkData.queryRunner.inTransaction(transactionSession -> {
LogicalPlanner.Stage stage = LogicalPlanner.Stage.valueOf(benchmarkData.stage.toUpperCase(ENGLISH));
return benchmarkData.queryRunner.createPlan(
transactionSession, benchmarkData.largeInQuery, stage, false, WarningCollector.NOOP);
});
}

@Test
public void verify()
{
BenchmarkData data = new BenchmarkData();
data.setup();
BenchmarkPlanner benchmark = new BenchmarkPlanner();
assertEquals(benchmark.planQueries(data).size(), 21);
assertNotNull(benchmark.planLargeInQuery(data));
}

public static void main(String[] args)
Expand Down

0 comments on commit ca64719

Please sign in to comment.