diff --git a/src/query/sql/src/executor/physical_plans/physical_hash_join.rs b/src/query/sql/src/executor/physical_plans/physical_hash_join.rs index a552194a5c8b..0ae1cb84aa4a 100644 --- a/src/query/sql/src/executor/physical_plans/physical_hash_join.rs +++ b/src/query/sql/src/executor/physical_plans/physical_hash_join.rs @@ -360,10 +360,15 @@ impl PhysicalPlanBuilder { column_projections.contains(&index) { let metadata = self.metadata.read(); + let unexpected_column = metadata.column(index); + let unexpected_column_info = if let Some(table_index) = unexpected_column.table_index() { + format!("{:?}.{:?}", metadata.table(table_index).name(), unexpected_column.name()) + } else { + unexpected_column.name().to_string() + }; return Err(ErrorCode::SemanticError(format!( - "cannot access the {:?}.{:?} in ANTI or SEMI join", - metadata.table(index).name(), - metadata.column(index).name() + "cannot access the {} in ANTI or SEMI join", + unexpected_column_info ))); } } diff --git a/tests/sqllogictests/suites/query/join/join.test b/tests/sqllogictests/suites/query/join/join.test index 8041c03249ae..cd3e83308aef 100644 --- a/tests/sqllogictests/suites/query/join/join.test +++ b/tests/sqllogictests/suites/query/join/join.test @@ -231,7 +231,22 @@ SELECT t2.a FROM t1 LEFT SEMI JOIN t2 ON t1.a = t2.a; --- statement ok -drop table t1; +drop table if exists t1; statement ok -drop table t2; +drop table if exists t2; + +statement ok +create table t1(a int, b int, c int, d int); + +statement ok +insert into t1 values(1, 2, 3, 4); + +statement ok +create table t2(a int, b int, c int, d int); + +statement ok +insert into t2 values(1, 2, 3, 4); + +statement error 1065 +SELECT tt1.d FROM t1 RIGHT SEMI JOIN t2 USING(b);