Skip to content

Commit

Permalink
executor: remove HashJoinV2Exec.needUsedFlag() (#54766)
Browse files Browse the repository at this point in the history
close #54755
  • Loading branch information
windtalker authored Jul 22, 2024
1 parent 41ed0e5 commit 8edd4ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
11 changes: 4 additions & 7 deletions pkg/executor/join/hash_join_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,6 @@ func (e *HashJoinV2Exec) Close() error {
return err
}

func (e *HashJoinV2Exec) needUsedFlag() bool {
return e.JoinType == plannercore.LeftOuterJoin && !e.RightAsBuildSide
}

// Open implements the Executor Open interface.
func (e *HashJoinV2Exec) Open(ctx context.Context) error {
if err := e.BaseExecutor.Open(ctx); err != nil {
Expand All @@ -306,14 +302,15 @@ func (e *HashJoinV2Exec) Open(ctx context.Context) error {
return err
}
e.prepared = false
needScanRowTableAfterProbeDone := e.ProbeWorkers[0].JoinProbe.NeedScanRowTable()
e.HashJoinCtxV2.needScanRowTableAfterProbeDone = needScanRowTableAfterProbeDone
if e.RightAsBuildSide {
e.hashTableMeta = newTableMeta(e.BuildWorkers[0].BuildKeyColIdx, e.BuildWorkers[0].BuildTypes,
e.BuildKeyTypes, e.ProbeKeyTypes, e.RUsedInOtherCondition, e.RUsed, e.needUsedFlag())
e.BuildKeyTypes, e.ProbeKeyTypes, e.RUsedInOtherCondition, e.RUsed, needScanRowTableAfterProbeDone)
} else {
e.hashTableMeta = newTableMeta(e.BuildWorkers[0].BuildKeyColIdx, e.BuildWorkers[0].BuildTypes,
e.BuildKeyTypes, e.ProbeKeyTypes, e.LUsedInOtherCondition, e.LUsed, e.needUsedFlag())
e.BuildKeyTypes, e.ProbeKeyTypes, e.LUsedInOtherCondition, e.LUsed, needScanRowTableAfterProbeDone)
}
e.HashJoinCtxV2.needScanRowTableAfterProbeDone = e.ProbeWorkers[0].JoinProbe.NeedScanRowTable()
e.HashJoinCtxV2.ChunkAllocPool = e.AllocPool
if e.memTracker != nil {
e.memTracker.Reset()
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/test/jointest/hashjoin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 18,
shard_count = 19,
deps = [
"//pkg/config",
"//pkg/executor/join",
Expand Down
20 changes: 20 additions & 0 deletions pkg/executor/test/jointest/hashjoin/hash_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,23 @@ func TestKillDuringBuild(t *testing.T) {
err = tk.QueryToErr("select /*+ HASH_JOIN_BUILD(t) */ * from t left outer join t1 on t.c1 = t1.c1")
require.Equal(t, exeerrors.ErrQueryInterrupted, err)
}

func TestIssue54755(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t1;")
tk.MustExec("drop table if exists t2;")
tk.MustExec("create table t1(pk INTEGER AUTO_INCREMENT, col_int_nokey INTEGER, col_int_key INTEGER, col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1), PRIMARY KEY (pk), KEY (col_int_key), KEY (col_varchar_key, col_int_key))")
tk.MustExec("create table t2(pk INTEGER AUTO_INCREMENT, col_int_nokey INTEGER, col_int_key INTEGER, col_varchar_key VARCHAR(1), col_varchar_nokey VARCHAR(1), PRIMARY KEY (pk), KEY (col_int_key), KEY (col_varchar_key, col_int_key))")
tk.MustExec("insert into t1(col_int_key, col_int_nokey,col_varchar_key, col_varchar_nokey) values(4,2,'v','v'),(62,150,'v','v')")
tk.MustExec("insert into t2(col_int_key, col_int_nokey,col_varchar_key, col_varchar_nokey) values(8,null,'x','x'),(7,8,'d','d')")
join.SetEnableHashJoinV2(true)
defer func() {
join.SetEnableHashJoinV2(false)
}()
// right join
tk.MustQuery("select max(SQ1_alias2.col_int_nokey) as SQ1_field1 from ( t2 as SQ1_alias1 right join t1 as SQ1_alias2 on ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ))").Check(testkit.Rows("150"))
// left join
tk.MustQuery("select max(SQ1_alias2.col_int_nokey) as SQ1_field1 from ( t1 as SQ1_alias2 left join t2 as SQ1_alias1 on ( SQ1_alias2.col_varchar_key = SQ1_alias1.col_varchar_nokey ))").Check(testkit.Rows("150"))
}

0 comments on commit 8edd4ed

Please sign in to comment.