Skip to content

Commit ae95f2f

Browse files
authored
bulider: hash join v2 handle correlated column in other conditions (#56252)
close #56214
1 parent 281462c commit ae95f2f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

pkg/executor/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,8 @@ func collectColumnIndexFromExpr(expr expression.Expression, leftColumnSize int,
14791479
leftColumnIndex = append(leftColumnIndex, colIndex)
14801480
}
14811481
return leftColumnIndex, rightColumnIndex
1482-
case *expression.Constant:
1482+
case *expression.Constant, *expression.CorrelatedColumn:
1483+
// correlatedColumn can be treated as constant during runtime
14831484
return leftColumnIndex, rightColumnIndex
14841485
case *expression.ScalarFunction:
14851486
for _, arg := range x.GetArgs() {

pkg/executor/test/jointest/hashjoin/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ go_test(
99
],
1010
flaky = True,
1111
race = "on",
12-
shard_count = 20,
12+
shard_count = 21,
1313
deps = [
1414
"//pkg/config",
1515
"//pkg/executor/join",

pkg/executor/test/jointest/hashjoin/hash_join_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,3 +660,22 @@ func TestIssue55016(t *testing.T) {
660660
tk.MustQuery("select count(*) from t t1 join t t2 on t1.a = t2.b and t2.a = t1.b").Check(testkit.Rows("0"))
661661
}
662662
}
663+
664+
func TestIssue56214(t *testing.T) {
665+
store := testkit.CreateMockStore(t)
666+
tk := testkit.NewTestKit(t, store)
667+
tk.MustExec("use test")
668+
tk.MustExec("drop table if exists t1;")
669+
tk.MustExec("drop table if exists t2;")
670+
tk.MustExec("drop table if exists t3;")
671+
tk.MustExec("create table t1(id int, value int)")
672+
tk.MustExec("create table t2(id int, value int)")
673+
tk.MustExec("create table t3(id int, value int)")
674+
tk.MustExec("insert into t1 values(1,2),(2,3),(3,4)")
675+
tk.MustExec("insert into t2 values(1,10),(1,1),(2,10),(2,10)")
676+
tk.MustExec("insert into t3 values(1,10),(1,20)")
677+
for _, hashJoinV2 := range join.HashJoinV2Strings {
678+
tk.MustExec(hashJoinV2)
679+
tk.MustQuery("select value, (select t1.id from t1 join t2 on t1.id = t2.id and t1.value < t2.value - t3.value + 3) d from t3 order by value").Check(testkit.Rows("10 1", "20 <nil>"))
680+
}
681+
}

0 commit comments

Comments
 (0)