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

   ## Which issue does this PR close?
   
   No linked issue.
   
   ## Rationale for this change
   
   TPC-DS Q47 and Q57 each join the same ranked input three times to obtain the 
preceding and following row. One pass over the grouped input can supply all 
three outputs.
   
   ## What changes are included in this PR?
   
   Recognize ordinary equality joins on adjacent ranks when grouping proves the 
ordering has no peers. Replace the two neighbor joins with offset-one windows. 
Check neighbor existence independently of nullable payloads and exclude NULL 
partition keys according to inner-join semantics. The separate batched 
evaluation experiment gave mixed incremental results and is omitted.
   
   ## What is the testing strategy for this PR?
   
   Compare the full original Q47 and Q57 results with the baseline. Exercise 
tied ranks, NULL partition keys, NULL payloads, nonunit offsets and small 
record batches.
   
   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 Q47 | 132.55 | 40.15 | -69.7% |
   | TPC-DS Q57 | 89.60 | 32.05 | -64.2% |
   | TPC-H Q18 | 98.90 | 96.55 | -2.4% |
   
   The executed Q47 and Q57 plans each use a single ranked producer. Both 
retained all 100 result rows. In a separate ablation, adding batched offset-one 
evaluation to the rewrite changed Q47 from 46.35 to 44.40 ms and Q57 from 31.90 
to 32.20 ms. This PR contains the logical rewrite alone.
   
   Reproduce a query from the benchmarks directory with:
   
   ```sh
   dfbench tpcds -p "$TPCDS_PARQUET" -Q ../datafusion/core/tests/tpc-ds -q 47 
-n 10 -i 7
   dfbench tpch -p "$TPCH_DATA" -f parquet -q 18 -n 10 -i 7
   ```
   
   ## Are there any user-facing changes?
   
   Eligible ranked self-joins can be replaced by bounded windows.
   
   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