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

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

Reply via email to