Skip to content

Commit

Permalink
fix anti semi join (#8792)
Browse files Browse the repository at this point in the history
close #8791
  • Loading branch information
windtalker authored Feb 27, 2024
1 parent a011bfd commit 9970e49
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
62 changes: 62 additions & 0 deletions dbms/src/Flash/tests/gtest_join_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,68 @@ try
}
CATCH

TEST_F(JoinExecutorTestRunner, Issue8791)
try
{
auto build_key = toNullableVec<Int64>(
"id",
{
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
});
auto build_col = toNullableVec<Int64>(
"build_value",
{
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
});
auto probe_key = toNullableVec<Int64>(
"id",
{
1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
});
auto probe_col = toNullableVec<Int64>(
"probe_value",
{
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
});
context.addMockTable(
"issue_8791",
"build_table",
{{"id", TiDB::TP::TypeLongLong}, {"build_value", TiDB::TP::TypeLongLong}},
{build_key, build_col});
context.addMockTable(
"issue_8791",
"probe_table",
{{"id", TiDB::TP::TypeLongLong}, {"probe_value", TiDB::TP::TypeLongLong}},
{probe_key, probe_col});

auto request = context.scan("issue_8791", "probe_table")
.join(
context.scan("issue_8791", "build_table"),
tipb::JoinType::TypeAntiSemiJoin,
{col("id")},
{},
{},
{gt(col("probe_value"), col("build_value"))},
{})
.aggregation({Count(col("id"))}, {})
.build(context);

context.context->setSetting("max_block_size", Field(static_cast<UInt64>(200)));
auto expected_columns = {toVec<UInt64>({1})};
ASSERT_COLUMNS_EQ_UR(expected_columns, executeStreams(request, 1));
}
CATCH

TEST_F(JoinExecutorTestRunner, CrossJoinWithoutCondition)
try
{
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Interpreters/Join.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,9 @@ Block Join::doJoinBlockHash(ProbeProcessInfo & probe_process_info) const
offsets_to_replicate->assign(
offsets_to_replicate->begin() + probe_process_info.start_row,
offsets_to_replicate->begin() + probe_process_info.end_row);
if (isAntiJoin(kind) && filter != nullptr)
filter->assign(filter->begin() + probe_process_info.start_row,
filter->begin() + probe_process_info.end_row);
}
}
}
Expand Down

0 comments on commit 9970e49

Please sign in to comment.