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

   ### Describe the bug
   
   `ArrayMap::try_new` allocates [`vec![0; range + 
1]`](https://github.com/apache/datafusion/blob/9d894e1ae001391cfde2f6d3078ac1989396ff90/datafusion/physical-plan/src/joins/array_map.rs#L165-L170)
 and rejects only `range >= usize::MAX`. With the default thresholds, the map 
serves only small ranges. A larger `perfect_hash_join_small_build_threshold`, 
or a `perfect_hash_join_min_key_density` of 0, lets it serve any range of a 
single integer key. The allocation then panics with `capacity overflow` past 
`isize::MAX` bytes. Below that, with the default unbounded memory pool, the 
allocation is attempted and fails, which aborts the process.
   
   ### To Reproduce
   
   In `datafusion-cli`:
   
   ```sql
   CREATE TABLE a AS SELECT * FROM (VALUES (arrow_cast(0, 'UInt64')), 
(arrow_cast(4611686018427387904, 'UInt64'))) t(k);
   CREATE TABLE b AS SELECT * FROM (VALUES (arrow_cast(0, 'UInt64'))) t(k);
   SELECT * FROM a JOIN b ON a.k = b.k;
   SET datafusion.execution.perfect_hash_join_min_key_density = 0;
   SELECT * FROM a JOIN b ON a.k = b.k;
   ```
   
   The first join returns `0 | 0`. The second panics:
   
   ```
   thread 'main' panicked at library/alloc/src/raw_vec/mod.rs:28:5:
   capacity overflow
   ```
   
   With `1152921504606846976` (2^60) in place of `4611686018427387904` (2^62), 
the map needs 2^62 bytes, which is under `isize::MAX`, and the process aborts:
   
   ```
   memory allocation of 4611686018427387908 bytes failed
   ```
   
   ### Expected behavior
   
   The join returns an error, or uses the general hash map, when the map's size 
cannot be allocated.
   
   ### Additional context
   
   #20995 fixed the overflow for a range that spans the whole type.


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