From a7fb3d0e7259a1e8c5fc55d57058aa71ee19372b Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Mon, 7 Aug 2023 14:21:30 +0800 Subject: [PATCH 1/2] fix --- executor/index_lookup_join.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/executor/index_lookup_join.go b/executor/index_lookup_join.go index 187e83cc0f763..21ac09baaefdc 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -188,9 +188,10 @@ func (e *IndexLookUpJoin) startWorkers(ctx context.Context) { innerCh := make(chan *lookUpJoinTask, concurrency) e.workerWg.Add(1) go e.newOuterWorker(resultCh, innerCh).run(workerCtx, e.workerWg) - e.workerWg.Add(concurrency) for i := 0; i < concurrency; i++ { - go e.newInnerWorker(innerCh).run(workerCtx, e.workerWg) + innerWorker := e.newInnerWorker(innerCh) + e.workerWg.Add(1) + go innerWorker.run(workerCtx, e.workerWg) } } From 3b53292a842d2484d44993d842140b133ebdfdba Mon Sep 17 00:00:00 2001 From: wshwsh12 <793703860@qq.com> Date: Tue, 8 Aug 2023 11:52:22 +0800 Subject: [PATCH 2/2] add ut --- executor/index_lookup_join.go | 5 +++++ executor/index_lookup_join_test.go | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/executor/index_lookup_join.go b/executor/index_lookup_join.go index 21ac09baaefdc..ee654b282cfe4 100644 --- a/executor/index_lookup_join.go +++ b/executor/index_lookup_join.go @@ -233,6 +233,11 @@ func (e *IndexLookUpJoin) newInnerWorker(taskCh chan *lookUpJoinTask) *innerWork lookup: e, memTracker: memory.NewTracker(memory.LabelForIndexJoinInnerWorker, -1), } + failpoint.Inject("inlNewInnerPanic", func(val failpoint.Value) { + if val.(bool) { + panic("test inlNewInnerPanic") + } + }) iw.memTracker.AttachTo(e.memTracker) if len(copiedRanges) != 0 { // We should not consume this memory usage in `iw.memTracker`. The diff --git a/executor/index_lookup_join_test.go b/executor/index_lookup_join_test.go index 01ec1f7563639..6b5d6e96bcc44 100644 --- a/executor/index_lookup_join_test.go +++ b/executor/index_lookup_join_test.go @@ -493,3 +493,21 @@ func TestPartitionTableIndexJoinAndIndexReader(t *testing.T) { tk.MustQuery("select /*+ TIDB_INLJ(t1, t2) */ t1.a from t t1, t t2 where t1.a=t2.b and " + cond).Sort().Check(result) } } + +func TestIssue45716(t *testing.T) { + store := testkit.CreateMockStore(t) + + tk := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("set tidb_mem_quota_query = 120000;") + tk.MustExec("drop table if exists t1, t2;") + tk.MustExec("create table t1(a int, index(a));") + tk.MustExec("create table t2(a int, index(a));") + tk.MustExec("insert into t1 values (1), (2);") + tk.MustExec("insert into t2 values (1),(1),(2),(2);") + + failpoint.Enable("github.com/pingcap/tidb/executor/inlNewInnerPanic", `return(true)`) + defer failpoint.Disable("github.com/pingcap/tidb/executor/inlNewInnerPanic") + err := tk.QueryToErr("select /*+ inl_join(t2) */ * from t1 join t2 on t1.a = t2.a;") + tk.MustContainErrMsg(err.Error(), "test inlNewInnerPanic") +}