Search in sources :

Example 6 with ServerConfig

use of io.mycat.config.ServerConfig in project Mycat2 by MyCATApache.

the class SQLRBORewriter method pushDownJoinByNormalTableOrGlobalTable.

private static Optional<RelNode> pushDownJoinByNormalTableOrGlobalTable(Join join, MycatView left, MycatView right) {
    Distribution ldistribution = left.getDistribution();
    Distribution rdistribution = right.getDistribution();
    Distribution.Type lType = ldistribution.type();
    Distribution.Type rType = rdistribution.type();
    boolean asBroadcast = ldistribution.canAsBroadcast(rdistribution);
    if (lType == Distribution.Type.SHARDING && (rType == Distribution.Type.BROADCAST || rType == Distribution.Type.PHY && asBroadcast)) {
        switch(join.getJoinType()) {
            case INNER:
            case LEFT:
            case SEMI:
            case ANTI:
                break;
            case RIGHT:
                RelHint lastPushJoinHint = HintTools.getLastPushJoinHint(join.getHints());
                if (lastPushJoinHint != null) {
                    if ("push_down_join_broadcast".equalsIgnoreCase(lastPushJoinHint.hintName)) {
                        break;
                    }
                }
                ServerConfig serverConfig = getServerConfig();
                if (serverConfig.isForcedPushDownBroadcast()) {
                    break;
                }
                return Optional.empty();
            case FULL:
                return Optional.empty();
        }
    } else if ((lType == Distribution.Type.BROADCAST || lType == Distribution.Type.PHY && asBroadcast) && rType == Distribution.Type.SHARDING) {
        switch(join.getJoinType()) {
            case INNER:
            case RIGHT:
                break;
            case SEMI:
            case ANTI:
            case LEFT:
                RelHint lastPushJoinHint = HintTools.getLastPushJoinHint(join.getHints());
                if (lastPushJoinHint != null) {
                    if ("push_down_join_broadcast".equalsIgnoreCase(lastPushJoinHint.hintName)) {
                        break;
                    }
                }
                ServerConfig serverConfig = getServerConfig();
                if (serverConfig.isForcedPushDownBroadcast()) {
                    break;
                }
                return Optional.empty();
            case FULL:
                return Optional.empty();
        }
    } else if (lType == Distribution.Type.PHY && rType == Distribution.Type.BROADCAST || (lType == Distribution.Type.BROADCAST && rType == Distribution.Type.PHY)) {
        switch(join.getJoinType()) {
            case INNER:
            case LEFT:
            case SEMI:
            case ANTI:
            case RIGHT:
                break;
            case FULL:
                return Optional.empty();
        }
    } else if (lType == Distribution.Type.PHY && rType == Distribution.Type.PHY) {
    } else if (lType == Distribution.Type.BROADCAST && rType == Distribution.Type.BROADCAST) {
    } else {
        return Optional.empty();
    }
    return ldistribution.join(rdistribution).map(distribution -> MycatView.ofBottom(join.copy(join.getTraitSet(), ImmutableList.of(left.getRelNode(), right.getRelNode())), distribution));
}
Also used : ServerConfig(io.mycat.config.ServerConfig) RelHint(org.apache.calcite.rel.hint.RelHint)

Aggregations

ServerConfig (io.mycat.config.ServerConfig)6 DruidDatasourceProvider (io.mycat.datasource.jdbc.DruidDatasourceProvider)3 SchemaHandler (io.mycat.calcite.table.SchemaHandler)2 ClusterConfig (io.mycat.config.ClusterConfig)2 DatasourceConfig (io.mycat.config.DatasourceConfig)2 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)2 LoadBalanceManager (io.mycat.plug.loadBalance.LoadBalanceManager)2 ReplicaSelectorManager (io.mycat.replica.ReplicaSelectorManager)2 NameMap (io.mycat.util.NameMap)2 SQLUtils (com.alibaba.druid.sql.SQLUtils)1 SQLExpr (com.alibaba.druid.sql.ast.SQLExpr)1 SQLStatement (com.alibaba.druid.sql.ast.SQLStatement)1 SQLVariantRefExpr (com.alibaba.druid.sql.ast.expr.SQLVariantRefExpr)1 SQLDeleteStatement (com.alibaba.druid.sql.ast.statement.SQLDeleteStatement)1 SQLInsertStatement (com.alibaba.druid.sql.ast.statement.SQLInsertStatement)1 SQLSelectStatement (com.alibaba.druid.sql.ast.statement.SQLSelectStatement)1 SQLUpdateStatement (com.alibaba.druid.sql.ast.statement.SQLUpdateStatement)1 MySqlKillStatement (com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlKillStatement)1 MySqlASTVisitorAdapter (com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitorAdapter)1 io.mycat (io.mycat)1