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/09 07:28:33 UTC

[GitHub] [shardingsphere] strongduanmu opened a new issue, #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation

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

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   
   https://github.com/apache/shardingsphere/commit/40b5076d63d21c0bb19cca16d4db211648b3c7f5
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-Proxy
   
   ### Expected behavior
   
   Execute `SELECT * FROM t_order UNION ALL SELECT * FROM t_order;`, then get following result.
   
   ```
    order_id | user_id | status | merchant_id | remark | creation_date 
   ----------+---------+--------+-------------+--------+---------------
        1000 |      10 | init   |           1 | test   | 2017-08-08
        1001 |      10 | init   |           2 | test   | 2017-08-08
        2000 |      20 | init   |           3 | test   | 2017-08-08
        2001 |      20 | init   |           4 | test   | 2017-08-08
        1100 |      11 | init   |           5 | test   | 2017-08-08
        1101 |      11 | init   |           6 | test   | 2017-08-08
        2100 |      21 | init   |           7 | test   | 2017-08-08
        2101 |      21 | init   |           8 | test   | 2017-08-08
        1200 |      12 | init   |           9 | test   | 2017-08-08
        1201 |      12 | init   |          10 | test   | 2017-08-08
        2200 |      22 | init   |          11 | test   | 2017-08-08
        2201 |      22 | init   |          12 | test   | 2017-08-08
        1300 |      13 | init   |          13 | test   | 2017-08-08
        1301 |      13 | init   |          14 | test   | 2017-08-08
        2300 |      23 | init   |          15 | test   | 2017-08-08
        2301 |      23 | init   |          16 | test   | 2017-08-08
        1400 |      14 | init   |          17 | test   | 2017-08-08
        1401 |      14 | init   |          18 | test   | 2017-08-08
        2400 |      24 | init   |          19 | test   | 2017-08-08
        2401 |      24 | init   |          20 | test   | 2017-08-08
        1500 |      15 | init   |           1 | test   | 2017-08-08
        1501 |      15 | init   |           2 | test   | 2017-08-08
        2500 |      25 | init   |           3 | test   | 2017-08-08
        2501 |      25 | init   |           4 | test   | 2017-08-08
        1600 |      16 | init   |           5 | test   | 2017-08-08
        1601 |      16 | init   |           6 | test   | 2017-08-08
        2600 |      26 | init   |           7 | test   | 2017-08-08
        2601 |      26 | init   |           8 | test   | 2017-08-08
        1700 |      17 | init   |           9 | test   | 2017-08-08
        1701 |      17 | init   |          10 | test   | 2017-08-08
        2700 |      27 | init   |          11 | test   | 2017-08-08
        2701 |      27 | init   |          12 | test   | 2017-08-08
        1800 |      18 | init   |          13 | test   | 2017-08-08
        1801 |      18 | init   |          14 | test   | 2017-08-08
        2800 |      28 | init   |          15 | test   | 2017-08-08
        2801 |      28 | init   |          16 | test   | 2017-08-08
        1900 |      19 | init   |          17 | test   | 2017-08-08
        1901 |      19 | init   |          18 | test   | 2017-08-08
        2900 |      29 | init   |          19 | test   | 2017-08-08
        2901 |      29 | init   |          20 | test   | 2017-08-08
        1000 |      10 | init   |           1 | test   | 2017-08-08
        1001 |      10 | init   |           2 | test   | 2017-08-08
        2000 |      20 | init   |           3 | test   | 2017-08-08
        2001 |      20 | init   |           4 | test   | 2017-08-08
        1100 |      11 | init   |           5 | test   | 2017-08-08
        1101 |      11 | init   |           6 | test   | 2017-08-08
        2100 |      21 | init   |           7 | test   | 2017-08-08
        2101 |      21 | init   |           8 | test   | 2017-08-08
        1200 |      12 | init   |           9 | test   | 2017-08-08
        1201 |      12 | init   |          10 | test   | 2017-08-08
        2200 |      22 | init   |          11 | test   | 2017-08-08
        2201 |      22 | init   |          12 | test   | 2017-08-08
        1300 |      13 | init   |          13 | test   | 2017-08-08
        1301 |      13 | init   |          14 | test   | 2017-08-08
        2300 |      23 | init   |          15 | test   | 2017-08-08
        2301 |      23 | init   |          16 | test   | 2017-08-08
        1400 |      14 | init   |          17 | test   | 2017-08-08
        1401 |      14 | init   |          18 | test   | 2017-08-08
        2400 |      24 | init   |          19 | test   | 2017-08-08
        2401 |      24 | init   |          20 | test   | 2017-08-08
        1500 |      15 | init   |           1 | test   | 2017-08-08
        1501 |      15 | init   |           2 | test   | 2017-08-08
        2500 |      25 | init   |           3 | test   | 2017-08-08
        2501 |      25 | init   |           4 | test   | 2017-08-08
        1600 |      16 | init   |           5 | test   | 2017-08-08
        1601 |      16 | init   |           6 | test   | 2017-08-08
        2600 |      26 | init   |           7 | test   | 2017-08-08
        2601 |      26 | init   |           8 | test   | 2017-08-08
        1700 |      17 | init   |           9 | test   | 2017-08-08
        1701 |      17 | init   |          10 | test   | 2017-08-08
        2700 |      27 | init   |          11 | test   | 2017-08-08
        2701 |      27 | init   |          12 | test   | 2017-08-08
        1800 |      18 | init   |          13 | test   | 2017-08-08
        1801 |      18 | init   |          14 | test   | 2017-08-08
        2800 |      28 | init   |          15 | test   | 2017-08-08
        2801 |      28 | init   |          16 | test   | 2017-08-08
        1900 |      19 | init   |          17 | test   | 2017-08-08
        1901 |      19 | init   |          18 | test   | 2017-08-08
        2900 |      29 | init   |          19 | test   | 2017-08-08
        2901 |      29 | init   |          20 | test   | 2017-08-08
   (80 rows)
   ```
   
   ### Actual behavior
   
   ```
    order_id | user_id | status | merchant_id | remark | creation_date
   ----------+---------+--------+-------------+--------+---------------
        1000 |      10 | init   |           1 | test   | 2017-08-08
        1001 |      10 | init   |           2 | test   | 2017-08-08
        2000 |      20 | init   |           3 | test   | 2017-08-08
        2001 |      20 | init   |           4 | test   | 2017-08-08
        1100 |      11 | init   |           5 | test   | 2017-08-08
        1101 |      11 | init   |           6 | test   | 2017-08-08
        2100 |      21 | init   |           7 | test   | 2017-08-08
        2101 |      21 | init   |           8 | test   | 2017-08-08
        1200 |      12 | init   |           9 | test   | 2017-08-08
        1201 |      12 | init   |          10 | test   | 2017-08-08
        2200 |      22 | init   |          11 | test   | 2017-08-08
        2201 |      22 | init   |          12 | test   | 2017-08-08
        1300 |      13 | init   |          13 | test   | 2017-08-08
        1301 |      13 | init   |          14 | test   | 2017-08-08
        2300 |      23 | init   |          15 | test   | 2017-08-08
        2301 |      23 | init   |          16 | test   | 2017-08-08
        1400 |      14 | init   |          17 | test   | 2017-08-08
        1401 |      14 | init   |          18 | test   | 2017-08-08
        2400 |      24 | init   |          19 | test   | 2017-08-08
        2401 |      24 | init   |          20 | test   | 2017-08-08
        1500 |      15 | init   |           1 | test   | 2017-08-08
        1501 |      15 | init   |           2 | test   | 2017-08-08
        2500 |      25 | init   |           3 | test   | 2017-08-08
        2501 |      25 | init   |           4 | test   | 2017-08-08
        1600 |      16 | init   |           5 | test   | 2017-08-08
        1601 |      16 | init   |           6 | test   | 2017-08-08
        2600 |      26 | init   |           7 | test   | 2017-08-08
        2601 |      26 | init   |           8 | test   | 2017-08-08
        1700 |      17 | init   |           9 | test   | 2017-08-08
        1701 |      17 | init   |          10 | test   | 2017-08-08
        2700 |      27 | init   |          11 | test   | 2017-08-08
        2701 |      27 | init   |          12 | test   | 2017-08-08
        1800 |      18 | init   |          13 | test   | 2017-08-08
        1801 |      18 | init   |          14 | test   | 2017-08-08
        2800 |      28 | init   |          15 | test   | 2017-08-08
        2801 |      28 | init   |          16 | test   | 2017-08-08
        1900 |      19 | init   |          17 | test   | 2017-08-08
        1901 |      19 | init   |          18 | test   | 2017-08-08
        2900 |      29 | init   |          19 | test   | 2017-08-08
        2901 |      29 | init   |          20 | test   | 2017-08-08
   (40 rows)
   ```
   
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   


-- 
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 #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation

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

   l have do some research in calcite, when we execute `SELECT * FROM t_order UNION ALL SELECT * FROM t_order;`, calcite will generate following java code.
   
   ```
   public org.apache.calcite.linq4j.Enumerable bind(final org.apache.calcite.DataContext root) {
     final org.apache.calcite.linq4j.Enumerable child0 = org.apache.calcite.schema.Schemas.enumerable((org.apache.calcite.schema.ProjectableFilterableTable) root.getRootSchema().getSubSchema("public").getTable("t_order"), root);
     return child0.concat(child0);
   }
   
   
   public Class getElementType() {
     return java.lang.Object[].class;
   }
   ```
   
   Since both select statements are same, so calcite generate `child0.concat(child0)` to handle this logic, and child0 corresponds to the result set returned after pushdown. Fetch two identical objects will cause the second result set to fail to be accessed normally, and the query result is empty, so the UNION result return wrong.
   
   <img width="1156" alt="image" src="https://user-images.githubusercontent.com/10829171/194790741-0e84f102-ad27-4a73-9dfa-8b9ad1409c8d.png">
   
   


-- 
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 issue #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation

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

   Ref #19580.


-- 
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 issue #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation

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

   When I execute `SELECT * FROM t_order INTERSECT ALL SELECT * FROM t_order;`, following result return.
   
   ```
   sharding_db=> SELECT * FROM t_order INTERSECT ALL SELECT * FROM t_order;
    order_id | user_id | status | merchant_id | remark | creation_date
   ----------+---------+--------+-------------+--------+---------------
   (0 rows)
   ```
   
   But the actual result should be.
   
   ```
    order_id | user_id | status | merchant_id | remark | creation_date 
   ----------+---------+--------+-------------+--------+---------------
        2501 |      25 | init   |           4 | test   | 2017-08-08
        1800 |      18 | init   |          13 | test   | 2017-08-08
        1900 |      19 | init   |          17 | test   | 2017-08-08
        1300 |      13 | init   |          13 | test   | 2017-08-08
        2600 |      26 | init   |           7 | test   | 2017-08-08
        1701 |      17 | init   |          10 | test   | 2017-08-08
        2801 |      28 | init   |          16 | test   | 2017-08-08
        2800 |      28 | init   |          15 | test   | 2017-08-08
        1001 |      10 | init   |           2 | test   | 2017-08-08
        2000 |      20 | init   |           3 | test   | 2017-08-08
        2301 |      23 | init   |          16 | test   | 2017-08-08
        1500 |      15 | init   |           1 | test   | 2017-08-08
        1201 |      12 | init   |          10 | test   | 2017-08-08
        2400 |      24 | init   |          19 | test   | 2017-08-08
        2201 |      22 | init   |          12 | test   | 2017-08-08
        1101 |      11 | init   |           6 | test   | 2017-08-08
        2700 |      27 | init   |          11 | test   | 2017-08-08
        1601 |      16 | init   |           6 | test   | 2017-08-08
        2300 |      23 | init   |          15 | test   | 2017-08-08
        1400 |      14 | init   |          17 | test   | 2017-08-08
        2701 |      27 | init   |          12 | test   | 2017-08-08
        1501 |      15 | init   |           2 | test   | 2017-08-08
        1401 |      14 | init   |          18 | test   | 2017-08-08
        2901 |      29 | init   |          20 | test   | 2017-08-08
        1200 |      12 | init   |           9 | test   | 2017-08-08
        2200 |      22 | init   |          11 | test   | 2017-08-08
        1700 |      17 | init   |           9 | test   | 2017-08-08
        2401 |      24 | init   |          20 | test   | 2017-08-08
        2500 |      25 | init   |           3 | test   | 2017-08-08
        2101 |      21 | init   |           8 | test   | 2017-08-08
        1600 |      16 | init   |           5 | test   | 2017-08-08
        1801 |      18 | init   |          14 | test   | 2017-08-08
        1301 |      13 | init   |          14 | test   | 2017-08-08
        2601 |      26 | init   |           8 | test   | 2017-08-08
        1100 |      11 | init   |           5 | test   | 2017-08-08
        2100 |      21 | init   |           7 | test   | 2017-08-08
        1000 |      10 | init   |           1 | test   | 2017-08-08
        2001 |      20 | init   |           4 | test   | 2017-08-08
        1901 |      19 | init   |          18 | test   | 2017-08-08
        2900 |      29 | init   |          19 | test   | 2017-08-08
   (40 rows)
   ```


-- 
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] tristaZero closed issue #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation

Posted by GitBox <gi...@apache.org>.
tristaZero closed issue #21417: SELECT UNION ALL statement return wrong result when execute with ADVANCED SQL Federation
URL: https://github.com/apache/shardingsphere/issues/21417


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