shihchengwei-lab commented on PR #30155:
URL: https://github.com/apache/flink/pull/30155#issuecomment-7216229497

   I came over from #30075 and found a case where the reorder changes which row 
a `UNION ALL` branch keeps:
   
   ```sql
   CREATE MATERIALIZED TABLE mt (y, x) AS
   SELECT a AS x, c AS y
   FROM (VALUES (CAST(1 AS BIGINT), 90), (CAST(2 AS BIGINT), 10)) AS t(a, c)
   WHERE 1 = 0
   UNION ALL
   (SELECT a AS y, c AS x
    FROM (VALUES (CAST(1 AS BIGINT), 90), (CAST(2 AS BIGINT), 10)) AS t(a, c)
    ORDER BY x LIMIT 1);
   ```
   
   In the right branch, `x` originally means `c`, so it keeps `(a, c) = (2, 
10)`. I checked the converter output on this PR: it rewrites the branch as 
`SELECT c AS y, a AS x ... ORDER BY x`, making `x` mean `a` and keeping `(1, 
90)` instead. To preserve the original row choice, the reordered `(y, x)` 
should be `(10, 2)`; the stored query produces `(90, 1)`.
   
   Could the rewrite keep this branch sorting by `c`? The two rows above would 
make a regression test for it.
   
   AI disclosure: I used AI to help review this case and draft the comment. I 
verified the converter output locally.
   


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