From 10b7651516e3984ddd6397944c8d0dd2742fec9d Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Wed, 24 Jul 2024 11:22:28 +0800 Subject: [PATCH 1/4] add ut --- pkg/executor/join/index_lookup_hash_join.go | 1 + pkg/executor/join/index_lookup_join_test.go | 40 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/pkg/executor/join/index_lookup_hash_join.go b/pkg/executor/join/index_lookup_hash_join.go index b3151def67437..f24e35c83cdbd 100644 --- a/pkg/executor/join/index_lookup_hash_join.go +++ b/pkg/executor/join/index_lookup_hash_join.go @@ -784,6 +784,7 @@ func (iw *indexHashJoinInnerWorker) joinMatchedInnerRow2Chunk(ctx context.Contex case iw.resultCh <- joinResult: case <-ctx.Done(): } + failpoint.InjectCall("joinMatchedInnerRow2Chunk") joinResult, ok = iw.getNewJoinResult(ctx) if !ok { return false, joinResult diff --git a/pkg/executor/join/index_lookup_join_test.go b/pkg/executor/join/index_lookup_join_test.go index d9c6025bf9ecd..aa59a913d8119 100644 --- a/pkg/executor/join/index_lookup_join_test.go +++ b/pkg/executor/join/index_lookup_join_test.go @@ -18,10 +18,12 @@ import ( "context" "fmt" "math/rand" + "runtime" "strings" "testing" "github.com/pingcap/failpoint" + "github.com/pingcap/tidb/pkg/session" "github.com/pingcap/tidb/pkg/testkit" "github.com/stretchr/testify/require" ) @@ -134,3 +136,41 @@ func TestIssue45716(t *testing.T) { require.Error(t, err) tk.MustContainErrMsg(err.Error(), "test inlNewInnerPanic") } + +func TestIssue54688(t *testing.T) { + val := runtime.GOMAXPROCS(1) + defer func() { + runtime.GOMAXPROCS(val) + }() + store := testkit.CreateMockStore(t) + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test;") + tk.MustExec("drop table if exists t, s;") + tk.MustExec("create table t(a int, index(a));") + tk.MustExec("create table s(a int, index(a));") + tk.MustExec("insert into t values(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16);") + tk.MustExec("insert into s values(1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16);") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("insert into s select * from s") + tk.MustExec("set @@tidb_index_lookup_join_concurrency=1;") + tk.MustExec("set @@tidb_index_join_batch_size=1000000;") + + for i := 0; i <= 100; i++ { + rs, err := tk.Exec("select /*+ INL_HASH_JOIN(s) */ * from t join s on t.a=s.a") + require.NoError(t, err) + context, cancel := context.WithCancel(context.Background()) + require.NoError(t, failpoint.EnableCall("github.com/pingcap/tidb/pkg/executor/join/joinMatchedInnerRow2Chunk", + func() { + cancel() + }, + )) + _, err = session.GetRows4Test(context, nil, rs) + rs.Close() + } +} From 48b13fbbf6b4d5fac8f4aced4bd0ad2214cf9d05 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Wed, 24 Jul 2024 11:37:56 +0800 Subject: [PATCH 2/4] fix --- pkg/executor/join/index_lookup_hash_join.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/executor/join/index_lookup_hash_join.go b/pkg/executor/join/index_lookup_hash_join.go index f24e35c83cdbd..5d7f4caa1bce8 100644 --- a/pkg/executor/join/index_lookup_hash_join.go +++ b/pkg/executor/join/index_lookup_hash_join.go @@ -563,6 +563,7 @@ func (iw *indexHashJoinInnerWorker) getNewJoinResult(ctx context.Context) (*inde select { case joinResult.chk, ok = <-iw.joinChkResourceCh: case <-ctx.Done(): + joinResult.err = ctx.Err() return joinResult, false } return joinResult, ok @@ -783,6 +784,8 @@ func (iw *indexHashJoinInnerWorker) joinMatchedInnerRow2Chunk(ctx context.Contex select { case iw.resultCh <- joinResult: case <-ctx.Done(): + joinResult.err = ctx.Err() + return false, joinResult } failpoint.InjectCall("joinMatchedInnerRow2Chunk") joinResult, ok = iw.getNewJoinResult(ctx) From cbd31a1c6f487538e3d6ae6f81847c788be2ce45 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Wed, 24 Jul 2024 11:54:23 +0800 Subject: [PATCH 3/4] bazel --- pkg/executor/join/BUILD.bazel | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/executor/join/BUILD.bazel b/pkg/executor/join/BUILD.bazel index d034744556ed2..f2ff69f547a7e 100644 --- a/pkg/executor/join/BUILD.bazel +++ b/pkg/executor/join/BUILD.bazel @@ -79,7 +79,7 @@ go_test( ], embed = [":join"], flaky = True, - shard_count = 47, + shard_count = 48, deps = [ "//pkg/config", "//pkg/domain", @@ -88,6 +88,7 @@ go_test( "//pkg/parser/ast", "//pkg/parser/mysql", "//pkg/planner/core", + "//pkg/session", "//pkg/sessionctx", "//pkg/sessionctx/variable", "//pkg/testkit", From af8d05ff5c5ecdd02462687c4f5f73ac88906cf8 Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Wed, 24 Jul 2024 12:10:35 +0800 Subject: [PATCH 4/4] fix bazel --- pkg/executor/join/index_lookup_join_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/executor/join/index_lookup_join_test.go b/pkg/executor/join/index_lookup_join_test.go index aa59a913d8119..571d0967388c6 100644 --- a/pkg/executor/join/index_lookup_join_test.go +++ b/pkg/executor/join/index_lookup_join_test.go @@ -170,7 +170,7 @@ func TestIssue54688(t *testing.T) { cancel() }, )) - _, err = session.GetRows4Test(context, nil, rs) + _, _ = session.GetRows4Test(context, nil, rs) rs.Close() } }