Skip to content

Commit

Permalink
Add MySQL automatic cost based JOIN pushdown support
Browse files Browse the repository at this point in the history
  • Loading branch information
wendigo authored and findepi committed Apr 1, 2022
1 parent 126fcc0 commit f5c627a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Expand Up @@ -112,6 +112,7 @@
import static io.trino.plugin.jdbc.DecimalSessionSessionProperties.getDecimalRounding;
import static io.trino.plugin.jdbc.DecimalSessionSessionProperties.getDecimalRoundingMode;
import static io.trino.plugin.jdbc.JdbcErrorCode.JDBC_ERROR;
import static io.trino.plugin.jdbc.JdbcJoinPushdownUtil.implementJoinCostAware;
import static io.trino.plugin.jdbc.PredicatePushdownController.DISABLE_PUSHDOWN;
import static io.trino.plugin.jdbc.PredicatePushdownController.FULL_PUSHDOWN;
import static io.trino.plugin.jdbc.StandardColumnMappings.bigintColumnMapping;
Expand Down Expand Up @@ -704,7 +705,13 @@ public Optional<PreparedQuery> implementJoin(
// Not supported in MySQL
return Optional.empty();
}
return super.implementJoin(session, joinType, leftSource, rightSource, joinConditions, rightAssignments, leftAssignments, statistics);
return implementJoinCostAware(
session,
joinType,
leftSource,
rightSource,
statistics,
() -> super.implementJoin(session, joinType, leftSource, rightSource, joinConditions, rightAssignments, leftAssignments, statistics));
}

@Override
Expand Down
Expand Up @@ -14,17 +14,18 @@
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;

Expand All @@ -34,16 +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);
configBinder(binder).bindConfig(JdbcStatisticsConfig.class);
binder.install(new DecimalModule());
install(new DecimalModule());
install(new JdbcJoinPushdownSupportModule());
}

@Provides
Expand Down
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();
}
}
Expand Up @@ -76,9 +76,7 @@ protected QueryRunner createQueryRunner()
return createMySqlQueryRunner(
mysqlServer,
Map.of(),
Map.of(
"case-insensitive-name-matching", "true",
"join-pushdown.enabled", "true"),
Map.of("case-insensitive-name-matching", "true"),
List.of(ORDERS));
}

Expand Down

0 comments on commit f5c627a

Please sign in to comment.