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

chore(planner): add tips for wrong usage of semi or anti join #13948

Merged
Merged
Changes from 12 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
26 changes: 23 additions & 3 deletions src/query/sql/src/executor/physical_plans/physical_hash_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl PhysicalPlanBuilder {

let mut probe_projections = ColumnSet::new();
let mut build_projections = ColumnSet::new();
for column in pre_column_projections {
for column in pre_column_projections.iter() {
if let Some((index, _)) = probe_schema.column_with_name(&column.to_string()) {
probe_projections.insert(index);
}
Expand Down Expand Up @@ -320,8 +320,28 @@ impl PhysicalPlanBuilder {
probe_fields.extend(build_fields);
probe_fields
}
JoinType::LeftSemi | JoinType::LeftAnti => probe_fields,
JoinType::RightSemi | JoinType::RightAnti => build_fields,
JoinType::LeftSemi | JoinType::LeftAnti | JoinType::RightSemi | JoinType::RightAnti => {
let (result_fields, dropped_fields) = if join.join_type == JoinType::LeftSemi
|| join.join_type == JoinType::LeftAnti
{
(probe_fields, build_fields)
} else {
(build_fields, probe_fields)
};
for field in dropped_fields.iter() {
if result_fields.iter().all(|x| x.name() != field.name())
&& field
.name()
.parse::<usize>()
.map_or(false, |index| column_projections.contains(&index))
{
return Err(ErrorCode::SemanticError(
"cannot access the columns on the ANTI or SEMI side",
Dousir9 marked this conversation as resolved.
Show resolved Hide resolved
));
}
}
result_fields
}
JoinType::LeftMark => {
let name = if let Some(idx) = join.marker_index {
idx.to_string()
Expand Down
Loading