Repository: apache/shardingsphere
Issue: The tables with no configuration appear in the proxy.

The tables which are not configed in yaml can be used with show tables, select etc.
It is not correct, i will fix it in next week.

Changed files:
sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java
sharding-core/src/test/java/io/shardingsphere/core/merger/dal/DALMergeEngineTest.java
sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java
sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLExecuteBackendHandler.java
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java
sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLPacketsBackendHandler.java
sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResultTest.java
sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java
sharding-core/src/test/java/io/shardingsphere/core/merger/MergeEngineFactoryTest.java
sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/StatementExecuteBackendHandler.java
sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
sharding-core/src/main/java/io/shardingsphere/core/merger/MergeEngineFactory.java

diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/MergeEngineFactory.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/MergeEngineFactory.java
index 368247b6be0..6a06589465c 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/merger/MergeEngineFactory.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/MergeEngineFactory.java
@@ -19,6 +19,7 @@ package io.shardingsphere.core.merger;
 
 import io.shardingsphere.core.merger.dal.DALMergeEngine;
 import io.shardingsphere.core.merger.dql.DQLMergeEngine;
+import io.shardingsphere.core.metadata.ShardingMetaData;
 import io.shardingsphere.core.parsing.parser.sql.SQLStatement;
 import io.shardingsphere.core.parsing.parser.sql.dal.DALStatement;
 import io.shardingsphere.core.parsing.parser.sql.dql.select.SelectStatement;
@@ -33,6 +34,7 @@ import java.util.List;
  * Result merge engine factory.
  *
  * @author zhangliang
+ * @author panjuan
  */
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class MergeEngineFactory {
@@ -43,15 +45,17 @@ public final class MergeEngineFactory {
      * @param shardingRule sharding rule
      * @param queryResults query results
      * @param sqlStatement SQL statement
+     * @param shardingMetaData sharding meta Data
      * @return merge engine instance
      * @throws SQLException SQL exception
      */
-    public static MergeEngine newInstance(final ShardingRule shardingRule, final List<QueryResult> queryResults, final SQLStatement sqlStatement) throws SQLException {
+    public static MergeEngine newInstance(final ShardingRule shardingRule, final List<QueryResult> queryResults,
+                                          final SQLStatement sqlStatement, final ShardingMetaData shardingMetaData) throws SQLException {
         if (sqlStatement instanceof SelectStatement) {
             return new DQLMergeEngine(queryResults, (SelectStatement) sqlStatement);
         } 
         if (sqlStatement instanceof DALStatement) {
-            return new DALMergeEngine(shardingRule, queryResults, (DALStatement) sqlStatement);
+            return new DALMergeEngine(shardingRule, queryResults, (DALStatement) sqlStatement, shardingMetaData);
         }
         throw new UnsupportedOperationException(String.format("Cannot support type '%s'", sqlStatement.getType()));
     }
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java
index b8884613dfe..4f8104f227c 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/DALMergeEngine.java
@@ -24,6 +24,7 @@ import io.shardingsphere.core.merger.dal.show.ShowCreateTableMergedResult;
 import io.shardingsphere.core.merger.dal.show.ShowDatabasesMergedResult;
 import io.shardingsphere.core.merger.dal.show.ShowOtherMergedResult;
 import io.shardingsphere.core.merger.dal.show.ShowTablesMergedResult;
+import io.shardingsphere.core.metadata.ShardingMetaData;
 import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowCreateTableStatement;
 import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowDatabasesStatement;
 import io.shardingsphere.core.parsing.parser.dialect.mysql.statement.ShowTablesStatement;
@@ -38,6 +39,7 @@ import java.util.List;
  * DAL result set merge engine.
  *
  * @author zhangliang
+ * @author panjuan
  */
 @RequiredArgsConstructor
 public final class DALMergeEngine implements MergeEngine {
@@ -48,13 +50,15 @@ public final class DALMergeEngine implements MergeEngine {
     
     private final DALStatement dalStatement;
     
+    private final ShardingMetaData shardingMetaData;
+    
     @Override
     public MergedResult merge() throws SQLException {
         if (dalStatement instanceof ShowDatabasesStatement) {
             return new ShowDatabasesMergedResult();
         }
         if (dalStatement instanceof ShowTablesStatement) {
-            return new ShowTablesMergedResult(shardingRule, queryResults);
+            return new ShowTablesMergedResult(shardingRule, queryResults, shardingMetaData);
         }
         if (dalStatement instanceof ShowCreateTableStatement) {
             return new ShowCreateTableMergedResult(shardingRule, queryResults);
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java
index f49d373e053..4fa86199ee4 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResult.java
@@ -22,6 +22,7 @@ import io.shardingsphere.core.constant.ShardingConstant;
 import io.shardingsphere.core.merger.QueryResult;
 import io.shardingsphere.core.merger.dql.common.MemoryMergedResult;
 import io.shardingsphere.core.merger.dql.common.MemoryQueryResultRow;
+import io.shardingsphere.core.metadata.ShardingMetaData;
 import io.shardingsphere.core.rule.ShardingRule;
 import io.shardingsphere.core.rule.TableRule;
 
@@ -38,6 +39,7 @@ import java.util.Set;
  * Merged result for show tables.
  *
  * @author zhangliang
+ * @author panjuan
  */
 public final class ShowTablesMergedResult extends MemoryMergedResult {
     
@@ -49,13 +51,16 @@ public final class ShowTablesMergedResult extends MemoryMergedResult {
     
     private final Set<String> tableNames = new HashSet<>();
     
+    private final ShardingMetaData shardingMetaData;
+    
     static {
         LABEL_AND_INDEX_MAP.put("Tables_in_" + ShardingConstant.LOGIC_SCHEMA_NAME, 1); 
     }
     
-    public ShowTablesMergedResult(final ShardingRule shardingRule, final List<QueryResult> queryResults) throws SQLException {
+    public ShowTablesMergedResult(final ShardingRule shardingRule, final List<QueryResult> queryResults, final ShardingMetaData shardingMetaData) throws SQLException {
         super(LABEL_AND_INDEX_MAP);
         this.shardingRule = shardingRule;
+        this.shardingMetaData = shardingMetaData;
         memoryResultSetRows = init(queryResults);
     }
     
@@ -67,7 +72,11 @@ public final class ShowTablesMergedResult extends MemoryMergedResult {
                 String actualTableName = memoryResultSetRow.getCell(1).toString();
                 Optional<TableRule> tableRule = shardingRule.tryFindTableRuleByActualTable(actualTableName);
                 if (!tableRule.isPresent()) {
-                    result.add(memoryResultSetRow);
+                    if (shardingMetaData.getTableMetaDataMap().keySet().contains(actualTableName)) {
+                        result.add(memoryResultSetRow);
+                    } else if (!shardingMetaData.isSupportedDatabaseType()) {
+                        result.add(memoryResultSetRow);
+                    }
                 } else if (tableNames.add(tableRule.get().getLogicTable())) {
                     memoryResultSetRow.setCell(1, tableRule.get().getLogicTable());
                     result.add(memoryResultSetRow);
diff --git a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java
index 5fbef7e72c4..13f20104f69 100644
--- a/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java
+++ b/sharding-core/src/main/java/io/shardingsphere/core/metadata/ShardingMetaData.java
@@ -168,4 +168,18 @@ public abstract class ShardingMetaData {
         return String.format("Cannot get uniformed table structure for %s. The different metadata of actual tables is as follows:\\n%s\\n%s.",
                 logicTableName, oldTableMetaData.toString(), newTableMetaData.toString());
     }
+    
+    /**
+     * Judge whether this databaseType is supported.
+     *
+     * @return supported or not
+     */
+    public boolean isSupportedDatabaseType() {
+        for (TableMetaData each : tableMetaDataMap.values()) {
+            if (each.getColumnMetaData().isEmpty()) {
+                return false;
+            }
+        }
+        return true;
+    }
 }
diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/MergeEngineFactoryTest.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/MergeEngineFactoryTest.java
index 24af722058d..40128c9ec21 100644
--- a/sharding-core/src/test/java/io/shardingsphere/core/merger/MergeEngineFactoryTest.java
+++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/MergeEngineFactoryTest.java
@@ -58,18 +58,18 @@ public final class MergeEngineFactoryTest {
     @Test
     public void assertNewInstanceWithSelectStatement() throws SQLException {
         SQLStatement selectStatement = new SelectStatement();
-        assertThat(MergeEngineFactory.newInstance(null, queryResults, selectStatement), instanceOf(DQLMergeEngine.class));
+        assertThat(MergeEngineFactory.newInstance(null, queryResults, selectStatement, null), instanceOf(DQLMergeEngine.class));
     }
 
     @Test
     public void assertNewInstanceWithDALStatement() throws SQLException {
         SQLStatement dalStatement = new DALStatement();
-        assertThat(MergeEngineFactory.newInstance(null, queryResults, dalStatement), instanceOf(DALMergeEngine.class));
+        assertThat(MergeEngineFactory.newInstance(null, queryResults, dalStatement, null), instanceOf(DALMergeEngine.class));
     }
     
     @Test(expected = UnsupportedOperationException.class)
     public void assertNewInstanceWithOtherStatement() throws SQLException {
         SQLStatement insertStatement = new InsertStatement();
-        MergeEngineFactory.newInstance(null, queryResults, insertStatement);
+        MergeEngineFactory.newInstance(null, queryResults, insertStatement, null);
     }
 }
diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/DALMergeEngineTest.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/DALMergeEngineTest.java
index 9d870960ad0..99f312519cb 100644
--- a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/DALMergeEngineTest.java
+++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/DALMergeEngineTest.java
@@ -53,28 +53,28 @@ public final class DALMergeEngineTest {
     @Test
     public void assertMergeForShowDatabasesStatement() throws SQLException {
         DALStatement dalStatement = new ShowDatabasesStatement();
-        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
+        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement, null);
         assertThat(dalMergeEngine.merge(), instanceOf(ShowDatabasesMergedResult.class));
     }
     
     @Test
     public void assertMergeForShowShowTablesStatement() throws SQLException {
         DALStatement dalStatement = new ShowTablesStatement();
-        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
+        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement, null);
         assertThat(dalMergeEngine.merge(), instanceOf(ShowTablesMergedResult.class));
     }
     
     @Test
     public void assertMergeForShowCreateTableStatement() throws SQLException {
         DALStatement dalStatement = new ShowCreateTableStatement();
-        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
+        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement, null);
         assertThat(dalMergeEngine.merge(), instanceOf(ShowCreateTableMergedResult.class));
     }
     
     @Test
     public void assertMergeForShowOtherStatement() throws SQLException {
         DALStatement dalStatement = new ShowOtherStatement();
-        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement);
+        DALMergeEngine dalMergeEngine = new DALMergeEngine(null, queryResults, dalStatement, null);
         assertThat(dalMergeEngine.merge(), instanceOf(ShowOtherMergedResult.class));
     }
 }
diff --git a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResultTest.java b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResultTest.java
index 0222ce7cadc..d90a12b6394 100644
--- a/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResultTest.java
+++ b/sharding-core/src/test/java/io/shardingsphere/core/merger/dal/show/ShowTablesMergedResultTest.java
@@ -24,6 +24,8 @@ import io.shardingsphere.core.api.config.TableRuleConfiguration;
 import io.shardingsphere.core.api.config.strategy.ComplexShardingStrategyConfiguration;
 import io.shardingsphere.core.merger.QueryResult;
 import io.shardingsphere.core.merger.fixture.TestQueryResult;
+import io.shardingsphere.core.metadata.ShardingMetaData;
+import io.shardingsphere.core.metadata.TableMetaData;
 import io.shardingsphere.core.rule.ShardingRule;
 import org.junit.Before;
 import org.junit.Test;
@@ -32,10 +34,12 @@ import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -47,6 +51,8 @@ public final class ShowTablesMergedResultTest {
     
     private ResultSet resultSet;
     
+    private ShardingMetaData shardingMetaData;
+    
     @Before
     public void setUp() throws SQLException {
         TableRuleConfiguration tableRuleConfig = new TableRuleConfiguration();
@@ -56,6 +62,11 @@ public final class ShowTablesMergedResultTest {
         ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
         shardingRuleConfig.getTableRuleConfigs().add(tableRuleConfig);
         shardingRule = new ShardingRule(shardingRuleConfig, Lists.newArrayList("ds"));
+        shardingMetaData = mock(ShardingMetaData.class);
+        Map<String, TableMetaData> tableMetaDataMap = new HashMap<>();
+        tableMetaDataMap.put("table", new TableMetaData());
+        when(shardingMetaData.getTableMetaDataMap()).thenReturn(tableMetaDataMap);
+//        when(shardingMetaData.getTableMetaDataMap().keySet()).thenReturn(new HashSet<String>(){{add("table");}});
         
         resultSet = mock(ResultSet.class);
         ResultSetMetaData resultSetMetaData = mock(ResultSetMetaData.class);
@@ -73,21 +84,21 @@ public final class ShowTablesMergedResultTest {
     
     @Test
     public void assertNextForEmptyQueryResult() throws SQLException {
-        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, new ArrayList<QueryResult>());
+        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, new ArrayList<QueryResult>(), shardingMetaData);
         assertFalse(showTablesMergedResult.next());
     }
     
     @Test
     public void assertNextForActualTableNameInTableRule() throws SQLException {
         when(resultSet.getObject(1)).thenReturn("table_0");
-        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, queryResults);
+        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, queryResults, shardingMetaData);
         assertTrue(showTablesMergedResult.next());
     }
     
     @Test
     public void assertNextForActualTableNameNotInTableRule() throws SQLException {
         when(resultSet.getObject(1)).thenReturn("table_3");
-        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, queryResults);
+        ShowTablesMergedResult showTablesMergedResult = new ShowTablesMergedResult(shardingRule, queryResults, shardingMetaData);
         assertTrue(showTablesMergedResult.next());
     }
 }
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
index 9c102091c54..a2368fdde14 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingPreparedStatement.java
@@ -137,7 +137,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
             for (ResultSet each : resultSets) {
                 queryResults.add(new JDBCQueryResult(each));
             }
-            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
+            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(),
+                    queryResults, routeResult.getSqlStatement(), connection.getShardingContext().getShardingMetaData());
             result = new ShardingResultSet(resultSets, merge(mergeEngine), this);
         } finally {
             clearBatch();
@@ -305,7 +306,8 @@ public final class ShardingPreparedStatement extends AbstractShardingPreparedSta
             queryResults.add(new JDBCQueryResult(resultSet));
         }
         if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
-            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
+            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults,
+                    routeResult.getSqlStatement(), connection.getShardingContext().getShardingMetaData());
             currentResultSet = new ShardingResultSet(resultSets, merge(mergeEngine), this);
         }
         return currentResultSet;
diff --git a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
index d7f69f24fa3..f1ef5aa97e7 100644
--- a/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
+++ b/sharding-jdbc/src/main/java/io/shardingsphere/core/jdbc/core/statement/ShardingStatement.java
@@ -110,7 +110,8 @@ public class ShardingStatement extends AbstractStatementAdapter {
             for (ResultSet each : resultSets) {
                 queryResults.add(new JDBCQueryResult(each));
             }
-            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
+            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults,
+                    routeResult.getSqlStatement(), connection.getShardingContext().getShardingMetaData());
             result = new ShardingResultSet(resultSets, merge(mergeEngine), this);
         } finally {
             currentResultSet = null;
@@ -283,7 +284,8 @@ public class ShardingStatement extends AbstractStatementAdapter {
             queryResults.add(new JDBCQueryResult(resultSet));
         }
         if (routeResult.getSqlStatement() instanceof SelectStatement || routeResult.getSqlStatement() instanceof DALStatement) {
-            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults, routeResult.getSqlStatement());
+            MergeEngine mergeEngine = MergeEngineFactory.newInstance(connection.getShardingContext().getShardingRule(), queryResults,
+                    routeResult.getSqlStatement(), connection.getShardingContext().getShardingMetaData());
             currentResultSet = new ShardingResultSet(resultSets, merge(mergeEngine), this);
         }
         return currentResultSet;
diff --git a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java
index 02feaa7d813..44fa16c821b 100644
--- a/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java
+++ b/sharding-opentracing/src/test/java/io/shardingsphere/opentracing/MergeEventListenerTest.java
@@ -82,7 +82,7 @@ public final class MergeEventListenerTest {
         dataSourceMap.put("ds_1", null);
         ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, dataSourceMap.keySet());
         shardingContext = new ShardingContext(dataSourceMap, shardingRule, DatabaseType.MySQL, null, null, true);
-        mergeEngine = new DALMergeEngine(null, null, new ShowDatabasesStatement());
+        mergeEngine = new DALMergeEngine(null, null, new ShowDatabasesStatement(), null);
     }
     
     @Test
@@ -107,7 +107,7 @@ public final class MergeEventListenerTest {
     @Test
     public void assertException() {
         try {
-            MergeEngine errorMergeEngine = new DALMergeEngine(null, null, new ShowColumnsStatement());
+            MergeEngine errorMergeEngine = new DALMergeEngine(null, null, new ShowColumnsStatement(), null);
             ShardingStatement statement = new ShardingStatement(new ShardingConnection(shardingContext));
             Method mergeMethod = ShardingStatement.class.getDeclaredMethod("merge", MergeEngine.class);
             mergeMethod.setAccessible(true);
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLExecuteBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLExecuteBackendHandler.java
index 234ed51c4d8..5dd2b8f99fe 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLExecuteBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLExecuteBackendHandler.java
@@ -17,17 +17,6 @@
 
 package io.shardingsphere.proxy.backend.common;
 
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
 import io.shardingsphere.core.constant.DatabaseType;
 import io.shardingsphere.core.constant.SQLType;
 import io.shardingsphere.core.exception.ShardingException;
@@ -55,6 +44,17 @@ import io.shardingsphere.proxy.transport.mysql.packet.generic.OKPacket;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
 /**
  * SQL execute backend handler.
  *
@@ -198,7 +198,8 @@ public final class SQLExecuteBackendHandler implements BackendHandler {
             queryResults.add(mySQLPacketQueryResult);
         }
         try {
-            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults, sqlStatement).merge();
+            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults,
+                    sqlStatement, RuleRegistry.getInstance().getShardingMetaData()).merge();
             isMerged = true;
         } catch (final SQLException ex) {
             return new CommandResponsePackets(new ErrPacket(1, ex.getErrorCode(), "", ex.getSQLState(), ex.getMessage()));
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLPacketsBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLPacketsBackendHandler.java
index 3b02783cde4..55e509112e9 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLPacketsBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/SQLPacketsBackendHandler.java
@@ -17,16 +17,7 @@
 
 package io.shardingsphere.proxy.backend.common;
 
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-
 import com.google.common.collect.Lists;
-
 import io.netty.channel.Channel;
 import io.netty.channel.pool.SimpleChannelPool;
 import io.shardingsphere.core.constant.DatabaseType;
@@ -57,11 +48,20 @@ import io.shardingsphere.proxy.util.MySQLResultCache;
 import io.shardingsphere.proxy.util.SynchronizedFuture;
 import lombok.extern.slf4j.Slf4j;
 
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
 /**
  * SQL packets backend handler.
  *
  * @author wangkai
  * @author linjiaqi
+ * @author panjuan
  */
 @Slf4j
 public final class SQLPacketsBackendHandler implements BackendHandler {
@@ -208,7 +208,8 @@ public final class SQLPacketsBackendHandler implements BackendHandler {
     
     private CommandResponsePackets mergeDQLorDAL(final SQLStatement sqlStatement, final List<CommandResponsePackets> packets, final List<QueryResult> queryResults) {
         try {
-            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults, sqlStatement).merge();
+            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults,
+                    sqlStatement, RuleRegistry.getInstance().getShardingMetaData()).merge();
             isMerged = true;
         } catch (final SQLException ex) {
             return new CommandResponsePackets(new ErrPacket(1, ex.getErrorCode(), "", ex.getSQLState(), ex.getMessage()));
diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/StatementExecuteBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/StatementExecuteBackendHandler.java
index 50a26c818e6..e1468ce99a7 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/StatementExecuteBackendHandler.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/StatementExecuteBackendHandler.java
@@ -62,6 +62,7 @@ import java.util.concurrent.Future;
  * Statement execute backend handler.
  *
  * @author zhangyonglun
+ * @author panjuan
  */
 @Getter
 @Setter
@@ -214,7 +215,8 @@ public final class StatementExecuteBackendHandler implements BackendHandler {
             queryResults.add(mySQLPacketStatementExecuteQueryResult);
         }
         try {
-            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults, sqlStatement).merge();
+            mergedResult = MergeEngineFactory.newInstance(RuleRegistry.getInstance().getShardingRule(), queryResults,
+                    sqlStatement, RuleRegistry.getInstance().getShardingMetaData()).merge();
             isMerged = true;
         } catch (final SQLException ex) {
             return new CommandResponsePackets(new ErrPacket(1, ex.getErrorCode(), "", ex.getSQLState(), ex.getMessage()));