raghavyadav01 opened a new pull request, #26836:
URL: https://github.com/apache/datafusion/pull/26836

   ## Which issue does this PR close?
   
   - Closes #26572.
   
   ## Rationale for this change
   
   - With more than one partition, `SELECT t.a, (SELECT max(a) FROM t) AS m ... 
ORDER BY t.a, m LIMIT 5` fails with `SanityCheckPlan`.
   - `ProjectionExec` does not know `m` is constant, so the child ordering 
`[a]` is not seen to satisfy `[a, m]`.
   - `ScalarSubqueryExpr` already reports itself as a singleton, but 
`is_expr_constant` only treated a `Literal` leaf as constant.
   
   ## What changes are included in this PR?
   
   - `is_expr_constant` treats a leaf that reports `SortProperties::Singleton` 
as `Uniform(None)`: the same value everywhere, not known yet.
   - Two unknown constants are never assumed equal:
     - `add_constant` no longer merges two `Uniform(None)` constants into one 
class.
     - `UNION` turns two `Uniform(None)` sides into `Heterogeneous`.
     - Without these, a UNION of two different subqueries lost its sort.
   - A volatile expression is never constant, even when its inputs are. This 
was already possible on main for a literal argument (`v(1)`).
   
   ## What is the testing strategy for this PR?
   
   - New `subquery.slt` cases:
     - the query from the issue, plus a variant with a DESC column;
     - a UNION of two different subqueries (plan keeps the merge, rows come 
back sorted);
     - two subqueries in one projection.
   - Unit tests in `class.rs`:
     - a subquery is `Uniform(None)` and a column is not constant;
     - unknown constants stay in separate classes, equal known values still 
merge;
     - a volatile function of a literal or a subquery is not constant, a stable 
one is.
   - Without the change, both issue queries fail with the same 
`SanityCheckPlan` error.
   
   ## Are there any user-facing changes?
   
   - No API changes. Queries that failed now plan, and some plans drop a sort 
that a constant made unnecessary.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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