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

   ## Which issue does this PR close?
   
   - Related to #15775.
   
   ## Rationale for this change
   
   The optimizer loop does two pieces of bookkeeping after every rule that cost 
more than they need to. It compares the root schema field by field even when 
the rule left the schema `Arc` untouched, and it walks the whole plan looking 
for subqueries after every change, even once it knows the plan has none.
   
   ## What changes are included in this PR?
   
   - `assert_expected_schema` returns early when the plan's schema is the same 
`Arc` as the expected one.
   - The pass loop rescans for subqueries after a rule only when the plan 
already contained one. No built-in rule creates a subquery on a plan that 
lacked one; a custom rule that does has that inner plan visited from the next 
pass, and a debug build logs which rule did it.
   
   Planning benchmarks, interleaved against the base commit, noise floor about 
2%:
   
   | benchmark | change |
   |---|---|
   | optimizer_select_all_from_1000 | -5% |
   | logical_wide_aggregate_100_exprs | -4% |
   | physical_select_all_from_1000 | -3.5% |
   | optimizer_wide_filter_200 | -3% |
   | TPC-H planning | within noise |
   
   ## What is the testing strategy for this PR?
   
   New unit tests: 
`assert_expected_schema_accepts_same_arc_and_rejects_renamed_schema` in 
`datafusion/expr` and 
`optimizer_terminates_after_one_pass_when_no_rule_transforms` in 
`datafusion/optimizer`. Existing cycle-detection tests in the optimizer and the 
`joins`, `predicates`, `subquery` and `explain` sqllogictest files pass 
unchanged.
   
   ## Are there any user-facing changes?
   
   Only for embedders who register a custom optimizer rule that creates a 
subquery on a plan without any: the subquery's inner plan is optimized from the 
following pass rather than the same one.
   


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