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

   ## Which issue does this PR close?
   
   Related to apache/datafusion#23213 and the earlier unmerged 
apache/datafusion#23214.
   
   ## Rationale for this change
   
   Several uncorrelated scalar reductions in one projection can cause repeated 
scans of the same table. TPC-DS Q9 has five CASE expressions that together 
request fifteen such reductions.
   
   ## What changes are included in this PR?
   
   Collect compatible scalar COUNT and AVG expressions on a shared scan. 
Compute their results using aggregate FILTER clauses and join the single output 
row to the original outer input. Retain the disjunction of contributing 
predicates on the scan so file pruning can still run. Compared with #23214, 
this draft restricts admission to the built-in functions and checks source 
identity.
   
   ## What is the testing strategy for this PR?
   
   Use SF1 Parquet with ten target partitions. Compare the original Q9 result 
and schema across builds. Check empty inputs, NULL averages and the scan count 
in the optimized plan.
   
   Independent release builds from `04b910869` on macOS arm64, using DuckDB 
1.4.1 SF1 Parquet data, upstream query files and ten target partitions. For 
each arm, five fresh processes ran the original query seven times each. Values 
are median warm SQL times in milliseconds, excluding the first execution of 
each process. Each independently built patch also completed all 22 TPC-H and 99 
TPC-DS queries with baseline row counts.
   
   | Query | Baseline ms | Candidate ms | Change |
   | --- | ---: | ---: | ---: |
   | TPC-DS Q9 | 56.60 | 16.65 | -70.6% |
   | TPC-H Q18 | 78.25 | 73.95 | -5.5% |
   
   The executed Q9 plan has one store_sales scan, down from fifteen. Q18 is a 
TPC-H control.
   
   Reproduce a query from the benchmarks directory with:
   
   ```sh
   dfbench tpcds -p "$TPCDS_PARQUET" -Q ../datafusion/core/tests/tpc-ds -q 9 -n 
10 -i 7
   dfbench tpch -p "$TPCH_DATA" -f parquet -q 18 -n 10 -i 7
   ```
   
   ## Are there any user-facing changes?
   
   Eligible plans can use a single fact scan.
   
   Implementation and benchmark preparation were AI-assisted.
   


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