Skip to content

ARROW-11806: [Rust][DataFusion] Optimize join / inner join creation of indices - #9595

Closed
Dandandan wants to merge 5 commits into
apache:masterfrom
Dandandan:opt_hash_join
Closed

ARROW-11806: [Rust][DataFusion] Optimize join / inner join creation of indices#9595
Dandandan wants to merge 5 commits into
apache:masterfrom
Dandandan:opt_hash_join

Conversation

@Dandandan

@DandandanDandandan commented Feb 27, 2021

Copy link
Copy Markdown
Contributor

This PR implements two optimizations

  • Change the way we create an array of indices for an inner join to avoid generating a null bit map. It seems currently not really ergonomic to do this with Arrow without resorting to an iterator (which would be hard to do here). This is around 3% difference
  • Allow to reuse allocations in create_hashes when possible. This is around 2% faster.

In total this gives a small (5%) speedup to query 5:

This PR:

Query 5 iteration 0 took 169.3 ms
Query 5 iteration 1 took 156.0 ms
Query 5 iteration 2 took 157.5 ms
Query 5 iteration 3 took 158.0 ms
Query 5 iteration 4 took 157.3 ms
Query 5 iteration 5 took 163.4 ms
Query 5 iteration 6 took 167.6 ms
Query 5 iteration 7 took 171.5 ms
Query 5 iteration 8 took 167.4 ms
Query 5 iteration 9 took 164.5 ms
Query 5 avg time: 163.26 ms

Master:

Query 5 iteration 0 took 177.6 ms
Query 5 iteration 1 took 169.6 ms
Query 5 iteration 2 took 171.8 ms
Query 5 iteration 3 took 175.1 ms
Query 5 iteration 4 took 167.2 ms
Query 5 iteration 5 took 171.1 ms
Query 5 iteration 6 took 174.2 ms
Query 5 iteration 7 took 178.1 ms
Query 5 iteration 8 took 167.9 ms
Query 5 iteration 9 took 172.0 ms
Query 5 avg time: 172.46 ms

@github-actions

Copy link
Copy Markdown

@DandandanDandandan changed the title ARROW-11806: Optimize inner join creation of indicesARROW-11806: Optimize join / inner join creation of indicesFeb 28, 2021

@andygroveandygrove left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @Dandandan

@alambalamb changed the title ARROW-11806: Optimize join / inner join creation of indicesARROW-11806: [Rust][DataFusion] Optimize join / inner join creation of indicesMar 3, 2021
@alamb

alamb commented Mar 3, 2021

Copy link
Copy Markdown
Contributor

The integration test failure in https://github.com/apache/arrow/pull/9595/checks?check_run_id=1998235390 seems to be the same as was fixed in #9593

I also pulled this branch locally, and re-ran the tests and everythings looks good to me

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code makes sense to me -- thank you @Dandandan

I would like to suggest we rename the hashes_buffer, hash_buff and hashes parameters consistently as I think they mean the same thing. I don't have a particular preference as to which, but I do think it would help readability a lot to use the same name

hash: &mut JoinHashMap,
offset: usize,
random_state: &RandomState,
hashes_buffer: &mut Vec<u64>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is effectively allowing hashes_buffer to be reused, right?

It may eventually make sense to make some struct that holds all the relevant state (on, random_state, hash_buf, etc).

@DandandanDandandanMar 3, 2021

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this change is for reusing the allocated Vec.

Yes, makes sense to group them in a struct. There are some opportunities in other functions build_join_indexesbuild_batch, etc. for this as well. Not sure if it makes sense they all receive the same struct, or maybe all of them a subset of the most commonly needed parts 🤔

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 definitely not for this PR

Comment threadrust/datafusion/src/physical_plan/hash_join.rs Outdated
Comment threadrust/datafusion/src/physical_plan/hash_join.rs Outdated
@Dandandan

Copy link
Copy Markdown
ContributorAuthor

Thanks @alamb resolved the incosistent naming.

@alambalamb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice to me. Thanks @Dandandan

@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #9595 (2869040) into master (0f64726) will increase coverage by 0.04%.
The diff coverage is 78.72%.

Impacted file tree graph

@@ Coverage Diff @@## master #9595 +/- ##
==========================================
+ Coverage 82.33% 82.38% +0.04% 
==========================================
Files 245 245 Lines 56407 57134 +727 ==========================================
+ Hits 46443 47068 +625 - Misses 9964 10066 +102 
Impacted FilesCoverage Δ
rust/datafusion/src/physical_plan/hash_join.rs84.16% <77.77%> (+0.64%)⬆️
rust/datafusion/src/physical_plan/repartition.rs81.21% <100.00%> (-0.14%)⬇️
...datafusion/src/physical_plan/string_expressions.rs73.38% <0.00%> (-3.62%)⬇️
rust/arrow/src/array/equal/utils.rs75.49% <0.00%> (-0.99%)⬇️
rust/arrow/src/datatypes/field.rs55.47% <0.00%> (-0.66%)⬇️
rust/datafusion/src/physical_plan/parquet.rs87.83% <0.00%> (-0.22%)⬇️
rust/benchmarks/src/bin/tpch.rs38.33% <0.00%> (ø)
...datafusion/src/physical_plan/crypto_expressions.rs52.45% <0.00%> (ø)
...integration-testing/src/flight_server_scenarios.rs0.00% <0.00%> (ø)
...-testing/src/flight_server_scenarios/middleware.rs0.00% <0.00%> (ø)
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0f64726...2869040. Read the comment docs.

@alamb

alamb commented Mar 3, 2021

Copy link
Copy Markdown
Contributor

@Dandandan on no! It now seems to have failed rust fmt linting

@Dandandan

Copy link
Copy Markdown
ContributorAuthor

@alamb ha, thanks, fixed!

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@Dandandan@alamb@codecov-io@andygrove