You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "wangtiga (via GitHub)" <gi...@apache.org> on 2023/06/12 10:15:28 UTC

[GitHub] [shardingsphere] wangtiga opened a new pull request, #26305: Bugfix issue 20096 encryption distinct select bug

wangtiga opened a new pull request, #26305:
URL: https://github.com/apache/shardingsphere/pull/26305

   Fixes #20096.
   
   Changes proposed in this pull request:
     - Bugfix encryption distinct select bug
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [x] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   


-- 
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 a diff in pull request #26305: Bugfix encryption distinct select bug

Posted by "wangtiga (via GitHub)" <gi...@apache.org>.
wangtiga commented on code in PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#discussion_r1238087165


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java:
##########
@@ -101,7 +101,9 @@ private Collection<OrderByItem> getOrderByItems(final SQLStatementContext sqlSta
         }
         Collection<OrderByItem> result = new LinkedList<>();
         SelectStatementContext statementContext = (SelectStatementContext) sqlStatementContext;
-        result.addAll(statementContext.getOrderByContext().getItems());
+        if (!statementContext.getOrderByContext().isGenerated()) {

Review Comment:
   To address issue #4565, the sharding feature automatically adds the ORDER BY clause when processing the "SELECT distinct amount FROM t_account" statement. However, for the account_id column that has encryption rules configured, when processing the same statement, it only needs to rewrite the encrypted column name without adding the ORDER BY clause.
   
   The presence of the orderByContext member variable in the SelectStatementContext class causes the problem described in issue #20096 when rewriting the SQL. It mistakenly assumes that the original SQL is "SELECT distinct amount FROM t_account ORDER BY amount".
   
   References:
   https://github.com/apache/shardingsphere/blob/5.3.2/test/it/rewriter/src/test/resources/scenario/sharding/case/dml/select.xml#L101
   
   https://github.com/apache/shardingsphere/pull/4597



-- 
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] tuichenchuxin commented on a diff in pull request #26305: Bugfix encryption distinct select bug

Posted by "tuichenchuxin (via GitHub)" <gi...@apache.org>.
tuichenchuxin commented on code in PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#discussion_r1234640848


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java:
##########
@@ -101,7 +101,9 @@ private Collection<OrderByItem> getOrderByItems(final SQLStatementContext sqlSta
         }
         Collection<OrderByItem> result = new LinkedList<>();
         SelectStatementContext statementContext = (SelectStatementContext) sqlStatementContext;
-        result.addAll(statementContext.getOrderByContext().getItems());
+        if (!statementContext.getOrderByContext().isGenerated()) {

Review Comment:
   Why we remove generated?



-- 
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 a diff in pull request #26305: Bugfix encryption distinct select bug

Posted by "wangtiga (via GitHub)" <gi...@apache.org>.
wangtiga commented on code in PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#discussion_r1238087165


##########
features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptOrderByItemTokenGenerator.java:
##########
@@ -101,7 +101,9 @@ private Collection<OrderByItem> getOrderByItems(final SQLStatementContext sqlSta
         }
         Collection<OrderByItem> result = new LinkedList<>();
         SelectStatementContext statementContext = (SelectStatementContext) sqlStatementContext;
-        result.addAll(statementContext.getOrderByContext().getItems());
+        if (!statementContext.getOrderByContext().isGenerated()) {

Review Comment:
   To address issue #4565, the sharding feature automatically adds the ORDER BY clause when processing the "SELECT distinct amount FROM t_account" statement. However, for the account_id column that has encryption rules configured, when processing the same statement, it only needs to rewrite the encrypted column name without adding the ORDER BY clause.
   
   The presence of the orderByContext member variable in the SelectStatementContext class causes the problem described in issue #20096 when rewriting the SQL. It mistakenly assumes that the original SQL is "SELECT distinct amount FROM t_account ORDER BY amount".
   
   References:
   https://github.com/apache/shardingsphere/blob/5.3.2/test/it/rewriter/src/test/resources/scenario/sharding/case/dml/select.xml#L101
   https://github.com/apache/shardingsphere/pull/4597



-- 
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 merged pull request #26305: Bugfix encryption distinct select bug

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #26305:
URL: 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 commented on pull request #26305: Bugfix encryption distinct select bug

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#issuecomment-1652795783

   Hi @wangtiga, can you comment on the original issue? I will assign it to you.


-- 
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 commented on pull request #26305: Bugfix encryption distinct select bug

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#issuecomment-1646845124

   Hi @wangtiga, can you merge master branch? I think this bug has been fixed.
   
   ```java
       private boolean containsOrderByItem(final SQLStatementContext sqlStatementContext) {
           if (!(sqlStatementContext instanceof SelectStatementContext)) {
               return false;
           }
           SelectStatementContext statementContext = (SelectStatementContext) sqlStatementContext;
           if (!statementContext.getOrderByContext().getItems().isEmpty() && !statementContext.getOrderByContext().isGenerated() || !statementContext.getGroupByContext().getItems().isEmpty()) {
               return true;
           }
           for (SelectStatementContext each : statementContext.getSubqueryContexts().values()) {
               if (containsOrderByItem(each)) {
                   return true;
               }
           }
           return false;
       }
   ```


-- 
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 pull request #26305: Bugfix encryption distinct select bug

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #26305:
URL: https://github.com/apache/shardingsphere/pull/26305#issuecomment-1646662124

   There hasn't been any activity on this pull request recently, and in order to prioritize active work, it has been marked as stale.


-- 
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