fbcouto commented on issue #21381:
URL: https://github.com/apache/datafusion/issues/21381#issuecomment-7062844145

   Hi! Some measurements that may be useful here. I built an extension 
operator, outside DataFusion, that replaces the final `SortPreservingMergeExec` 
over sorted partitions with a parallel merge (and, in a second mode, the whole 
`SortExec` + `SortPreservingMergeExec`): 
https://github.com/fbcouto/multimerge_apache_Datafusion. It comes in through a 
physical optimizer rule, without changes to DataFusion. The merge finds the 
sorted runs and merges them with all cores (cache-blocked k-way merge, split 
across threads by co-ranking). The rule also takes the case in this issue, a 
`SortPreservingMergeExec` without a `LIMIT` over partitions that are already 
sorted (as after sort pushdown), but the numbers below are for full sorts.
   
   On the `sort_tpch` queries (DataFusion 55.3.0, 24 partitions, AMD EPYC 7B13 
with 24 vCPUs), replacing only the final merge (DataFusion still sorts each 
partition):
   
   | | speedup over DataFusion's plan |
   | :--- | :--- |
   | SF1, table in memory | 2.32x to 6.66x, geometric mean 3.98x |
   | SF1, reading Parquet | 1.76x to 5.52x, geometric mean 3.17x |
   | SF10, reading Parquet | 1.69x to 5.45x, geometric mean 3.48x (10 of the 11 
queries) |
   
   Most of the gain is the merge itself: with 24 sorted partitions, the 
single-threaded merge takes most of the query's time. With the rule installed, 
DataFusion's sqllogictest suite shows only `EXPLAIN` differences in this mode.
   
   The cost, in this version: the operator reads its whole input and builds its 
whole output before returning it (no streaming, no spilling), so it needs more 
memory than `SortPreservingMergeExec`, up to about 3x DataFusion's peak at SF10 
(Q7: 39 GB against 12 GB).
   
   Would numbers like these help the work on a parallel merge inside DataFusion 
(here and in #7181)? I would be glad to help with it, or to move the extension 
to `datafusion-contrib` if that is a better home for it.
   
   There is also a 5-minute video with more detail (DataFusion's sort 
benchmark, the sqllogictest runs, the limits). It is narrated with a synthetic 
voice (Kokoro, an open-source model) reading my script:
   
   
   
https://github.com/user-attachments/assets/9da112fb-04f7-4e48-a7a4-892be6545b51


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