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

   ## Which issue does this PR close?
   
   - Closes #27763.
   
   ## Rationale for this change
   
   planning a sort or group by over a column computed by a deep expression like 
`a + 1 + ... + 1` got way slower in 56, roughly cubic in the depth (about 6.5s 
vs 0.035s at depth 200 in the issue). since #26747 the deep expression stays in 
the alias's equivalence class, so finding the ordering of `s` walks the whole 
expression, and the walk normalized every node from scratch. each of those 
normalizations hashes the whole subtree under the node, so the cost stacks up 
fast.
   
   ## What changes are included in this PR?
   
   - `SortKeyWalk` now keeps the normal form and the "is fixed" flag of each 
node in the walk tree and builds the parent's from its children's, instead of 
calling `normalize_expr` and `is_fixed` on every subtree. the result should be 
identical, since `normalize_expr` is a bottom-up transform anyway. a node that 
gets swapped for a canonical expression still has `is_fixed` checked on that 
canonical expression like before.
   - `is_fixed` is split into `is_fixed_with`, so the parent can reuse what the 
children already found.
   - two new `sql_planner` benchmarks: `physical_sort_by_deep_expr_100` and 
`physical_group_by_deep_expr_100`.
   
   ## What is the testing strategy for this PR?
   
   - new unit test `deep_expression_is_normalized_once` in `walk.rs`. it wraps 
the leaf in an expression that counts how often it gets hashed and checks that 
`ordering_satisfy` hashes each sub-expression a bounded number of times, for 
both the sorted and unsorted case. on main it hashes 40000 times at depth 200, 
with this change about 400.
   - existing physical-expr, physical-plan, physical-optimizer and sqllogictest 
suites pass.
   - locally an unsatisfied `ordering_satisfy` over a depth-200 alias went from 
~5.3s to ~20ms in release.
   
   ## Are there any user-facing changes?
   
   no, just faster planning. no api changes.
   


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