This is an automated email from the ASF dual-hosted git repository.

panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 388b850  optimize columnMatchTableAndCheckAmbiguous method logic 
(#13695)
388b850 is described below

commit 388b8503b59a4e2df1d08905952bfa3f7f53b1b2
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Fri Nov 19 09:44:43 2021 +0800

    optimize columnMatchTableAndCheckAmbiguous method logic (#13695)
---
 .../impl/EncryptProjectionTokenGenerator.java      | 109 +++++------------
 .../impl/EncryptProjectionTokenGeneratorTest.java  | 131 +++++++--------------
 .../impl/ShardingDropTableStatementValidator.java  |   2 +-
 .../dml/ShardingInsertStatementValidatorTest.java  |   8 +-
 .../infra/binder/segment/table/TablesContext.java  |  67 +++++------
 .../statement/dml/DeleteStatementContext.java      |   2 +-
 .../statement/dml/InsertStatementContext.java      |   2 +-
 .../statement/dml/SelectStatementContext.java      |   2 +-
 .../statement/dml/UpdateStatementContext.java      |   2 +-
 .../statement/dml/CallStatementContextTest.java    |   2 +-
 .../statement/impl/SelectStatementContextTest.java |   2 +-
 .../resources/scenario/encrypt/case/insert.xml     |   5 -
 .../encrypt/case/select_for_query_with_cipher.xml  |   2 +-
 13 files changed, 117 insertions(+), 219 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
index ba81182..152b46a 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/impl/EncryptProjectionTokenGenerator.java
@@ -18,6 +18,7 @@
 package org.apache.shardingsphere.encrypt.rewrite.token.generator.impl;
 
 import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
 import lombok.Setter;
 import 
org.apache.shardingsphere.encrypt.rewrite.aware.QueryWithCipherColumnAware;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.BaseEncryptSQLTokenGenerator;
@@ -28,7 +29,6 @@ import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.Col
 import 
org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ShorthandProjection;
 import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
-import 
org.apache.shardingsphere.infra.binder.statement.dml.InsertStatementContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
@@ -50,7 +50,6 @@ import java.util.Optional;
 /**
  * Projection token generator for encrypt.
  */
-@SuppressWarnings("rawtypes")
 @Setter
 public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGenerator 
         implements CollectionSQLTokenGenerator<SQLStatementContext>, 
QueryWithCipherColumnAware, PreviousSQLTokensAware {
@@ -59,45 +58,26 @@ public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGe
     
     private List<SQLToken> previousSQLTokens;
     
-    @SuppressWarnings("rawtypes")
     @Override
     protected boolean isGenerateSQLTokenForEncrypt(final SQLStatementContext 
sqlStatementContext) {
-        return (sqlStatementContext instanceof SelectStatementContext && 
!((SelectStatementContext) sqlStatementContext).getAllTables().isEmpty())
-                || ((sqlStatementContext instanceof InsertStatementContext) && 
null != ((InsertStatementContext) 
sqlStatementContext).getInsertSelectContext());
+        return sqlStatementContext instanceof SelectStatementContext && 
!((SelectStatementContext) sqlStatementContext).getAllTables().isEmpty();    
     }
     
-    @SuppressWarnings("rawtypes")
     @Override
     public Collection<SubstitutableColumnNameToken> generateSQLTokens(final 
SQLStatementContext sqlStatementContext) {
+        Preconditions.checkState(sqlStatementContext instanceof 
SelectStatementContext);
         Collection<SubstitutableColumnNameToken> result = new 
LinkedHashSet<>();
-        if (sqlStatementContext instanceof InsertStatementContext) {
-            SelectStatementContext selectStatementContext = 
((InsertStatementContext) 
sqlStatementContext).getInsertSelectContext().getSelectStatementContext();
-            result.addAll(generateSQLTokens(selectStatementContext));
-        }
-        if (sqlStatementContext instanceof SelectStatementContext) {
-            SelectStatementContext selectStatementContext = 
(SelectStatementContext) sqlStatementContext;
-            result.addAll(generateProjectionSQLTokens(selectStatementContext));
-            for (SelectStatementContext each : 
selectStatementContext.getSubqueryContexts().values()) {
-                result.addAll(generateProjectionSQLTokens(each));
-            }
-        }
-        return result;
-    }
-    
-    private Collection<SubstitutableColumnNameToken> 
generateProjectionSQLTokens(final SelectStatementContext 
selectStatementContext) {
-        Collection<SubstitutableColumnNameToken> result = new 
LinkedHashSet<>();
-        for (String each : 
selectStatementContext.getTablesContext().getTableNames()) {
-            Optional<EncryptTable> encryptTable = 
getEncryptRule().findEncryptTable(each);
-            if (!encryptTable.isPresent()) {
-                continue;
+        for (SelectStatementContext each : 
getSelectStatementContexts((SelectStatementContext) sqlStatementContext)) {
+            for (String table : each.getTablesContext().getTableNames()) {
+                Optional<EncryptTable> encryptTable = 
getEncryptRule().findEncryptTable(table);
+                encryptTable.ifPresent(optional -> 
result.addAll(generateSQLTokens(each, optional, table)));
             }
-            result.addAll(generateProjectionSQLTokens(selectStatementContext, 
encryptTable.get(), each));
         }
         return result;
     }
     
-    private Collection<SubstitutableColumnNameToken> 
generateProjectionSQLTokens(final SelectStatementContext selectStatementContext,
-                                                                               
  final EncryptTable encryptTable, final String tableName) {
+    private Collection<SubstitutableColumnNameToken> generateSQLTokens(final 
SelectStatementContext selectStatementContext,
+                                                                       final 
EncryptTable encryptTable, final String tableName) {
         Collection<SubstitutableColumnNameToken> result = new LinkedList<>();
         SubqueryType subqueryType = selectStatementContext.getSubqueryType();
         TablesContext tablesContext = 
selectStatementContext.getTablesContext();
@@ -106,27 +86,26 @@ public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGe
             if (each instanceof ColumnProjectionSegment) {
                 ColumnProjectionSegment columnSegment = 
(ColumnProjectionSegment) each;
                 String columnName = 
columnSegment.getColumn().getIdentifier().getValue();
-                if (encryptTable.getLogicColumns().contains(columnName)
-                        && 
columnMatchTableAndCheckAmbiguous(selectStatementContext, columnSegment, 
tableName)) {
-                    result.add(generateProjectionSQLTokens(columnSegment, 
encryptTable, tableName, subqueryType));
-                }
                 String owner = 
columnSegment.getColumn().getOwner().map(optional -> 
optional.getIdentifier().getValue()).orElse(null);
+                if (encryptTable.getLogicColumns().contains(columnName) && 
isOwnerSameWithTableNameOrAlias(tableName, owner, tablesContext)) {
+                    result.add(generateSQLTokens(columnSegment, encryptTable, 
tableName, subqueryType));
+                }
                 Optional<String> subqueryTableName = 
tablesContext.findTableNameFromSubquery(columnName, owner);
-                subqueryTableName.ifPresent(optional -> 
result.add(generateProjectionSQLTokens(columnSegment, encryptTable, optional, 
subqueryType)));
+                subqueryTableName.ifPresent(optional -> 
result.add(generateSQLTokens(columnSegment, encryptTable, optional, 
subqueryType)));
             }
             if (isToGeneratedSQLToken(each, selectStatementContext, 
tableName)) {
                 ShorthandProjectionSegment shorthandSegment = 
(ShorthandProjectionSegment) each;
                 ShorthandProjection shorthandProjection = 
getShorthandProjection(shorthandSegment, 
selectStatementContext.getProjectionsContext());
                 if (!shorthandProjection.getActualColumns().isEmpty()) {
-                    result.add(generateProjectionSQLTokens(shorthandSegment, 
shorthandProjection, tableName, encryptTable, 
selectStatementContext.getDatabaseType(), subqueryType));
+                    result.add(generateSQLTokens(shorthandSegment, 
shorthandProjection, tableName, encryptTable, 
selectStatementContext.getDatabaseType(), subqueryType));
                 }
             }
         }
         return result;
     }
     
-    private SubstitutableColumnNameToken generateProjectionSQLTokens(final 
ColumnProjectionSegment segment, final EncryptTable encryptTable,
-                                                                     final 
String tableName, final SubqueryType subqueryType) {
+    private SubstitutableColumnNameToken generateSQLTokens(final 
ColumnProjectionSegment segment, final EncryptTable encryptTable,
+                                                           final String 
tableName, final SubqueryType subqueryType) {
         String columnName = segment.getColumn().getIdentifier().getValue();
         String alias = segment.getAlias().orElseGet(() -> 
segment.getColumn().getIdentifier().getValue());
         Collection<ColumnProjection> projections = 
generateProjections(tableName, columnName, alias, null, encryptTable, 
subqueryType);
@@ -135,8 +114,8 @@ public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGe
         return new SubstitutableColumnNameToken(startIndex, stopIndex, 
projections);
     }
     
-    private SubstitutableColumnNameToken generateProjectionSQLTokens(final 
ShorthandProjectionSegment segment, final ShorthandProjection 
shorthandProjection, final String tableName, 
-                                                                     final 
EncryptTable encryptTable, final DatabaseType databaseType, final SubqueryType 
subqueryType) {
+    private SubstitutableColumnNameToken generateSQLTokens(final 
ShorthandProjectionSegment segment, final ShorthandProjection 
shorthandProjection, final String tableName,
+                                                           final EncryptTable 
encryptTable, final DatabaseType databaseType, final SubqueryType subqueryType) 
{
         List<ColumnProjection> projections = new LinkedList<>();
         for (ColumnProjection each : 
shorthandProjection.getActualColumns().values()) {
             if (encryptTable.getLogicColumns().contains(each.getName())) {
@@ -150,6 +129,20 @@ public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGe
         return new SubstitutableColumnNameToken(segment.getStartIndex(), 
segment.getStopIndex(), projections, databaseType.getQuoteCharacter());
     }
     
+    private Collection<SelectStatementContext> 
getSelectStatementContexts(final SelectStatementContext selectStatementContext) 
{
+        Collection<SelectStatementContext> result = new LinkedList<>();
+        result.add(selectStatementContext);
+        result.addAll(selectStatementContext.getSubqueryContexts().values());
+        return result;
+    }
+    
+    private boolean isOwnerSameWithTableNameOrAlias(final String tableName, 
final String owner, final TablesContext tablesContext) {
+        if (Strings.isNullOrEmpty(owner)) {
+            return true;
+        }
+        return tablesContext.findTableNameFromSQL(owner).filter(optional -> 
optional.equals(tableName)).isPresent();
+    }
+    
     private Collection<ColumnProjection> generateProjections(final String 
tableName, final String columnName, final String alias, final String owner, 
                                                              final 
EncryptTable encryptTable, final SubqueryType subqueryType) {
         Collection<ColumnProjection> result = new LinkedList<>();
@@ -193,44 +186,6 @@ public final class EncryptProjectionTokenGenerator extends 
BaseEncryptSQLTokenGe
         return new ColumnProjection(owner, encryptColumnName, alias);
     }
     
-    private boolean columnMatchTableAndCheckAmbiguous(final 
SelectStatementContext selectStatementContext, final ColumnProjectionSegment 
columnProjectionSegment, final String tableName) {
-        return isOwnerExistsMatchTableAlias(selectStatementContext, 
columnProjectionSegment, tableName) 
-                || isOwnerExistsMatchTableName(selectStatementContext, 
columnProjectionSegment, tableName) 
-                || isColumnUnAmbiguous(selectStatementContext, 
columnProjectionSegment);
-    }
-    
-    private boolean isOwnerExistsMatchTableAlias(final SelectStatementContext 
selectStatementContext, final ColumnProjectionSegment columnProjectionSegment, 
final String tableName) {
-        if (!columnProjectionSegment.getColumn().getOwner().isPresent()) {
-            return false;
-        }
-        return 
selectStatementContext.getTablesContext().getOriginalTables().stream().anyMatch(table
 -> tableName.equals(table.getTableName().getIdentifier().getValue())
-                && table.getAlias().isPresent() && 
columnProjectionSegment.getColumn().getOwner().get().getIdentifier().getValue().equals(table.getAlias().get()));
-    }
-    
-    private boolean isOwnerExistsMatchTableName(final SelectStatementContext 
selectStatementContext, final ColumnProjectionSegment columnProjectionSegment, 
final String tableName) {
-        if (!columnProjectionSegment.getColumn().getOwner().isPresent()) {
-            return false;
-        }
-        return 
selectStatementContext.getTablesContext().getOriginalTables().stream().anyMatch(table
 -> tableName.equals(table.getTableName().getIdentifier().getValue())
-                && !table.getAlias().isPresent() && 
columnProjectionSegment.getColumn().getOwner().get().getIdentifier().getValue().equals(tableName));
-    }
-    
-    private boolean isColumnUnAmbiguous(final SelectStatementContext 
selectStatementContext, final ColumnProjectionSegment columnProjectionSegment) {
-        if (columnProjectionSegment.getColumn().getOwner().isPresent()) {
-            return false;
-        }
-        int columnCount = 0;
-        for (String each : 
selectStatementContext.getTablesContext().getTableNames()) {
-            Optional<EncryptTable> encryptTable;
-            if ((encryptTable = 
getEncryptRule().findEncryptTable(each)).isPresent() 
-                    && 
encryptTable.get().getLogicColumns().contains(columnProjectionSegment.getColumn().getIdentifier().getValue()))
 {
-                columnCount++;
-            }
-        }
-        Preconditions.checkState(columnCount <= 1, "column `%s` is ambiguous 
in encrypt rules", 
columnProjectionSegment.getColumn().getIdentifier().getValue());
-        return true;
-    }
-    
     private boolean isToGeneratedSQLToken(final ProjectionSegment 
projectionSegment, final SelectStatementContext selectStatementContext, final 
String tableName) {
         if (!(projectionSegment instanceof ShorthandProjectionSegment)) {
             return false;
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
index 4f88654..57b30d4 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/test/java/org/apache/shardingsphere/encrypt/rewrite/impl/EncryptProjectionTokenGeneratorTest.java
@@ -20,6 +20,7 @@ package org.apache.shardingsphere.encrypt.rewrite.impl;
 import 
org.apache.shardingsphere.encrypt.rewrite.token.generator.impl.EncryptProjectionTokenGenerator;
 import org.apache.shardingsphere.encrypt.rule.EncryptRule;
 import org.apache.shardingsphere.encrypt.rule.EncryptTable;
+import org.apache.shardingsphere.infra.binder.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.statement.dml.SelectStatementContext;
 import 
org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
@@ -31,14 +32,11 @@ import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.Sim
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
 import 
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 import org.junit.Before;
-import org.junit.Rule;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -49,107 +47,62 @@ import static org.mockito.Mockito.when;
 
 public final class EncryptProjectionTokenGeneratorTest {
     
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-    
-    private EncryptProjectionTokenGenerator encryptProjectionTokenGenerator;
+    private EncryptProjectionTokenGenerator generator;
     
     @Before
     public void setup() {
-        encryptProjectionTokenGenerator = new 
EncryptProjectionTokenGenerator();
-        encryptProjectionTokenGenerator.setEncryptRule(buildEncryptRule());
-    }
-    
-    @Test
-    public void assertOwnerExistsMatchTableAliasGenerateSQLTokens() {
-        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
-        SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projectionsSegment);
-        SimpleTableSegment doctor = new SimpleTableSegment(new 
TableNameSegment(1, 7, new IdentifierValue("doctor")));
-        doctor.setAlias(new AliasSegment(8, 9, new IdentifierValue("a")));
-        SimpleTableSegment doctor1 = new SimpleTableSegment(new 
TableNameSegment(10, 17, new IdentifierValue("doctor1")));
-        
when(sqlStatementContext.getTablesContext().getOriginalTables()).thenReturn(Arrays.asList(doctor,
 doctor1));
-        
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Arrays.asList("doctor",
 "doctor1"));
-        IdentifierValue identifierValue = new IdentifierValue("mobile");
-        ColumnSegment columnSegment = new ColumnSegment(0, 0, identifierValue);
-        OwnerSegment ownerSegment = new OwnerSegment(0, 0, new 
IdentifierValue("a"));
-        columnSegment.setOwner(ownerSegment);
-        ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(columnSegment);
-        
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(columnProjectionSegment));
-        Collection<SubstitutableColumnNameToken> tokens = 
encryptProjectionTokenGenerator.generateSQLTokens(sqlStatementContext);
-        assertThat(tokens.size(), is(1));
+        generator = new EncryptProjectionTokenGenerator();
+        generator.setEncryptRule(buildEncryptRule());
     }
     
     @Test
-    public void assertOwnerExistsMatchTableAliasGenerateSQLTokens2() {
-        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+    public void assertGenerateSQLTokensWhenOwnerMatchTableAlias() {
+        SimpleTableSegment doctorTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor")));
+        doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a")));
+        ColumnSegment column = new ColumnSegment(0, 0, new 
IdentifierValue("mobile"));
+        column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
+        ProjectionsSegment projections = mock(ProjectionsSegment.class);
+        
when(projections.getProjections()).thenReturn(Collections.singletonList(new 
ColumnProjectionSegment(column)));
         SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projectionsSegment);
-        SimpleTableSegment doctor = new SimpleTableSegment(new 
TableNameSegment(1, 7, new IdentifierValue("doctor")));
-        doctor.setAlias(new AliasSegment(8, 9, new IdentifierValue("a")));
-        SimpleTableSegment doctor1 = new SimpleTableSegment(new 
TableNameSegment(10, 17, new IdentifierValue("doctor")));
-        
when(sqlStatementContext.getTablesContext().getOriginalTables()).thenReturn(Arrays.asList(doctor,
 doctor1));
-        
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Arrays.asList("doctor"));
-        IdentifierValue identifierValue = new IdentifierValue("mobile");
-        ColumnSegment columnSegment = new ColumnSegment(0, 0, identifierValue);
-        OwnerSegment ownerSegment = new OwnerSegment(0, 0, new 
IdentifierValue("a"));
-        columnSegment.setOwner(ownerSegment);
-        ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(columnSegment);
-        
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(columnProjectionSegment));
-        Collection<SubstitutableColumnNameToken> tokens = 
encryptProjectionTokenGenerator.generateSQLTokens(sqlStatementContext);
-        assertThat(tokens.size(), is(1));
+        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
+        
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
+        SimpleTableSegment doctorOneTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor1")));
+        when(sqlStatementContext.getTablesContext()).thenReturn(new 
TablesContext(Arrays.asList(doctorTable, doctorOneTable)));
+        Collection<SubstitutableColumnNameToken> actual = 
generator.generateSQLTokens(sqlStatementContext);
+        assertThat(actual.size(), is(1));
     }
     
     @Test
-    public void assertOwnerExistsMatchTableNameGenerateSQLTokens() {
-        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+    public void assertGenerateSQLTokensWhenOwnerMatchTableAliasForSameTable() {
+        SimpleTableSegment doctorTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor")));
+        doctorTable.setAlias(new AliasSegment(0, 0, new IdentifierValue("a")));
+        ColumnSegment column = new ColumnSegment(0, 0, new 
IdentifierValue("mobile"));
+        column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("a")));
+        ProjectionsSegment projections = mock(ProjectionsSegment.class);
+        
when(projections.getProjections()).thenReturn(Collections.singletonList(new 
ColumnProjectionSegment(column)));
         SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projectionsSegment);
-        SimpleTableSegment doctor = new SimpleTableSegment(new 
TableNameSegment(1, 7, new IdentifierValue("doctor")));
-        SimpleTableSegment doctor1 = new SimpleTableSegment(new 
TableNameSegment(10, 17, new IdentifierValue("doctor1")));
-        
when(sqlStatementContext.getTablesContext().getOriginalTables()).thenReturn(Arrays.asList(doctor,
 doctor1));
-        
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Arrays.asList("doctor",
 "doctor1"));
-        IdentifierValue identifierValue = new IdentifierValue("mobile");
-        ColumnSegment columnSegment = new ColumnSegment(0, 0, identifierValue);
-        OwnerSegment ownerSegment = new OwnerSegment(0, 0, new 
IdentifierValue("doctor"));
-        columnSegment.setOwner(ownerSegment);
-        ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(columnSegment);
-        
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(columnProjectionSegment));
-        Collection<SubstitutableColumnNameToken> tokens = 
encryptProjectionTokenGenerator.generateSQLTokens(sqlStatementContext);
-        assertThat(tokens.size(), is(1));
+        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
+        
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
+        SimpleTableSegment sameDoctorTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor")));
+        when(sqlStatementContext.getTablesContext()).thenReturn(new 
TablesContext(Arrays.asList(doctorTable, sameDoctorTable)));
+        Collection<SubstitutableColumnNameToken> actual = 
generator.generateSQLTokens(sqlStatementContext);
+        assertThat(actual.size(), is(1));
     }
     
     @Test
-    public void assertColumnUnAmbiguousGenerateSQLTokens() {
-        expectedException.expect(IllegalStateException.class);
-        expectedException.expectMessage("column `mobile` is ambiguous in 
encrypt rules");
-        ProjectionsSegment projectionsSegment = mock(ProjectionsSegment.class);
+    public void assertGenerateSQLTokensWhenOwnerMatchTableName() {
+        ColumnSegment column = new ColumnSegment(0, 0, new 
IdentifierValue("mobile"));
+        column.setOwner(new OwnerSegment(0, 0, new IdentifierValue("doctor")));
+        ProjectionsSegment projections = mock(ProjectionsSegment.class);
+        
when(projections.getProjections()).thenReturn(Collections.singletonList(new 
ColumnProjectionSegment(column)));
         SelectStatementContext sqlStatementContext = 
mock(SelectStatementContext.class, RETURNS_DEEP_STUBS);
-        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projectionsSegment);
-        
when(sqlStatementContext.getTablesContext().getTableNames()).thenReturn(Arrays.asList("doctor",
 "doctor1"));
-        List<SimpleTableSegment> allUniqueTables = buildAllUniqueTables();
-        
when(sqlStatementContext.getTablesContext().getAllUniqueTables()).thenReturn(allUniqueTables);
-        IdentifierValue identifierValue = new IdentifierValue("mobile");
-        ColumnSegment columnSegment = new ColumnSegment(0, 0, identifierValue);
-        ColumnProjectionSegment columnProjectionSegment = new 
ColumnProjectionSegment(columnSegment);
-        
when(projectionsSegment.getProjections()).thenReturn(Collections.singletonList(columnProjectionSegment));
-        encryptProjectionTokenGenerator.generateSQLTokens(sqlStatementContext);
-    }
-    
-    private List<SimpleTableSegment> buildAllUniqueTables() {
-        return buildAllUniqueTables(true);
-    }
-    
-    private List<SimpleTableSegment> buildAllUniqueTables(final boolean 
hasAlias) {
-        SimpleTableSegment table1 = mock(SimpleTableSegment.class, 
RETURNS_DEEP_STUBS);
-        
when(table1.getTableName().getIdentifier().getValue()).thenReturn("doctor");
-        SimpleTableSegment table2 = mock(SimpleTableSegment.class, 
RETURNS_DEEP_STUBS);
-        
when(table2.getTableName().getIdentifier().getValue()).thenReturn("doctor1");
-        if (hasAlias) {
-            when(table1.getAlias()).thenReturn(Optional.of("a"));
-            when(table2.getAlias()).thenReturn(Optional.of("b"));
-        }
-        return Arrays.asList(table1, table2);
+        
when(sqlStatementContext.getSqlStatement().getProjections()).thenReturn(projections);
+        
when(sqlStatementContext.getSubqueryContexts().values()).thenReturn(Collections.emptyList());
+        SimpleTableSegment doctorTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor")));
+        SimpleTableSegment doctorOneTable = new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("doctor1")));
+        when(sqlStatementContext.getTablesContext()).thenReturn(new 
TablesContext(Arrays.asList(doctorTable, doctorOneTable)));
+        Collection<SubstitutableColumnNameToken> actual = 
generator.generateSQLTokens(sqlStatementContext);
+        assertThat(actual.size(), is(1));
     }
     
     private EncryptRule buildEncryptRule() {
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
index 4fc521a..c9e7a08 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
@@ -44,7 +44,7 @@ public final class ShardingDropTableStatementValidator 
extends ShardingDDLStatem
     public void preValidate(final ShardingRule shardingRule, final 
SQLStatementContext<DropTableStatement> sqlStatementContext,
                             final List<Object> parameters, final 
ShardingSphereSchema schema) {
         if 
(!DropTableStatementHandler.containsExistClause(sqlStatementContext.getSqlStatement()))
 {
-            validateTableExist(schema, 
sqlStatementContext.getTablesContext().getUniqueTables().values());
+            validateTableExist(schema, 
sqlStatementContext.getTablesContext().getTables());
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
index a48ebdc..fece274 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingInsertStatementValidatorTest.java
@@ -104,7 +104,7 @@ public final class ShardingInsertStatementValidatorTest {
         
when(shardingRule.findGenerateKeyColumnName("user")).thenReturn(Optional.of("id"));
         when(shardingRule.isGenerateKeyColumn("id", "user")).thenReturn(false);
         SQLStatementContext<InsertStatement> sqlStatementContext = 
createInsertStatementContext(Collections.singletonList(1), 
createInsertSelectStatement());
-        
sqlStatementContext.getTablesContext().getUniqueTables().putAll(createSingleTablesContext().getUniqueTables());
+        
sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames());
         new 
ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), mock(ShardingSphereSchema.class));
     }
     
@@ -113,7 +113,7 @@ public final class ShardingInsertStatementValidatorTest {
         
when(shardingRule.findGenerateKeyColumnName("user")).thenReturn(Optional.of("id"));
         when(shardingRule.isGenerateKeyColumn("id", "user")).thenReturn(true);
         SQLStatementContext<InsertStatement> sqlStatementContext = 
createInsertStatementContext(Collections.singletonList(1), 
createInsertSelectStatement());
-        
sqlStatementContext.getTablesContext().getUniqueTables().putAll(createSingleTablesContext().getUniqueTables());
+        
sqlStatementContext.getTablesContext().getTableNames().addAll(createSingleTablesContext().getTableNames());
         new 
ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), mock(ShardingSphereSchema.class));
     }
     
@@ -124,7 +124,7 @@ public final class ShardingInsertStatementValidatorTest {
         TablesContext multiTablesContext = createMultiTablesContext();
         
when(shardingRule.isAllBindingTables(multiTablesContext.getTableNames())).thenReturn(false);
         SQLStatementContext<InsertStatement> sqlStatementContext = 
createInsertStatementContext(Collections.singletonList(1), 
createInsertSelectStatement());
-        
sqlStatementContext.getTablesContext().getUniqueTables().putAll(multiTablesContext.getUniqueTables());
+        
sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames());
         new 
ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), mock(ShardingSphereSchema.class));
     }
     
@@ -135,7 +135,7 @@ public final class ShardingInsertStatementValidatorTest {
         TablesContext multiTablesContext = createMultiTablesContext();
         
when(shardingRule.isAllBindingTables(multiTablesContext.getTableNames())).thenReturn(true);
         SQLStatementContext<InsertStatement> sqlStatementContext = 
createInsertStatementContext(Collections.singletonList(1), 
createInsertSelectStatement());
-        
sqlStatementContext.getTablesContext().getUniqueTables().putAll(multiTablesContext.getUniqueTables());
+        
sqlStatementContext.getTablesContext().getTableNames().addAll(multiTablesContext.getTableNames());
         new 
ShardingInsertStatementValidator(shardingConditions).preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), mock(ShardingSphereSchema.class));
     }
     
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
index c4555c7..5d27a21 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/segment/table/TablesContext.java
@@ -48,14 +48,14 @@ import java.util.stream.Collectors;
 @ToString
 public final class TablesContext {
     
-    private final Collection<SimpleTableSegment> originalTables = new 
LinkedList<>();
+    private final Collection<SimpleTableSegment> tables = new LinkedList<>();
     
-    private final Map<String, SimpleTableSegment> uniqueTables = new 
HashMap<>();
-    
-    private final Map<String, Collection<SubqueryTableContext>> subqueryTables 
= new HashMap<>();
+    private final Collection<String> tableNames = new HashSet<>();
     
     private final Collection<String> schemaNames = new HashSet<>();
     
+    private final Map<String, Collection<SubqueryTableContext>> subqueryTables 
= new HashMap<>();
+    
     public TablesContext(final SimpleTableSegment tableSegment) {
         this(Collections.singletonList(tableSegment));
     }
@@ -71,8 +71,8 @@ public final class TablesContext {
         Collection<SimpleTableSegment> simpleTableSegments = 
tableSegments.stream().filter(each 
             -> each instanceof SimpleTableSegment).map(each -> 
(SimpleTableSegment) each).collect(Collectors.toList());
         for (SimpleTableSegment each : simpleTableSegments) {
-            originalTables.add(each);
-            
uniqueTables.putIfAbsent(each.getTableName().getIdentifier().getValue(), each);
+            tables.add(each);
+            tableNames.add(each.getTableName().getIdentifier().getValue());
             each.getOwner().ifPresent(optional -> 
schemaNames.add(optional.getIdentifier().getValue()));
         }
         Collection<SubqueryTableSegment> subqueryTableSegments = 
tableSegments.stream().filter(each
@@ -90,16 +90,7 @@ public final class TablesContext {
      * @return table names
      */
     public Collection<String> getTableNames() {
-        return uniqueTables.keySet();
-    }
-    
-    /**
-     * Get all unique table segments.
-     *
-     * @return all unique table segments
-     */
-    public Collection<SimpleTableSegment> getAllUniqueTables() {
-        return uniqueTables.values();
+        return tableNames;
     }
     
     /**
@@ -110,8 +101,8 @@ public final class TablesContext {
      * @return table name map
      */
     public Map<String, String> findTableName(final Collection<ColumnSegment> 
columns, final ShardingSphereSchema schema) {
-        if (1 == uniqueTables.size()) {
-            String tableName = uniqueTables.keySet().iterator().next();
+        if (1 == tableNames.size()) {
+            String tableName = tableNames.iterator().next();
             return 
columns.stream().collect(Collectors.toMap(ColumnSegment::getQualifiedName, each 
-> tableName, (oldValue, currentValue) -> oldValue));
         }
         Map<String, String> result = new HashMap<>(columns.size(), 1);
@@ -131,8 +122,8 @@ public final class TablesContext {
      * @return table name
      */
     public Optional<String> findTableName(final ColumnProjection column, final 
ShardingSphereSchema schema) {
-        if (1 == uniqueTables.size()) {
-            return Optional.of(uniqueTables.keySet().iterator().next());
+        if (1 == tableNames.size()) {
+            return Optional.of(tableNames.iterator().next());
         }
         if (null != column.getOwner()) {
             return findTableNameFromSQL(column.getOwner());
@@ -147,9 +138,10 @@ public final class TablesContext {
      * @return table name
      */
     public Optional<String> findTableNameFromSQL(final String 
tableNameOrAlias) {
-        for (String each : uniqueTables.keySet()) {
-            if (tableNameOrAlias.equalsIgnoreCase(each) || 
tableNameOrAlias.equalsIgnoreCase(uniqueTables.get(each).getAlias().orElse(null)))
 {
-                return Optional.of(each);
+        for (SimpleTableSegment each : tables) {
+            String tableName = each.getTableName().getIdentifier().getValue();
+            if (tableNameOrAlias.equalsIgnoreCase(tableName) || 
tableNameOrAlias.equalsIgnoreCase(each.getAlias().orElse(null))) {
+                return Optional.of(tableName);
             }
         }
         return Optional.empty();
@@ -160,13 +152,14 @@ public final class TablesContext {
             return Collections.emptyMap();
         }
         Map<String, String> result = new HashMap<>();
-        for (String each : uniqueTables.keySet()) {
-            if (ownerColumns.containsKey(each)) {
-                
ownerColumns.get(each).stream().map(ColumnSegment::getQualifiedName).forEach(column
 -> result.put(column, each));
+        for (SimpleTableSegment each : tables) {
+            String tableName = each.getTableName().getIdentifier().getValue();
+            if (ownerColumns.containsKey(tableName)) {
+                
ownerColumns.get(tableName).stream().map(ColumnSegment::getQualifiedName).forEach(column
 -> result.put(column, tableName));
             }
-            Optional<String> alias = uniqueTables.get(each).getAlias();
+            Optional<String> alias = each.getAlias();
             if (alias.isPresent() && ownerColumns.containsKey(alias.get())) {
-                
ownerColumns.get(alias.get()).stream().map(ColumnSegment::getQualifiedName).forEach(column
 -> result.put(column, each));
+                
ownerColumns.get(alias.get()).stream().map(ColumnSegment::getQualifiedName).forEach(column
 -> result.put(column, tableName));
             }
         }
         return result;
@@ -177,23 +170,25 @@ public final class TablesContext {
             return Collections.emptyMap();
         }
         Map<String, String> result = new HashMap<>();
-        for (String each : uniqueTables.keySet()) {
-            Collection<String> tableColumnNames = 
schema.getAllColumnNames(each);
+        for (SimpleTableSegment each : tables) {
+            String tableName = each.getTableName().getIdentifier().getValue();
+            Collection<String> tableColumnNames = 
schema.getAllColumnNames(tableName);
             if (tableColumnNames.isEmpty()) {
                 continue;
             }
-            Collection<String> intersectionColumnNames = 
tableColumnNames.stream().filter(columnNames::contains).collect(Collectors.toList());
-            for (String columnName : intersectionColumnNames) {
-                result.put(columnName, each);
+            Collection<String> intersectColumnNames = 
tableColumnNames.stream().filter(columnNames::contains).collect(Collectors.toList());
+            for (String columnName : intersectColumnNames) {
+                result.put(columnName, tableName);
             }
         }
         return result;
     }
     
     private Optional<String> findTableNameFromMetaData(final String 
columnName, final ShardingSphereSchema schema) {
-        for (String each : uniqueTables.keySet()) {
-            if (schema.containsColumn(each, columnName)) {
-                return Optional.of(each);
+        for (SimpleTableSegment each : tables) {
+            String tableName = each.getTableName().getIdentifier().getValue();
+            if (schema.containsColumn(tableName, columnName)) {
+                return Optional.of(tableName);
             }
         }
         return Optional.empty();
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementContext.java
index 67e1580..5b29326 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/DeleteStatementContext.java
@@ -72,7 +72,7 @@ public final class DeleteStatementContext extends 
CommonSQLStatementContext<Dele
     
     @Override
     public Collection<SimpleTableSegment> getAllTables() {
-        return tablesContext.getOriginalTables();
+        return tablesContext.getTables();
     }
     
     @Override
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
index 865bba0..282fef0 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/InsertStatementContext.java
@@ -183,7 +183,7 @@ public final class InsertStatementContext extends 
CommonSQLStatementContext<Inse
     
     @Override
     public Collection<SimpleTableSegment> getAllTables() {
-        return tablesContext.getOriginalTables();
+        return tablesContext.getTables();
     }
     
     /**
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
index b20c4cc..e825e4a 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/SelectStatementContext.java
@@ -244,7 +244,7 @@ public final class SelectStatementContext extends 
CommonSQLStatementContext<Sele
     
     @Override
     public Collection<SimpleTableSegment> getAllTables() {
-        return tablesContext.getOriginalTables();
+        return tablesContext.getTables();
     }
     
     @Override
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementContext.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementContext.java
index ff4d35c..b1de6a2 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/main/java/org/apache/shardingsphere/infra/binder/statement/dml/UpdateStatementContext.java
@@ -55,7 +55,7 @@ public final class UpdateStatementContext extends 
CommonSQLStatementContext<Upda
     
     @Override
     public Collection<SimpleTableSegment> getAllTables() {
-        return tablesContext.getOriginalTables();
+        return tablesContext.getTables();
     }
     
     @Override
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/CallStatementContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/CallStatementContextTest.java
index 187dd47..ad9a693 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/CallStatementContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/dml/CallStatementContextTest.java
@@ -47,6 +47,6 @@ public final class CallStatementContextTest {
         CallStatementContext actual = new CallStatementContext(callStatement, 
DefaultSchema.LOGIC_NAME);
         assertThat(actual, instanceOf(CommonSQLStatementContext.class));
         assertThat(actual.getSqlStatement(), is(callStatement));
-        assertThat(actual.getTablesContext().getUniqueTables(), 
is(Collections.emptyMap()));
+        assertThat(actual.getTablesContext().getTableNames(), 
is(Collections.emptySet()));
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
index 0a88399..f73f366 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-binder/src/test/java/org/apache/shardingsphere/infra/binder/statement/impl/SelectStatementContextTest.java
@@ -386,7 +386,7 @@ public final class SelectStatementContextTest {
         ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
         selectStatement.setProjections(new ProjectionsSegment(0, 0));
         SelectStatementContext actual = new 
SelectStatementContext(Collections.singletonMap(DefaultSchema.LOGIC_NAME, 
metaData), Collections.emptyList(), selectStatement, DefaultSchema.LOGIC_NAME);
-        assertThat(actual.getTablesContext().getUniqueTables(), 
is(Collections.emptyMap()));
+        assertThat(actual.getTablesContext().getTableNames(), 
is(Collections.emptySet()));
         assertThat(actual.getAllTables(), is(Lists.newLinkedList()));
         assertThat(actual.getGroupByContext().getItems(), 
is(Lists.newLinkedList()));
         assertThat(actual.getWhere(), is(Optional.of(whereSegment)));
diff --git 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/insert.xml
 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/insert.xml
index 5c27454..a1f21d4 100644
--- 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/insert.xml
+++ 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/insert.xml
@@ -67,11 +67,6 @@
         <output sql="INSERT INTO t_account(account_id, 
cipher_certificate_number, assisted_query_certificate_number, cipher_password, 
assisted_query_password, cipher_amount, status) VALUES (?, ?, ?, ?, ?, ?, ?), 
(2, 'encrypt_222X', 'assisted_query_222X', 'encrypt_bbb', 'assisted_query_bbb', 
'encrypt_2000', 'OK'), (?, ?, ?, ?, ?, ?, ?), (4, 'encrypt_444X', 
'assisted_query_444X', 'encrypt_ddd', 'assisted_query_ddd', 'encrypt_4000', 
'OK')" parameters="1, encrypt_111X, assisted_query_111X, e [...]
     </rewrite-assertion>
     
-    <rewrite-assertion id="insert_select_encrypt_rewrite" db-types="MySQL">
-        <input sql="INSERT INTO t_account(account_id, certificate_number, 
password, amount) SELECT account_id, certificate_number, password, amount FROM 
t_account_bak WHERE certificate_number = ?" parameters="111X"/>
-        <output sql="INSERT INTO t_account(account_id, 
cipher_certificate_number, assisted_query_certificate_number, cipher_password, 
assisted_query_password, cipher_amount) SELECT account_id, 
cipher_certificate_number AS certificate_number, cipher_password AS password, 
cipher_amount AS amount FROM t_account_bak WHERE 
assisted_query_certificate_number = ?" parameters="assisted_query_111X" />
-    </rewrite-assertion>
-    
     <rewrite-assertion id="insert_values_without_columns_for_literals" 
db-types="MySQL">
         <input sql="INSERT INTO t_account VALUES (1, '111X', 'aaa', 1000, 
'OK'), (2, '222X', 'bbb', 2000, 'OK'), (3, '333X', 'ccc', 3000, 'OK'), (4, 
'444X', 'ddd', 4000, 'OK')" />
         <output sql="INSERT INTO t_account(account_id, 
cipher_certificate_number, assisted_query_certificate_number, cipher_password, 
assisted_query_password, cipher_amount, status) VALUES (1, 'encrypt_111X', 
'assisted_query_111X', 'encrypt_aaa', 'assisted_query_aaa', 'encrypt_1000', 
'OK'), (2, 'encrypt_222X', 'assisted_query_222X', 'encrypt_bbb', 
'assisted_query_bbb', 'encrypt_2000', 'OK'), (3, 'encrypt_333X', 
'assisted_query_333X', 'encrypt_ccc', 'assisted_query_ccc', 'encrypt_3000', ' 
[...]
diff --git 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
index 26fa807..6d97a3e 100644
--- 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
+++ 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/select_for_query_with_cipher.xml
@@ -91,7 +91,7 @@
 
     <rewrite-assertion id="select_not_nested_subquery_in_projection" 
db-types="MySQL">
         <input sql="SELECT u.certificate_number, u.password, (SELECT o.amount 
FROM t_account_bak o WHERE o.certificate_number=u.certificate_number) amount 
FROM t_account u, t_account_bak c WHERE u.certificate_number = 
c.certificate_number and u.password=?" parameters="1" />
-        <output sql="SELECT u.cipher_certificate_number AS certificate_number, 
u.cipher_password AS password, (SELECT o.cipher_amount AS amount FROM 
t_account_bak o WHERE o.certificate_number=u.assisted_query_certificate_number) 
amount FROM t_account u, t_account_bak c WHERE 
u.assisted_query_certificate_number = c.assisted_query_certificate_number and 
u.assisted_query_password=?" parameters="assisted_query_1" />
+        <output sql="SELECT u.cipher_certificate_number AS certificate_number, 
u.cipher_password AS password, (SELECT o.cipher_amount AS amount FROM 
t_account_bak o WHERE 
o.assisted_query_certificate_number=u.assisted_query_certificate_number) amount 
FROM t_account u, t_account_bak c WHERE u.assisted_query_certificate_number = 
c.assisted_query_certificate_number and u.assisted_query_password=?" 
parameters="assisted_query_1" />
     </rewrite-assertion>
 
     <rewrite-assertion id="select_not_nested_subquery_in_table_segment" 
db-types="MySQL">

Reply via email to