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

   
   I am seeing an issue with arithmetic aggregate expressions of the form:
   
   SUM(...) - SUM(...)
   
   when the query runs across multiple shards.
   
   ### Example query pattern
   
   ```sql
   SELECT
       SUM(CASE
               WHEN t.record_date = DATE '2025-04-02' THEN t.value_col
               ELSE 0
           END)
       - SUM(CASE
               WHEN t.record_date = DATE '2025-03-26' THEN t.value_col
               ELSE 0
           END) AS delta_value
   FROM source_table t;
   ```
   
   ### Example numeric scenario
   
   Suppose the query runs across two shards.
   
   On shard 1, the expression `SUM(a) - SUM(b)` evaluates to `1681`.
   
   On shard 2, the expression `SUM(a) - SUM(b)` evaluates to `420`.
   
   ### Expected result
   
   2101 (1681 + 420)
   
   ### Actual result
   
   Only one shard's value is returned 1681 .
   
   ### Environment
   
   ShardingSphere version: 5.5.2  
   Database: PostgreSQL with TimescaleDB extension  
   Some tables involved are hypertables.
   
   ### Simplified sharding rule
   
   Tables are distributed across two data sources:
   
   ds_0  
   ds_1  
   
   Example configuration:
   
   ```yaml
   source_table:
     actualDataNodes: ds_${0..1}.source_table
   ```
   
   Other tables used in joins follow the same distribution pattern.
   
   ### Question
   
   Is there any limitation with cross-shard merging for expressions like 
`SUM(...) - SUM(...)` that would explain why the final result is not matching 
the expected result above?


-- 
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: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to