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

fix anti semi join (release-7.5) #8792

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Better not to use assign because it uses memcpy which has an undefined behavior if two memory locations are overlapped.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I aggree, but since it is close to the release deadline, I suggest we keep assign in this pr and fix it later since assign is used many places, it will bring extra risk if we change too many in this pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

filter->begin() + probe_process_info.end_row);
}
}
}
Expand Down