github-actions[bot] commented on code in PR #64080:
URL: https://github.com/apache/doris/pull/64080#discussion_r3385314788


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushProjectThroughUnion.java:
##########
@@ -60,7 +61,12 @@ public static boolean canPushProject(List<NamedExpression> 
projects, LogicalSetO
             if (e instanceof SlotReference) {
                 return true;
             } else {
-                Expression expr = 
ExpressionUtils.getExpressionCoveredByCast(e.child(0));
+                Expression expr;
+                if (logicalSetOperation.getQualifier().equals(Qualifier.ALL)) {
+                    expr = 
ExpressionUtils.getExpressionCoveredByCast(e.child(0));
+                } else {

Review Comment:
   This still lets `UNION DISTINCT` run after a projection that is not 
injective as a tuple. The check proves each expression is a slot or an 
injective cast of one slot, but it never verifies that the referenced slots 
form a permutation of the set-op output. For example:
   
   ```sql
   select cast(a as bigint), cast(a as bigint)
   from (select 1 a, 2 b union select 1, 3) t;
   ```
   
   Before the rewrite, the inner union keeps two distinct `(a,b)` rows and the 
outer project returns two `(1,1)` rows. After this rule pushes the project into 
both children, the union distinct sees only `(1,1)` and collapses them to one 
row. For non-`UNION ALL` set ops, please require the stripped slots to cover 
every output slot exactly once (or otherwise prove the whole projection vector 
is injective), not just each expression independently.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to