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/12/02 08:41:46 UTC

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

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