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

[GitHub] [shardingsphere] MrCong233 opened a new issue, #21234: The data source of the select (select) composite sql request is incorrect

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

   ## Bug Report
   
   During consistency check based on shardingsphere-proxy + openGauss 3.1.0 (1 coordination node and two data nodes ), an exception is found in one of the conditions. 
   
   ```sql
   select
       c.c_w_id, c.c_d_id, c.c_id, c.c_balance,
       (select sum(h_amount) as c_h_amount from bmsql_history h where h.h_c_w_id = c.c_w_id and h.h_c_d_id = c.c_d_id and h.h_c_id = c.c_id),
       (select sum(ol_amount) as c_ol_amount from bmsql_order_line ol, bmsql_oorder o where ol.ol_w_id = o.o_w_id and ol.ol_d_id = o.o_d_id and ol.ol_o_id = o.o_id
           and ol.ol_delivery_d is not null
           and o.o_w_id = c.c_w_id and o.o_d_id = c.c_d_id and o.o_c_id = c.c_id)
      from bmsql_customer c where c.c_w_id = 1 and c.c_d_id = 1 and c.c_id = 997;
   ```
   
   To simplify the problem description, query SQL is simplified as follows:
   
   c_w_id、c_d_id、c_id are primary keys of a customer, bmsql_history means payment records for all users. 
   
   Use select(select) composite sql to query the sum of all payment records of a customer, c_h_amount = 4055.82, only one datasource is requested.
   
   ```sql
   select
       c.c_w_id, c.c_d_id, c.c_id, c.c_balance,
       (select sum(h_amount) as c_h_amount from bmsql_history h where h.h_c_w_id = c.c_w_id and h.h_c_d_id = c.c_d_id and h.h_c_id = c.c_id)
   from bmsql_customer c where c.c_w_id = 1 and c.c_d_id = 1 and c.c_id = 997;
   ```
   ![image-20220928144951824-1664348911579-1](https://user-images.githubusercontent.com/27768675/192719871-685a9236-0446-4e46-b147-8365c62cce67.png)
   ![image-20220928145459486](https://user-images.githubusercontent.com/27768675/192719926-d8787a7f-5b8f-4813-a549-4deb06c7a532.png)
   
   
   Directly query the total payment amount of the user, c_amount = 18086.50, two datasources were requested.
   
   ```sql
   select * from bmsql_history h where h.h_c_w_id = 1 and h.h_c_d_id = 1 and h.h_c_id = 997;
   select sum(h_amount) from bmsql_history h where h.h_c_w_id = 1 and h.h_c_d_id = 1 and h.h_c_id = 997;
   ```
   ![image-20220928143806819](https://user-images.githubusercontent.com/27768675/192719981-634f4e17-8fa6-4b28-8a33-3a6e6c87dfca.png)
   ![image-20220928145410537](https://user-images.githubusercontent.com/27768675/192719993-f2d1a332-1208-4599-a331-c51b17ec82f4.png)
   
   
   ### Which version of ShardingSphere did you use?
   
   5.2.0 snapshot, commit d4c0048a5c3fd61625b3b502380c65b7e88cd927
   
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   
   ShardingSphere-Proxy
   
   ### Expected behavior
   
   The total payment amount of the customer in the select(select) query is equal to the total payment amount of the user in the direct query.
   
   ### Actual behavior
   
   The total payment amount of the customer in the select(select) query, sum(h_amount) = 4055.82, only one datasource is requested.
   
   The total payment amount of the customer in the direct query, sum(h_amount) = 18086.5, two datasources are requested.
   
   ### Reason analyze (If you can)
   
   When executing select(select)  composite sql, shardingshere determines the target datasources based on th table bmsql_customer's rules,  doesn't consider the table bmsql_history's rules.
   
   ![image-20220928145459486](https://user-images.githubusercontent.com/27768675/192720063-b6753908-72bb-4f3a-8f83-24062f348807.png)
   
   ![image-20220928154504109](https://user-images.githubusercontent.com/27768675/192720086-fe869007-1630-4b74-b2f9-5f75dc
   ![image-20220928154514934](https://user-images.githubusercontent.com/27768675/192720124-64a0561e-69d4-45fc-b75d-812afa34d51c.png)
   b2e6a1.png)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc.
   
   * steps to reproduce the behavior
   
   1. execute benchmark for an hour
   2. gsql to shardingsphere
   3. execute `select sum(h_amount) from bmsql_history h where h.h_c_w_id = 1 and h.h_c_d_id = 1 and h.h_c_id = 997;`,check sum(h_amount)
   4. execute `select
          c.c_w_id, c.c_d_id, c.c_id, c.c_balance,
          (select sum(h_amount) as c_h_amount from bmsql_history h where h.h_c_w_id = c.c_w_id and h.h_c_d_id = c.c_d_id and h.h_c_id = c.c_id)
      from bmsql_customer c where c.c_w_id = 1 and c.c_d_id = 1 and c.c_id = 997;`, check c_h_amount.
   
   * table bmsql_customer
   
   ![image-20220928153431397](select(select)复杂查询数据源路由问题.assets/image-20220928153431397.png)
   
   * table bmsql_history
   
   ![image-20220928153514800](select(select)复杂查询数据源路由问题.assets/image-20220928153514800.png)
   
   * config-sharding.yaml
   
   ```config-sharding.yaml
   databaseName: sharding_db
   dataSources:
     ds_0:
       connectionTimeoutMilliseconds: 3600000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 410
       minPoolSize: 400
     ds_1:
       connectionTimeoutMilliseconds: 3600000
       idleTimeoutMilliseconds: 60000
       maxLifetimeMilliseconds: 1800000
       maxPoolSize: 410
       minPoolSize: 400
   rules:
     - !SHARDING
       bindingTables:
         - bmsql_warehouse, bmsql_customer
         - bmsql_stock, bmsql_district, bmsql_order_line
       broadcastTables:
         - bmsql_item
       defaultDatabaseStrategy:
         standard:
           shardingAlgorithmName: database_inline
           shardingColumn: ds_id
       defaultTableStrategy:
         none: null
       shardingAlgorithms:
         database_inline:
           props:
             algorithm-expression: ds_${ds_id % 1}
           type: INLINE
         ds_inline_mod:
           props:
             sharding-count: 2
           type: MOD
       tables:
         bmsql_config:
           actualDataNodes: ds_${0..1}.bmsql_config
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: cfg_id
         bmsql_customer:
           actualDataNodes: ds_${0..1}.bmsql_customer
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: c_w_id
         bmsql_district:
           actualDataNodes: ds_${0..1}.bmsql_district
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: d_w_id
         bmsql_history:
           actualDataNodes: ds_${0..1}.bmsql_history
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: h_w_id
         bmsql_new_order:
           actualDataNodes: ds_${0..1}.bmsql_new_order
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: no_w_id
         bmsql_oorder:
           actualDataNodes: ds_${0..1}.bmsql_oorder
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: o_w_id
         bmsql_order_line:
           actualDataNodes: ds_${0..1}.bmsql_order_line
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: ol_w_id
         bmsql_stock:
           actualDataNodes: ds_${0..1}.bmsql_stock
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: s_w_id
         bmsql_warehouse:
           actualDataNodes: ds_${0..1}.bmsql_warehouse
           databaseStrategy:
             standard:
               shardingAlgorithmName: ds_inline_mod
               shardingColumn: w_id
         t_order:
           actualDataNodes: ds_${0..0}.t_order
   ```
   
   ### 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] FlyingZC commented on issue #21234: The data source of the select (select) composite sql request is incorrect

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

   preview
   use one ds:
   ![image](https://user-images.githubusercontent.com/19788130/192745976-b027416c-149e-4992-966e-f76461ad1393.png)
   
   use two ts:
   ![image](https://user-images.githubusercontent.com/19788130/192746008-001031cf-065b-4bc7-a900-759920b5a6f1.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] FlyingZC commented on issue #21234: The data source of the select (select) composite sql request is incorrect

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

   Now ss does not support subqueries, you can try the sql-federation experiment function.You can config the `federation-type: ADVANCED` param in server.yaml to enable the sql-federation.


-- 
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] terrymanu commented on issue #21234: The data source of the select (select) composite sql request is incorrect

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

   I just set the issue as `invalid` because the author close it without any reason.


-- 
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] FlyingZC commented on issue #21234: The data source of the select (select) composite sql request is incorrect

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

   You can check the sharding support at this page: 
   https://shardingsphere.apache.org/document/current/cn/features/sharding/limitation/


-- 
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] MrCong233 closed issue #21234: The data source of the select (select) composite sql request is incorrect

Posted by GitBox <gi...@apache.org>.
MrCong233 closed issue #21234: The data source of the select (select) composite sql  request is incorrect 
URL: https://github.com/apache/shardingsphere/issues/21234


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