You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by tu...@apache.org on 2022/06/15 01:25:31 UTC

[shardingsphere] branch master updated: Support create index on table(column) statement rewrite when config encrypt (#18366)

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

tuichenchuxin 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 39acbd90293 Support create index on table(column) statement rewrite when config encrypt (#18366)
39acbd90293 is described below

commit 39acbd90293345a9928f92d563802cd122f29df8
Author: Zhengqiang Duan <du...@apache.org>
AuthorDate: Wed Jun 15 09:25:18 2022 +0800

    Support create index on table(column) statement rewrite when config encrypt (#18366)
---
 .../rewrite/token/EncryptTokenGenerateBuilder.java |  4 +-
 .../EncryptCreateIndexTokenGenerator.java          | 89 ++++++++++++++++++++++
 .../ddl/alter/{alter.xml => alter-table.xml}       |  0
 .../ddl/create/{create.xml => create-index.xml}    | 11 ++-
 .../ddl/create/{create.xml => create-table.xml}    |  0
 .../{insert_column.xml => insert-column.xml}       |  0
 ...rt_on_duplicate.xml => insert-on-duplicate.xml} |  0
 .../dml/insert/{insert_set.xml => insert-set.xml}  |  0
 .../{select_group_by.xml => select-group-by.xml}   |  0
 .../select/{select_join.xml => select-join.xml}    |  0
 .../{select_order_by.xml => select-order-by.xml}   |  0
 ...select_projection.xml => select-projection.xml} |  0
 .../{select_subquery.xml => select-subquery.xml}   |  0
 .../select/{select_where.xml => select-where.xml}  |  0
 .../ddl/alter/{alter.xml => alter-table.xml}       |  0
 .../ddl/create/{create.xml => create-index.xml}    | 11 ++-
 .../ddl/create/{create.xml => create-table.xml}    |  0
 .../{insert_column.xml => insert-column.xml}       |  0
 ...rt_on_duplicate.xml => insert-on-duplicate.xml} |  0
 .../dml/insert/{insert_set.xml => insert-set.xml}  |  0
 .../{select_group_by.xml => select-group-by.xml}   |  0
 .../select/{select_join.xml => select-join.xml}    |  0
 .../{select_order_by.xml => select-order-by.xml}   |  0
 ...select_projection.xml => select-projection.xml} |  0
 .../{select_subquery.xml => select-subquery.xml}   |  0
 .../select/{select_where.xml => select-where.xml}  |  0
 .../ddl/create/{create.xml => create-table.xml}    |  0
 .../{insert_column.xml => insert-column.xml}       |  0
 .../dml/insert/{insert_set.xml => insert-set.xml}  |  0
 .../select/{select_join.xml => select-join.xml}    |  0
 ...select_projection.xml => select-projection.xml} |  0
 .../{select_subquery.xml => select-subquery.xml}   |  0
 .../select/{select_where.xml => select-where.xml}  |  0
 ...select_projection.xml => select-projection.xml} |  0
 .../select/{select_where.xml => select-where.xml}  |  0
 .../scenario/sharding/case/{ => dal}/analyze.xml   |  0
 .../case/{alter.xml => ddl/alter-table.xml}        |  0
 .../scenario/sharding/case/{ => ddl}/close.xml     |  0
 .../case/{create.xml => ddl/create-table.xml}      |  0
 .../scenario/sharding/case/{ => ddl}/cursor.xml    |  0
 .../sharding/case/{drop.xml => ddl/drop-table.xml} |  0
 .../scenario/sharding/case/{ => ddl}/fetch.xml     |  0
 .../scenario/sharding/case/{ => ddl}/index.xml     |  0
 .../scenario/sharding/case/{ => ddl}/move.xml      |  0
 .../scenario/sharding/case/{ => ddl}/show.xml      |  0
 .../scenario/sharding/case/{ => dml}/copy.xml      |  0
 .../scenario/sharding/case/{ => dml}/delete.xml    |  0
 .../scenario/sharding/case/{ => dml}/insert.xml    |  0
 .../scenario/sharding/case/{ => dml}/select.xml    |  0
 .../scenario/sharding/case/{ => dml}/update.xml    |  0
 50 files changed, 108 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
index 3cc64519175..e04fba885a6 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/EncryptTokenGenerateBuilder.java
@@ -18,12 +18,13 @@
 package org.apache.shardingsphere.encrypt.rewrite.token;
 
 import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware;
 import org.apache.shardingsphere.encrypt.rewrite.aware.DatabaseNameAware;
+import org.apache.shardingsphere.encrypt.rewrite.aware.EncryptConditionsAware;
 import org.apache.shardingsphere.encrypt.rewrite.condition.EncryptCondition;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.AssistQueryAndPlainInsertColumnsTokenGenerator;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAlterTableTokenGenerator;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptAssignmentTokenGenerator;
+import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateIndexTokenGenerator;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptCreateTableTokenGenerator;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptForUseDefaultInsertColumnsTokenGenerator;
 import org.apache.shardingsphere.encrypt.rewrite.token.generator.EncryptInsertOnUpdateTokenGenerator;
@@ -71,6 +72,7 @@ public final class EncryptTokenGenerateBuilder implements SQLTokenGeneratorBuild
         addSQLTokenGenerator(result, new EncryptCreateTableTokenGenerator());
         addSQLTokenGenerator(result, new EncryptAlterTableTokenGenerator());
         addSQLTokenGenerator(result, new EncryptOrderByItemTokenGenerator());
+        addSQLTokenGenerator(result, new EncryptCreateIndexTokenGenerator());
         return result;
     }
     
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateIndexTokenGenerator.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateIndexTokenGenerator.java
new file mode 100644
index 00000000000..d71a85ec082
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptCreateIndexTokenGenerator.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.shardingsphere.encrypt.rewrite.token.generator;
+
+import lombok.Setter;
+import org.apache.shardingsphere.encrypt.rule.EncryptRule;
+import org.apache.shardingsphere.encrypt.rule.aware.EncryptRuleAware;
+import org.apache.shardingsphere.infra.binder.segment.select.projection.impl.ColumnProjection;
+import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
+import org.apache.shardingsphere.infra.binder.statement.ddl.CreateIndexStatementContext;
+import org.apache.shardingsphere.infra.rewrite.sql.token.generator.CollectionSQLTokenGenerator;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
+import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.generic.SubstitutableColumnNameToken;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.Optional;
+
+/**
+ * Create index token generator for encrypt.
+ */
+@Setter
+public final class EncryptCreateIndexTokenGenerator implements CollectionSQLTokenGenerator<CreateIndexStatementContext>, EncryptRuleAware {
+    
+    private EncryptRule encryptRule;
+    
+    @Override
+    public boolean isGenerateSQLToken(final SQLStatementContext<?> sqlStatementContext) {
+        return sqlStatementContext instanceof CreateIndexStatementContext && !(((CreateIndexStatementContext) sqlStatementContext).getSqlStatement()).getColumns().isEmpty();
+    }
+    
+    @Override
+    public Collection<SQLToken> generateSQLTokens(final CreateIndexStatementContext createIndexStatementContext) {
+        Collection<SQLToken> result = new LinkedList<>();
+        String tableName = createIndexStatementContext.getSqlStatement().getTable().getTableName().getIdentifier().getValue();
+        Collection<ColumnSegment> columns = createIndexStatementContext.getSqlStatement().getColumns();
+        for (ColumnSegment each : columns) {
+            encryptRule.findEncryptor(tableName, each.getIdentifier().getValue()).flatMap(optional -> getColumnToken(tableName, each)).ifPresent(result::add);
+        }
+        return result;
+    }
+    
+    private Optional<SQLToken> getColumnToken(final String tableName, final ColumnSegment columnSegment) {
+        String columnName = columnSegment.getIdentifier().getValue();
+        boolean queryWithCipherColumn = encryptRule.isQueryWithCipherColumn(tableName, columnName);
+        if (queryWithCipherColumn) {
+            Optional<String> assistedQueryColumn = encryptRule.findAssistedQueryColumn(tableName, columnName);
+            return assistedQueryColumn.map(optional -> getAssistedQueryColumnToken(columnSegment, optional)).orElseGet(() -> getCipherColumnToken(tableName, columnSegment, columnName));
+        }
+        return getPlainColumnToken(tableName, columnSegment, columnName);
+    }
+    
+    private Optional<SQLToken> getAssistedQueryColumnToken(final ColumnSegment columnSegment, final String columnName) {
+        Collection<ColumnProjection> columnProjections = getColumnProjections(columnName);
+        return Optional.of(new SubstitutableColumnNameToken(columnSegment.getStartIndex(), columnSegment.getStopIndex(), columnProjections));
+    }
+    
+    private Optional<SQLToken> getCipherColumnToken(final String tableName, final ColumnSegment columnSegment, final String columnName) {
+        String cipherColumn = encryptRule.getCipherColumn(tableName, columnName);
+        Collection<ColumnProjection> columnProjections = getColumnProjections(cipherColumn);
+        return Optional.of(new SubstitutableColumnNameToken(columnSegment.getStartIndex(), columnSegment.getStopIndex(), columnProjections));
+    }
+    
+    private Optional<SQLToken> getPlainColumnToken(final String tableName, final ColumnSegment columnSegment, final String columnName) {
+        Optional<String> plainColumn = encryptRule.findPlainColumn(tableName, columnName);
+        return plainColumn.map(optional -> new SubstitutableColumnNameToken(columnSegment.getStartIndex(), columnSegment.getStopIndex(), getColumnProjections(optional)));
+    }
+    
+    private Collection<ColumnProjection> getColumnProjections(final String columnName) {
+        return Collections.singletonList(new ColumnProjection(null, columnName, null));
+    }
+}
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/alter/alter.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/alter/alter-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/alter/alter.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/alter/alter-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create-index.xml
similarity index 62%
copy from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create.xml
copy to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create-index.xml
index 25c601921e5..5aeaf6d49f2 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create-index.xml
@@ -17,8 +17,13 @@
   -->
 
 <rewrite-assertions yaml-rule="scenario/encrypt/config/query-with-cipher.yaml">
-    <rewrite-assertion id="create_table_for_cipher" db-types="MySQL">
-        <input sql="CREATE TABLE t_account_bak (id int not null, name varchar(100) not null default '', password varchar(255) not null default '', primary key (`id`))" />
-        <output sql="CREATE TABLE t_account_bak (id int not null, name varchar(100) not null default '', cipher_password varchar(255) not null default '', assisted_query_password varchar(255) not null default '', plain_password varchar(255) not null default '', primary key (`id`))" />
+    <rewrite-assertion id="create_index_with_assisted_query_column_for_cipher" db-types="MySQL">
+        <input sql="CREATE INDEX t_account_certificate_number_idx ON t_account(certificate_number)" />
+        <output sql="CREATE INDEX t_account_certificate_number_idx ON t_account(assisted_query_certificate_number)" />
+    </rewrite-assertion>
+
+    <rewrite-assertion id="create_index_with_cipher_column_for_cipher" db-types="MySQL">
+        <input sql="CREATE INDEX t_account_amount_idx ON t_account(amount)" />
+        <output sql="CREATE INDEX t_account_amount_idx ON t_account(cipher_amount)" />
     </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/ddl/create/create-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_column.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-column.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_column.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-column.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_on_duplicate.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-on-duplicate.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_on_duplicate.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-on-duplicate.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_set.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-set.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert_set.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/insert/insert-set.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_group_by.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-group-by.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_group_by.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-group-by.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_join.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-join.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_join.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-join.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_order_by.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-order-by.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_order_by.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-order-by.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_projection.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-projection.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_projection.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-projection.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_subquery.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_subquery.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-subquery.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_where.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-where.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select_where.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-cipher/dml/select/select-where.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/alter/alter.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/alter/alter-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/alter/alter.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/alter/alter-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create-index.xml
similarity index 61%
copy from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create.xml
copy to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create-index.xml
index db7a8543fbc..4c79e936dac 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create-index.xml
@@ -17,8 +17,13 @@
   -->
 
 <rewrite-assertions yaml-rule="scenario/encrypt/config/query-with-plain.yaml">
-    <rewrite-assertion id="create_table_for_plain" db-types="MySQL">
-        <input sql="CREATE TABLE t_account_bak (id int not null, name varchar(100) not null default '', password varchar(255) not null default '', primary key (`id`))" />
-        <output sql="CREATE TABLE t_account_bak (id int not null, name varchar(100) not null default '', cipher_password varchar(255) not null default '', assisted_query_password varchar(255) not null default '', plain_password varchar(255) not null default '', primary key (`id`))" />
+    <rewrite-assertion id="create_index_with_assisted_query_column_for_cipher" db-types="MySQL">
+        <input sql="CREATE INDEX t_account_bak_certificate_number_idx ON t_account_bak(certificate_number)" />
+        <output sql="CREATE INDEX t_account_bak_certificate_number_idx ON t_account_bak(plain_certificate_number)" />
+    </rewrite-assertion>
+
+    <rewrite-assertion id="create_index_with_cipher_column_for_cipher" db-types="MySQL">
+        <input sql="CREATE INDEX t_account_bak_amount_idx ON t_account_bak(amount)" />
+        <output sql="CREATE INDEX t_account_bak_amount_idx ON t_account_bak(plain_amount)" />
     </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/ddl/create/create-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_column.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-column.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_column.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-column.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_on_duplicate.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-on-duplicate.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_on_duplicate.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-on-duplicate.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_set.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-set.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert_set.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/insert/insert-set.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_group_by.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-group-by.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_group_by.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-group-by.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_join.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-join.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_join.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-join.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_order_by.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-order-by.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_order_by.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-order-by.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-projection.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-projection.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_subquery.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-subquery.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_subquery.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-subquery.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_where.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-where.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_where.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select-where.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/ddl/create/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/ddl/create/create-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/ddl/create/create.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/ddl/create/create-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert_column.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert-column.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert_column.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert-column.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert_set.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert-set.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert_set.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/insert/insert-set.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_join.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-join.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_join.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-join.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_projection.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_projection.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-projection.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_subquery.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-subquery.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_subquery.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-subquery.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_where.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-where.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select_where.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-cipher/dml/select/select-where.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select_projection.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select-projection.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select_projection.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select-projection.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select_where.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select-where.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select_where.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/mix/case/query-with-plain/dml/select/select-where.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/analyze.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dal/analyze.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/analyze.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dal/analyze.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/alter-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/alter-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/close.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/close.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/close.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/close.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/create-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/create-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/cursor.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/cursor.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/cursor.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/cursor.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/drop-table.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/drop-table.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/fetch.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/fetch.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/fetch.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/fetch.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/index.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/index.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/index.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/index.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/move.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/move.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/move.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/move.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/show.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/show.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/show.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/ddl/show.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/copy.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/copy.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/copy.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/copy.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/delete.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/delete.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/delete.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/insert.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/insert.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/insert.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/insert.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/select.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/select.xml
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/update.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/update.xml
similarity index 100%
rename from shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/update.xml
rename to shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/dml/update.xml