You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/10 06:33:06 UTC

[GitHub] [shardingsphere] shuvigoss opened a new issue, #20096: encryption distinct select bug~

shuvigoss opened a new issue, #20096:
URL: https://github.com/apache/shardingsphere/issues/20096

   ## Bug Report
   Mysql 5.7 with shardingsphere 5.1.2
   -- `sharding-demo`.t_user definition
   
   CREATE TABLE `t_user` (
     `user_id` bigint(20) NOT NULL COMMENT '用户唯一ID',
     `fullname` varchar(50) DEFAULT NULL COMMENT '名字',
     `user_type` varchar(255) DEFAULT NULL COMMENT '类型',
     `cipher_pwd` varchar(255) DEFAULT NULL COMMENT '密码',
     `mobile` varchar(100) DEFAULT NULL COMMENT '手机号',
     `mobile_data` varchar(100) DEFAULT NULL COMMENT '手机号',
     `id_card` varchar(60) DEFAULT NULL COMMENT '身份证',
     PRIMARY KEY (`user_id`)
   ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
   
   I want the encryption fullname field,insert is OK, select is OK, bug use select distinct fullname will throw exception 
   
   
   Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -8
   	at java.lang.String.substring(String.java:1967)
   	at org.apache.shardingsphere.infra.rewrite.sql.impl.AbstractSQLBuilder.getConjunctionText(AbstractSQLBuilder.java:64)
   	at org.apache.shardingsphere.infra.rewrite.sql.impl.AbstractSQLBuilder.toSQL(AbstractSQLBuilder.java:47)
   	at org.apache.shardingsphere.infra.rewrite.engine.RouteSQLRewriteEngine.addSQLRewriteUnits(RouteSQLRewriteEngine.java:96)
   	at org.apache.shardingsphere.infra.rewrite.engine.RouteSQLRewriteEngine.rewrite(RouteSQLRewriteEngine.java:72)
   	at org.apache.shardingsphere.infra.rewrite.SQLRewriteEntry.rewrite(SQLRewriteEntry.java:73)
   	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.rewrite(KernelProcessor.java:59)
   	at org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:47)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.createExecutionContext(ShardingSphereStatement.java:474)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement.executeQuery(ShardingSphereStatement.java:156)
   
   
   ``` java
       val columnConfigAes =
           new EncryptColumnRuleConfiguration("fullname", "fullname", "", "", "name_encryptor", null);
    ....
     val query = connection.createStatement();
       ResultSet rs = query.executeQuery("select distinct t.fullname from t_user t ");
   ```
   
   i debug with IDE found `AbstractSQLBuilder` toSQL() method getConjunctionText throw exception.
   ![image](https://user-images.githubusercontent.com/3062921/184276353-b40d88fb-5322-45cd-8b00-98ac05a2f9bf.png)
   
   will be create 2 SQLToken with the save start stop index .
   
   i use `select distinct t.fullname from t_user t order by fullname` is OK。
   i have a question about `SelectStatementContext`,why create `OrderByContextEngine` Special handling `private OrderByContext createOrderByContextForDistinctRowWithoutGroupBy(final SelectStatement selectStatement, final GroupByContext groupByContext)`  distinct row must have order by expression?
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu commented on issue #20096: encryption distinct select bug~

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on issue #20096:
URL: https://github.com/apache/shardingsphere/issues/20096#issuecomment-1654826270

   Thank you @wangtiga, you can try to solve other issue which relate to encrypt now.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] wangtiga commented on issue #20096: encryption distinct select bug~

Posted by "wangtiga (via GitHub)" <gi...@apache.org>.
wangtiga commented on issue #20096:
URL: https://github.com/apache/shardingsphere/issues/20096#issuecomment-1653718759

   I want to fix this problem and submit pull request already.   see https://github.com/apache/shardingsphere/pull/26305


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu closed issue #20096: encryption distinct select bug~

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu closed issue #20096: encryption distinct select bug~
URL: https://github.com/apache/shardingsphere/issues/20096


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] ZhaoAlice commented on issue #20096: encryption distinct select bug~

Posted by GitBox <gi...@apache.org>.
ZhaoAlice commented on issue #20096:
URL: https://github.com/apache/shardingsphere/issues/20096#issuecomment-1334913740

   Hello, I have met the same problem.
   Mysql 5.7.31 with shardingsphere 5.1.1
   
   debug code:
   ```
   public final class OrderByContextEngine {
       
       /**
        * Create order by context.
        *
        * @param selectStatement select statement
        * @param groupByContext group by context
        * @return order by context
        */
       public OrderByContext createOrderBy(final SelectStatement selectStatement, final GroupByContext groupByContext) {
       if (!selectStatement.getOrderBy().isPresent() || selectStatement.getOrderBy().get().getOrderByItems().isEmpty()) {
               OrderByContext orderByItems = createOrderByContextForDistinctRowWithoutGroupBy(selectStatement, groupByContext);
               return null != orderByItems ? orderByItems : new OrderByContext(groupByContext.getItems(), !groupByContext.getItems().isEmpty());
           }
           List<OrderByItem> orderByItems = new LinkedList<>();
           for (OrderByItemSegment each : selectStatement.getOrderBy().get().getOrderByItems()) {
               OrderByItem orderByItem = new OrderByItem(each);
               if (each instanceof IndexOrderByItemSegment) {
                   orderByItem.setIndex(((IndexOrderByItemSegment) each).getColumnIndex());
               }
               orderByItems.add(orderByItem);
           }
           return new OrderByContext(orderByItems, false);
       }
   .........
   }
   ```
   I have the same question,
   Why the special handling for the select dinstinct statement without order by clause ? 
   This will cause an exception in the following code.
   ```
   public abstract class AbstractSQLBuilder implements SQLBuilder {
       
       .......
       private String getConjunctionText(final SQLToken sqlToken) {
           // startIndex > stopIndex
           return context.getSql().substring(getStartIndex(sqlToken), getStopIndex(sqlToken));
       }
       
       private int getStartIndex(final SQLToken sqlToken) {
           int startIndex = sqlToken instanceof Substitutable ? ((Substitutable) sqlToken).getStopIndex() + 1 : sqlToken.getStartIndex();
           return Math.min(startIndex, context.getSql().length());
       }
       
       private int getStopIndex(final SQLToken sqlToken) {
           int currentSQLTokenIndex = context.getSqlTokens().indexOf(sqlToken);
           return context.getSqlTokens().size() - 1 == currentSQLTokenIndex ? context.getSql().length() : context.getSqlTokens().get(currentSQLTokenIndex + 1).getStartIndex();
       }
   }
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] commented on issue #20096: encryption distinct select bug~

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on issue #20096:
URL: https://github.com/apache/shardingsphere/issues/20096#issuecomment-1272348866

   Hello , this issue has not received a reply for several days.
   This issue is supposed to be closed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] github-actions[bot] closed issue #20096: encryption distinct select bug~

Posted by GitBox <gi...@apache.org>.
github-actions[bot] closed issue #20096: encryption distinct select bug~
URL: https://github.com/apache/shardingsphere/issues/20096


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org