Skip to content

Commit

Permalink
[fix](null safe equal join) fix coredump if both sides of the conjunc…
Browse files Browse the repository at this point in the history
…t is not nullable apache#36263
  • Loading branch information
jacktengg committed Jul 1, 2024
1 parent 14c991f commit b5f010d
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 4 deletions.
10 changes: 8 additions & 2 deletions be/src/pipeline/exec/hashjoin_build_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,14 @@ Status HashJoinBuildSinkOperatorX::init(const TPlanNode& tnode, RuntimeState* st
const auto vexpr = _build_expr_ctxs.back()->root();

/// null safe equal means null = null is true, the operator in SQL should be: <=>.
const bool is_null_safe_equal = eq_join_conjunct.__isset.opcode &&
eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL;
const bool is_null_safe_equal =
eq_join_conjunct.__isset.opcode &&
(eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL) &&
// For a null safe equal join, FE may generate a plan that
// both sides of the conjuct are not nullable, we just treat it
// as a normal equal join conjunct.
(eq_join_conjunct.right.nodes[0].is_nullable ||
eq_join_conjunct.left.nodes[0].is_nullable);

const bool should_convert_to_nullable = is_null_safe_equal &&
!eq_join_conjunct.right.nodes[0].is_nullable &&
Expand Down
8 changes: 6 additions & 2 deletions be/src/pipeline/exec/hashjoin_probe_operator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,13 +540,17 @@ Status HashJoinProbeOperatorX::init(const TPlanNode& tnode, RuntimeState* state)
RETURN_IF_ERROR(vectorized::VExpr::create_expr_tree(eq_join_conjunct.left, ctx));
_probe_expr_ctxs.push_back(ctx);
bool null_aware = eq_join_conjunct.__isset.opcode &&
eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL;
eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL &&
(eq_join_conjunct.right.nodes[0].is_nullable ||
eq_join_conjunct.left.nodes[0].is_nullable);
probe_not_ignore_null[conjuncts_index] =
null_aware ||
(_probe_expr_ctxs.back()->root()->is_nullable() && probe_dispose_null);
conjuncts_index++;
const bool is_null_safe_equal = eq_join_conjunct.__isset.opcode &&
eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL;
(eq_join_conjunct.opcode == TExprOpcode::EQ_FOR_NULL) &&
(eq_join_conjunct.right.nodes[0].is_nullable ||
eq_join_conjunct.left.nodes[0].is_nullable);

/// If it's right anti join,
/// we should convert the probe to nullable if the build side is nullable.
Expand Down
5 changes: 5 additions & 0 deletions regression-test/data/query_p0/join/rqg/rqg12257/rqg12257.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !rqg12257 --

-- !rqg12257_2 --

Loading

0 comments on commit b5f010d

Please sign in to comment.