Skip to content
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

Add table statistics and automatic Join pushdown for MySQL connector #11638

Merged
merged 3 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions plugin/trino-mysql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<artifactId>configuration</artifactId>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>json</artifactId>
</dependency>

<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
Expand Down Expand Up @@ -73,6 +78,11 @@
<artifactId>mysql-connector-java</artifactId>
</dependency>

<dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi3-core</artifactId>
</dependency>

<!-- Trino SPI -->
<dependency>
<groupId>io.trino</groupId>
Expand Down Expand Up @@ -131,6 +141,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-testing-services</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.trino</groupId>
<artifactId>trino-tpch</artifactId>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
package io.trino.plugin.mysql;

import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.Scopes;
import com.google.inject.Singleton;
import com.mysql.jdbc.Driver;
import io.airlift.configuration.AbstractConfigurationAwareModule;
import io.trino.plugin.jdbc.BaseJdbcConfig;
import io.trino.plugin.jdbc.ConnectionFactory;
import io.trino.plugin.jdbc.DecimalModule;
import io.trino.plugin.jdbc.DriverConnectionFactory;
import io.trino.plugin.jdbc.ForBaseJdbc;
import io.trino.plugin.jdbc.JdbcClient;
import io.trino.plugin.jdbc.JdbcJoinPushdownSupportModule;
import io.trino.plugin.jdbc.JdbcStatisticsConfig;
import io.trino.plugin.jdbc.credential.CredentialProvider;

import java.sql.SQLException;
Expand All @@ -33,15 +35,17 @@
import static io.airlift.configuration.ConfigBinder.configBinder;

public class MySqlClientModule
implements Module
extends AbstractConfigurationAwareModule
{
@Override
public void configure(Binder binder)
protected void setup(Binder binder)
{
binder.bind(JdbcClient.class).annotatedWith(ForBaseJdbc.class).to(MySqlClient.class).in(Scopes.SINGLETON);
configBinder(binder).bindConfig(MySqlJdbcConfig.class);
configBinder(binder).bindConfig(MySqlConfig.class);
binder.install(new DecimalModule());
configBinder(binder).bindConfig(JdbcStatisticsConfig.class);
install(new DecimalModule());
install(new JdbcJoinPushdownSupportModule());
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,4 +392,13 @@ protected SqlExecutor onRemoteDatabase()
{
return mySqlServer::execute;
}

@Override
protected Session joinPushdownEnabled(Session session)
{
return Session.builder(super.joinPushdownEnabled(session))
// strategy is AUTOMATIC by default and would not work for certain test cases (even if statistics are collected)
.setCatalogSessionProperty(session.getCatalog().orElseThrow(), "join_pushdown_strategy", "EAGER")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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 io.trino.plugin.mysql;

import io.trino.testing.MaterializedRow;
import org.testng.SkipException;

import static java.lang.String.format;

public abstract class BaseMySqlTableStatisticsIndexStatisticsTest
extends BaseTestMySqlTableStatisticsTest
{
protected BaseMySqlTableStatisticsIndexStatisticsTest(String dockerImageName)
{
super(dockerImageName,
nullFraction -> 0.1, // Without histograms we have no way of knowing real null fraction, 10% is just a "wild guess"
varcharNdv -> null); // Without histograms we don't know cardinality for varchar columns
}

@Override
protected void gatherStats(String tableName)
{
for (MaterializedRow row : computeActual("SHOW COLUMNS FROM " + tableName)) {
String columnName = (String) row.getField(0);
String columnType = (String) row.getField(1);
if (columnType.startsWith("varchar")) {
continue;
}
executeInMysql(format("CREATE INDEX %2$s ON %1$s (%2$s)", tableName, columnName).replace("\"", "`"));
}
executeInMysql("ANALYZE TABLE " + tableName.replace("\"", "`"));
}

@Override
public void testStatsWithPredicatePushdownWithStatsPrecalculationDisabled()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithPredicatePushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithVarcharPredicatePushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithLimitPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithTopNPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithDistinctPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithDistinctLimitPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithAggregationPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithSimpleJoinPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}

@Override
public void testStatsWithJoinPushdown()
{
// TODO (https://github.com/trinodb/trino/issues/11664) implement the test for MySQL, with permissive approximate assertions
throw new SkipException("Test to be implemented");
}
}
Loading