You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Dandandan (via GitHub)" <gi...@apache.org> on 2025/03/24 10:16:06 UTC

[I] Support zero copy hash repartitioning inside Hash Join [datafusion]

Dandandan opened a new issue, #15382:
URL: https://github.com/apache/datafusion/issues/15382

   ### Is your feature request related to a problem or challenge?
   
   Currently `RepartitionExec: partitioning=Hash` will be added whenever a hash 
   The benefit is increased parallelism, but at the cost of copying the entire table (in a not-so efficient way).
   
   We should consider lowering the cost of repartitioning by not having to copy the input.
   
   ### Describe the solution you'd like
   
   Instead of repartitioning the right side and left side input in `RepartitionExec`, support repartitioning the inputs based on a selection vector.
   
   Instead of `taking` the `RecordBatch`, we can consider doing the following:
   
   * Add a (boolean) selection vector as output column for each output partition. I.e. `true` means the row is selected for the partition.
   * The rest of the `RecordBatch` remains unchanged (i.e. no copy).
   * CoalesceBatchesExec is no longer needed for the output (reducing another copy) 
   * In the hash join algorith,, only try matching input indices for the selection vector for each partition. This seems not that hard as `get_matched_indices` already supports getting an input of input indices + hashes.
   
   ### Describe alternatives you've considered
   
   The partitioning could be done inside the hash join algorithm, however this would add more complexity to each operator (join / aggregates) to do hash-repartitioning inside 
   
   ### Additional context
   
   _No response_


-- 
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: github-unsubscribe@datafusion.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "Rich-T-kid (via GitHub)" <gi...@apache.org>.
Rich-T-kid commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-5548707642

   > The rest of the RecordBatch remains unchanged (i.e. no copy).
   
   @Dandandan Wouldn't this mean our memory consumption would grow? In this model, we'd keep each record batch alive instead of slicing it apart and allocating a new one. If record batches have backing arrays/buffers that remain referenced, won't they stick around for the duration of the query?


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "zebsme (via GitHub)" <gi...@apache.org>.
zebsme commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2752247061

   > 
   > > * Add a mode that outputs selection vectors (for now let's use dense boolean arrays so it can be added to `RecordBatch`) in `RepartitionExec`. The array outputs `true` for each row that has `hash % partition == 0` (and false if not).
   > 
   > I'll work on #15383, but I guess there are some duplicate works here.
   
   That makes sense. Perhaps we should address #15420 first - I'd be happy to help review the code.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "zebsme (via GitHub)" <gi...@apache.org>.
zebsme commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2750312644

   If anyone's interested in this, feel free to try :)


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "zebsme (via GitHub)" <gi...@apache.org>.
zebsme commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2748715468

   take


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2749333765

   @zebsme  this is likely a fairly tricky thing to implement, just FYI


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2750596093

   Yes, I agree with @alamb I don't consider this super easy. However, feel free to try and implement some steps and let us know when you need help @zebsme .
   
   Probably it makes sense to split this issue in some subtasks, these are the ones I can think of and I think the individually they might be doable for an "advanced beginner":
   
   * Add a mode that outputs selection vectors (for now let's use dense boolean arrays so it can be added to `RecordBatch`) in `RepartitionExec`. The array outputs `true` for each row that has `hash % partition == 0` (and false if not).
   * Support using this selection vector in hash join (only matching indices in the selection vector)
   * Support planning with the repartition mode (probably behind an option), run some benchmarks to decide on the default.
   
   We probably want to think about some general way of representing / using selection vectors in `RecordBatch` (or as wrapped `RecordBatch`) as well but this requires some more design / discussion.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-2751311833

   
   > * Add a mode that outputs selection vectors (for now let's use dense boolean arrays so it can be added to `RecordBatch`) in `RepartitionExec`. The array outputs `true` for each row that has `hash % partition == 0` (and false if not).
   
   I'll work on #15383, but I guess there are some duplicate works here.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


Re: [I] Support zero copy hash repartitioning for Hash Join [datafusion]

Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on issue #15382:
URL: https://github.com/apache/datafusion/issues/15382#issuecomment-5550837152

   > > The rest of the RecordBatch remains unchanged (i.e. no copy).
   > 
   > @Dandandan Wouldn't this mean our memory consumption would grow? In this model, we'd keep each record batch alive instead of slicing it apart and allocating a new one. If record batches have backing arrays/buffers that remain referenced, won't they stick around for the duration of the query?
   > 
   > besides that I think this is a pretty cool idea
   
   I think it depends - if the join reduces data, then it could grow and we maybe would need to compact it / detect this case.
   
   In other cases (each row has at least one match), not copying it might actually reduce peak memory.


-- 
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: github-unsubscribe@datafusion.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org