Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve hash join detail functions #10273

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 28 additions & 25 deletions cpp/src/join/join.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <join/hash_join.cuh>
#include <join/join_common_utils.hpp>
#include "join/hash_join.cuh"
#include "join/join_common_utils.hpp"

#include <cudf/detail/gather.cuh>
#include <cudf/dictionary/detail/update_keys.hpp>
Expand Down Expand Up @@ -51,8 +51,8 @@ inner_join(table_view const& left_input,
// build the hash map from the smaller table.
if (right.num_rows() > left.num_rows()) {
cudf::hash_join hj_obj(left, compare_nulls, stream);
auto result = hj_obj.inner_join(right, std::nullopt, stream, mr);
return std::make_pair(std::move(result.second), std::move(result.first));
auto [right_result, left_result] = hj_obj.inner_join(right, std::nullopt, stream, mr);
return std::make_pair(std::move(left_result), std::move(right_result));
} else {
cudf::hash_join hj_obj(right, compare_nulls, stream);
return hj_obj.inner_join(left, std::nullopt, stream, mr);
Expand All @@ -78,16 +78,17 @@ std::unique_ptr<table> inner_join(table_view const& left_input,
auto const left = scatter_columns(matched.second.front(), left_on, left_input);
auto const right = scatter_columns(matched.second.back(), right_on, right_input);

auto join_indices = inner_join(left.select(left_on), right.select(right_on), compare_nulls, mr);
auto const [left_join_indices, right_join_indices] = cudf::detail::inner_join(
left.select(left_on), right.select(right_on), compare_nulls, stream, mr);
std::unique_ptr<table> left_result = detail::gather(left,
join_indices.first->begin(),
join_indices.first->end(),
left_join_indices->begin(),
left_join_indices->end(),
out_of_bounds_policy::DONT_CHECK,
stream,
mr);
std::unique_ptr<table> right_result = detail::gather(right,
join_indices.second->begin(),
join_indices.second->end(),
right_join_indices->begin(),
right_join_indices->end(),
out_of_bounds_policy::DONT_CHECK,
stream,
mr);
Expand Down Expand Up @@ -134,23 +135,24 @@ std::unique_ptr<table> left_join(table_view const& left_input,
table_view const left = scatter_columns(matched.second.front(), left_on, left_input);
table_view const right = scatter_columns(matched.second.back(), right_on, right_input);

auto join_indices = left_join(left.select(left_on), right.select(right_on), compare_nulls);
auto const [left_join_indices, right_join_indices] = cudf::detail::left_join(
left.select(left_on), right.select(right_on), compare_nulls, stream, mr);

if ((left_on.empty() || right_on.empty()) ||
Copy link
Contributor

@bdice bdice Feb 12, 2022

Choose a reason for hiding this comment

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

It looks like this if statement is for an early exit with an empty result. However, we're calling cudf::detail::left_join before the early-exit. None of the early exit conditions left_on.empty(), right_on.empty(), or is_trivial_join(left, right, ...) appear to depend on the result of the call to cudf::detail::left_join.

It seems like we could move these lines up, so that the if statement and early exit could be evaluated earlier in the function. Similarly for full_join below. (Am I missing something important?)

Apologies for expanding the scope of the PR review twice -- this just seemed important for performance.

#7454 is where this section of code was last changed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! And tbh no need to apologize at all. I'm working on improving the hash join performance #10248 thus found small issues here and there. That's also why this PR exists 😄. The goal is to improve hash join!

is_trivial_join(left, right, cudf::detail::join_kind::LEFT_JOIN)) {
auto probe_build_pair = get_empty_joined_table(left, right);
return cudf::detail::combine_table_pair(std::move(probe_build_pair.first),
std::move(probe_build_pair.second));
auto [left_empty_table, right_empty_table] = get_empty_joined_table(left, right);
return cudf::detail::combine_table_pair(std::move(left_empty_table),
std::move(right_empty_table));
}
std::unique_ptr<table> left_result = detail::gather(left,
join_indices.first->begin(),
join_indices.first->end(),
left_join_indices->begin(),
left_join_indices->end(),
out_of_bounds_policy::NULLIFY,
stream,
mr);
std::unique_ptr<table> right_result = detail::gather(right,
join_indices.second->begin(),
join_indices.second->end(),
right_join_indices->begin(),
right_join_indices->end(),
out_of_bounds_policy::NULLIFY,
stream,
mr);
Expand Down Expand Up @@ -197,23 +199,24 @@ std::unique_ptr<table> full_join(table_view const& left_input,
table_view const left = scatter_columns(matched.second.front(), left_on, left_input);
table_view const right = scatter_columns(matched.second.back(), right_on, right_input);

auto join_indices = full_join(left.select(left_on), right.select(right_on), compare_nulls);
auto const [left_join_indices, right_join_indices] = cudf::detail::full_join(
left.select(left_on), right.select(right_on), compare_nulls, stream, mr);

if ((left_on.empty() || right_on.empty()) ||
is_trivial_join(left, right, cudf::detail::join_kind::FULL_JOIN)) {
auto probe_build_pair = get_empty_joined_table(left, right);
return cudf::detail::combine_table_pair(std::move(probe_build_pair.first),
std::move(probe_build_pair.second));
auto [left_empty_table, right_empty_table] = get_empty_joined_table(left, right);
return cudf::detail::combine_table_pair(std::move(left_empty_table),
std::move(right_empty_table));
}
std::unique_ptr<table> left_result = detail::gather(left,
join_indices.first->begin(),
join_indices.first->end(),
left_join_indices->begin(),
left_join_indices->end(),
out_of_bounds_policy::NULLIFY,
stream,
mr);
std::unique_ptr<table> right_result = detail::gather(right,
join_indices.second->begin(),
join_indices.second->end(),
right_join_indices->begin(),
right_join_indices->end(),
out_of_bounds_policy::NULLIFY,
stream,
mr);
Expand Down